public int SetRow(int index, ComplexList src) { for (int i = 0; i < Width; i++) { this[index, i] = (i < src.Lenght) ? src[i] : new Complex(0); } return(0); }
public int SetColumn(int index, ComplexList src) { for (int i = 0; i < Height; i++) { this[i, index] = (i < src.Lenght) ? src[i] : new Complex(0); } return(0); }
public ComplexList GetRow(int index) { ComplexList ret = new ComplexList(Width); for (int i = 0; i < Width; i++) { ret[i] = this[index, i]; } return(ret); }
public ComplexList GetColumn(int index) { ComplexList ret = new ComplexList(Height); for (int i = 0; i < Height; i++) { ret[i] = this[i, index]; } return(ret); }
// 快速傅里叶变换 // ComplexList src:数据输入,若长度非2的n次幂, // 则函数对末尾补零后的数据进行运算 public static ComplexList fft_1D(ComplexList src) { int lenght = src.Lenght; return(fft_core(src, ref lenght, 1)); }
// 快速傅里叶变换 // 作者:死猫 // ComplexList src:数据输入 // ref int lenght:欲变换数据的长度,函数调用后此值更改为实际变换长度 // int flag:区分fft或idft,为1为fft,为-1为idft private static ComplexList fft_core(ComplexList src, ref int lenght, int flag) { //按时间抽取FFT方法(DIT) //补零后长度 int relog2N = ReLog2N(lenght); int bitlenghth = relog2N; int N = 0x01 << bitlenghth; //重新复制数据,同时进行 // 逆序排放,并补零 int index; ComplexList Register = new ComplexList(N); for (int i = 0; i < N; i++) { index = ReArrange(i, bitlenghth); Register[i] = (index < src.Lenght) ? src[index] : new Complex(0); } //生成WN表,以免运行时进行重复计算 ComplexList WN = new ComplexList(N / 2); for (int i = 0; i < N / 2; i++) { WN[i] = new Complex(Math.Cos(2 * Math.PI / N * i), -flag * Math.Sin(2 * Math.PI / N * i)); } //蝶形运算 int Index0, Index1; Complex temp; for (int steplenght = 2; steplenght <= N; steplenght *= 2) { for (int step = 0; step < N / steplenght; step++) { for (int i = 0; i < steplenght / 2; i++) { Index0 = steplenght * step + i; Index1 = steplenght * step + i + steplenght / 2; temp = Register[Index1] * WN[N / steplenght * i]; Register[Index1] = Register[Index0] - temp; Register[Index0] = Register[Index0] + temp; } } } //若为idft if (-1 == flag) { for (int i = 0; i < Register.Lenght; i++) { Register[i] /= N; } } //赋值 lenght = N; /* * //清理内存 * WN = null; * temp = null; * GC.Collect(); */ //返回 return(Register); }
// 快速傅里叶变换的逆变换 // ComplexList src:数据输入 // ref int lenght:欲变换数据的长度,函数调用后此值更改为实际变换长度 public static ComplexList idft_1D(ComplexList src, ref int lenght) { return(fft_core(src, ref lenght, -1)); }
// 快速傅里叶变换的逆变换 // ComplexList src:数据输入 public static ComplexList idft_1D(ComplexList src) { int lenght = src.Lenght; return(idft_1D(src, ref lenght)); }