File: ex_windowfuncs.ppl

package info (click to toggle)
pyxplot 0.9.2-14
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 10,288 kB
  • sloc: ansic: 50,373; xml: 1,339; python: 570; sh: 318; makefile: 89
file content (126 lines) | stat: -rw-r--r-- 3,161 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# ex_windowfuncs.ppl
#
# The code in this file is part of Pyxplot
# <http://www.pyxplot.org.uk>
#
# Copyright (C) 2006-2012 Dominic Ford <coders@pyxplot.org.uk>
#               2008-2012 Ross Church
#
# $Id: ex_windowfuncs.ppl 1261 2012-07-11 21:38:05Z dcf21 $
#
# Pyxplot is free software; you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any later
# version.
#
# You should have received a copy of the GNU General Public License along with
# Pyxplot; if not, write to the Free Software Foundation, Inc., 51 Franklin
# Street, Fifth Floor, Boston, MA  02110-1301, USA

# ----------------------------------------------------------------------------

# This script produces a figure for the Pyxplot Users' Guide

# Call common initialisation script
reset
title = "ex_windowfuncs"
load "examples/fig_init.ppl"

# Define window functions
a0    = 0.62
a1    = 0.48
a2    = 0.38
sigma = 0.5
N     = 20

bartlett(n)      = 0
bartlett_hann(n) = 0
cosine(n)        = 0
gauss(n)         = 0
hamming(n)       = 0
hann(n)          = 0
lanczos(n)       = 0
rectangular(n)   = 0
triangular(n)    = 0

bartlett(n)      [0:N-1] = (2/(N-1))*( (N-1)/2 - abs(n - (N-1)/2))
bartlett_hann(n) [0:N-1] = a0 - a1*abs(n/(N-1)-0.5) - a2*cos(2*pi*n/(N-1))
cosine(n)        [0:N-1] = cos(pi*n/(N-1) - pi/2)
gauss(n)         [0:N-1] = exp(-0.5*((n-(N-1)/2)/(sigma*(N-1)/2))**2)
hamming(n)       [0:N-1] = 0.54 - 0.46*cos(2*pi*n/(N-1))
hann(n)          [0:N-1] = 0.5*(1-cos(2*pi*n/(N-1)))
lanczos(n)       [0:N-1] = sinc(2*n/(N-1)-1)
rectangular(n)   [0:N-1] = 1
triangular(n)    [0:N-1] = (2/N)*(N/2 - abs(n-(N-1)/2))

# Main body of figure script
set multiplot
set nodisplay
width = 5
height = width/goldenRatio
set width width
set nokey
set xtics (0,0.5,1)
set ytics (0,0.5,1)
set xrange [-0.1:1.1]
set yrange [-0.1:1.1]
set texthalign center
set textvalign bottom

set origin 0*width , 0*height
set label 1 "(a) Bartlett" at 0.5,0
set xformat "" ; set xlabel ""
set ylabel ""
plot bartlett(x*(N-1))

set axis x linked item 1 x
set axis y linked item 1 y

set origin 1*width , 0*height
set label 1 "(b) Hann" at 0.5,0
set yformat ""
plot bartlett_hann(x*(N-1))

set origin 2*width , 0*height
set label 1 "(c) Cosine" at 0.5,0
plot cosine(x*(N-1))

set origin 0*width ,-1*height
set label 1 "(d) Gauss" at 0.5,0
unset yformat ; set ylabel "$w(n)$"
plot gauss(x*(N-1))

set origin 1*width ,-1*height
set label 1 "(e) Hamming" at 0.5,0
set yformat "" ; set ylabel ""
plot hamming(x*(N-1))

set origin 2*width ,-1*height
set label 1 "(f) Hann" at 0.5,0
plot hann(x*(N-1))

set origin 0*width ,-2*height
set label 1 "(g) Lanczos" at 0.5,0
unset xformat
unset yformat
plot lanczos(x*(N-1))

set origin 1*width ,-2*height
set label 1 "(h) Rectangular" at 0.5,0
set xlabel "$n/(N-1)$"
set yformat ""
plot rectangular(x*(N-1))

set origin 2*width ,-2*height
set label 1 "(i) Triangular" at 0.5,0
set xlabel ""
plot triangular(x*(N-1))

# Produce output
set term landscape
set display
refresh

# Call common cleanup script
load "examples/fig_end.ppl"