comparison src/samer/units/SpectralFIR.java @ 0:bf79fb79ee13

Initial Mercurial check in.
author samer
date Tue, 17 Jan 2012 17:50:20 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:bf79fb79ee13
1 /*
2 * Copyright (c) 2000, Samer Abdallah, King's College London.
3 * All rights reserved.
4 *
5 * This software is provided AS iS and WITHOUT ANY WARRANTY;
6 * without even the implied warranty of MERCHANTABILITY or
7 * FITNESS FOR A PARTICULAR PURPOSE.
8 */
9
10 package samer.units;
11 import samer.core.*;
12 import samer.maths.*;
13 import samer.tools.*;
14
15 public class SpectralFIR implements Task
16 {
17 FFT fft;
18 Vec spectrum;
19 VVector A;
20 int n, m;
21
22 public SpectralFIR(int n, VVector input)
23 {
24 this.n = n;
25
26 fft=new FFT(n);
27 fft.setWindow(new Constant(1));
28 fft.invert();
29
30 spectrum = input;
31 A=new VVector("coeffs",n);
32 }
33
34 public VVector coefficients() { return A; }
35
36 public void dispose() { A.dispose(); }
37 public void run() {
38 Vec.Iterator it=spectrum.iterator();
39 double [] _A=A.array();
40
41 Mathx.zero(fft.real);
42 Mathx.zero(fft.imag);
43
44 fft.real[fft.bitrev[0]]=it.next(); // zero frequency
45 for (int i=1; it.more(); i++) {
46 fft.real[fft.bitrev[i]] = fft.real[fft.bitrev[n-i]] = it.next(); // pos and neg freqs
47 }
48 fft.calculate();
49
50 // copy FFT results to filter coefficients
51 // with some reordering
52 System.arraycopy( fft.real, n/2, _A, 0, n/2);
53 System.arraycopy( fft.real, 0, _A, n/2, n/2);
54 A.changed();
55 }
56
57 // private static double pos(double t) { if (t<0) return 0; else return t; }
58
59 public void starting() {}
60 public void stopping() {}
61 }
62