annotate src/samer/units/SpectralFIR.java @ 8:5e3cbbf173aa tip

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