2 This file is part of a program that implements a Software-Defined Radio.
4 Copyright (C) 2004 by Frank Brickle, AB2KT and Bob McGwier, N4HY
5 Implemented from code by Bill Schottstaedt of Snd Editor at CCRMA
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 The authors can be reached by email at
29 The DTTS Microwave Society
36 /* shamelessly stolen from Bill Schottstaedt's clm.c */
37 /* made worse in the process, but enough for our purposes here */
40 //sqr(double x) { return (x * x); }
43 * Fredric J. Harris, "On the Use of Windows for Harmonic Analysis with the
44 * Discrete Fourier Transform," Proceedings of the IEEE, Vol. 66, No. 1,
46 * Albert H. Nuttall, "Some Windows with Very Good Sidelobe Behaviour",
47 * IEEE Transactions of Acoustics, Speech, and Signal Processing, Vol. ASSP-29,
48 * No. 1, February 1981, pp 84-91
50 * JOS had slightly different numbers for the Blackman-Harris windows.
54 makewindow(Windowtype type, int size, double *window) {
55 int i, j, midn, midp1, midm1;
56 double freq, rate, sr1, angle, expn, expsum, cx, two_pi;
59 midp1 = (size + 1) / 2;
60 midm1 = (size - 1) / 2;
61 two_pi = 8.0 * atan(1.0);
62 freq = two_pi / (double) size;
63 rate = 1.0 / (double) midn;
65 expn = log(2.0) / (double) midn + 1.0;
69 case RECTANGULAR_WINDOW:
70 for (i = 0; i < size; i++) window[i] = 1.0;
72 case HANNING_WINDOW: /* Hann would be more accurate */
73 for (i = 0, j = size - 1, angle = 0.0; i <= midn; i++, j--, angle += freq)
74 window[j] = (window[i] = 0.5 - 0.5 * cos(angle));
77 for (i = 0, j = size - 1; i <= midn; i++, j--)
79 (window[i] = 1.0 - sqr((double) (i - midm1) / (double) midp1));
82 for (i = 0, j = size - 1; i <= midn; i++, j--)
84 (window[i] = 1.0 - fabs((double) (i - midm1) / (double) midp1));
87 for (i = 0, j = size - 1, angle = 0.0; i <= midn; i++, j--, angle += rate)
88 window[j] = (window[i] = angle);
91 for (i = 0, j = size - 1, angle = 0.0; i <= midn; i++, j--, angle += freq)
92 window[j] = (window[i] = 0.54 - 0.46 * cos(angle));
94 case BLACKMAN2_WINDOW: /* using Chebyshev polynomial equivalents here */
95 for (i = 0, j = size - 1, angle = 0.0; i <= midn; i++, j--, angle += freq) {
97 window[j] = (window[i] = (.34401 + (cx * (-.49755 + (cx * .15844)))));
100 case BLACKMAN3_WINDOW:
101 for (i = 0, j = size - 1, angle = 0.0; i <= midn; i++, j--, angle += freq) {
104 (window[i] = (.21747 + (cx * (-.45325 + (cx * (.28256 - (cx * .04672)))))));
107 case BLACKMAN4_WINDOW:
108 for (i = 0, j = size - 1, angle = 0.0; i <= midn; i++, j--, angle += freq) {
110 window[j] = (window[i] =
115 (.375696 + (cx * (-.20762 + (cx * .041194)))))))));
118 case EXPONENTIAL_WINDOW:
119 for (i = 0, j = size - 1; i <= midn; i++, j--) {
120 window[j] = (window[i] = expsum - 1.0);
125 sr1 = two_pi / (double) size;
126 for (i = 0, j = size - 1; i <= midn; i++, j--) {
127 if (i == midn) window[j] = (window[i] = 1.0);
129 /* split out because NeXT C compiler can't handle the full expression */
130 cx = sr1 * (midn - i);
131 window[i] = sin(cx) / cx;
132 window[j] = window[i];
136 case BLACKMANHARRIS_WINDOW:
145 for (i = 0; i<size;i++) {
146 window[i] = a0 - a1*cos(two_pi*(double)(i+0.5)/(double)size)
147 + a2*cos(2.0*two_pi*(double)(i+0.5)/(double)size)
148 - a3*cos(3.0*two_pi*(double)(i+0.5)/(double)size);