00001 using System; 00002 00003 namespace FFT 00004 { 00005 /// 00006 /// Convolution based on Discrete Fourier Transformation. 00007 /// 00008 public class DFTConvolution : PolynomialConvolution 00009 { 00010 /// 00011 /// DFT engine to calculate Fourier Transformata. 00012 /// 00013 protected IDFT engine; 00014 00015 /// 00016 /// Assigns a specific DFT engine. 00017 /// 00018 public DFTConvolution(IDFT engine) 00019 { 00020 this.engine = engine; 00021 } 00022 00023 /// 00024 /// \copydoc FFT::IConvolution::Convolution(Complex[], Complex[]) 00025 /// 00026 public override Complex[] Convolution(Complex[] a, Complex[] b) 00027 { 00028 Normalize(ref a, ref b); 00029 00030 Complex[] ya = engine.DFT(a); 00031 Complex[] yb = engine.DFT(b); 00032 Complex[] y = PointwiseMultiply(ya,yb); 00033 Complex[] c = engine.InverseDFT(y); 00034 00035 return c; 00036 } 00037 00038 /// 00039 /// Normalizes the lengths of the input tables. 00040 /// 00041 /// Ensures that the length of tables <tt>a</tt> and <tt>b</tt> 00042 /// is equal to the smalles power of 2 that can the result of 00043 /// the convolution of <tt>a</tt> and <tt>b</tt>. 00044 /// 00045 protected internal virtual void Normalize(ref Complex[] a, ref Complex[] b) 00046 { 00047 int n = Utils.Exp2(Utils.Log2(a.Length+b.Length-1)); 00048 00049 a = Utils.copy(a,new Complex[n]); 00050 b = Utils.copy(b,new Complex[n]); 00051 } 00052 00053 /// 00054 /// \copybrief FFT::IConvolution::ToString() 00055 /// 00056 /// Returns <tt>"DFT"</tt> with the name of the 00057 /// DFT engine in square brackets. 00058 public override string ToString() 00059 { 00060 return "DFT[" + engine.ToString() + "]"; 00061 } 00062 00063 } //class DFTConvolution 00064 00065 } //namespace FFT