Mercurial > hg > jslab
diff src/samer/units/SpectralFIR.java @ 0:bf79fb79ee13
Initial Mercurial check in.
author | samer |
---|---|
date | Tue, 17 Jan 2012 17:50:20 +0000 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/samer/units/SpectralFIR.java Tue Jan 17 17:50:20 2012 +0000 @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2000, Samer Abdallah, King's College London. + * All rights reserved. + * + * This software is provided AS iS and WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + */ + +package samer.units; +import samer.core.*; +import samer.maths.*; +import samer.tools.*; + +public class SpectralFIR implements Task +{ + FFT fft; + Vec spectrum; + VVector A; + int n, m; + + public SpectralFIR(int n, VVector input) + { + this.n = n; + + fft=new FFT(n); + fft.setWindow(new Constant(1)); + fft.invert(); + + spectrum = input; + A=new VVector("coeffs",n); + } + + public VVector coefficients() { return A; } + + public void dispose() { A.dispose(); } + public void run() { + Vec.Iterator it=spectrum.iterator(); + double [] _A=A.array(); + + Mathx.zero(fft.real); + Mathx.zero(fft.imag); + + fft.real[fft.bitrev[0]]=it.next(); // zero frequency + for (int i=1; it.more(); i++) { + fft.real[fft.bitrev[i]] = fft.real[fft.bitrev[n-i]] = it.next(); // pos and neg freqs + } + fft.calculate(); + + // copy FFT results to filter coefficients + // with some reordering + System.arraycopy( fft.real, n/2, _A, 0, n/2); + System.arraycopy( fft.real, 0, _A, n/2, n/2); + A.changed(); + } + + // private static double pos(double t) { if (t<0) return 0; else return t; } + + public void starting() {} + public void stopping() {} +} +