public static double[] getSinc(int sampleRate, long frequency, int length, WindowType window) { //Get unity response array (one element longer to align with IDFT size) double[] frequencyResponse = getUnityResponseArray(sampleRate, frequency, length + 1); //Apply Inverse DFT against frequency response unity values, leaving the //IDFT bin results in the frequency response array FFTHelper idft = new FFTHelper(); idft.RealFFT(frequencyResponse, false); /* * DoubleFFT_1D idft = new DoubleFFT_1D(length + 1); * idft.realInverseFull(frequencyResponse, false); */ //Transfer the IDFT results to the return array double[] coefficients = new double[length]; int middleCoefficient = (int)(length / 2); //Bin 0 of the idft is our center coefficient coefficients[middleCoefficient] = frequencyResponse[0]; //The remaining idft bins from 1 to (middle - 1) are the mirror image //coefficients for (int x = 1; x < middleCoefficient; x++) { coefficients[middleCoefficient + x] = frequencyResponse[2 * x]; coefficients[middleCoefficient - x] = frequencyResponse[2 * x]; } //Apply the window against the coefficients coefficients = Window.apply(window, coefficients); //Normalize to unity (1) gain coefficients = normalize(coefficients); return(coefficients); }
public static double[] getSinc(int sampleRate, long frequency, int length, WindowType window) { //Get unity response array (one element longer to align with IDFT size) double[] frequencyResponse = getUnityResponseArray(sampleRate, frequency, length + 1); //Apply Inverse DFT against frequency response unity values, leaving the //IDFT bin results in the frequency response array FFTHelper idft = new FFTHelper(); idft.RealFFT(frequencyResponse, false); /* DoubleFFT_1D idft = new DoubleFFT_1D(length + 1); idft.realInverseFull(frequencyResponse, false); */ //Transfer the IDFT results to the return array double[] coefficients = new double[length]; int middleCoefficient = (int)(length / 2); //Bin 0 of the idft is our center coefficient coefficients[middleCoefficient] = frequencyResponse[0]; //The remaining idft bins from 1 to (middle - 1) are the mirror image //coefficients for (int x = 1; x < middleCoefficient; x++) { coefficients[middleCoefficient + x] = frequencyResponse[2 * x]; coefficients[middleCoefficient - x] = frequencyResponse[2 * x]; } //Apply the window against the coefficients coefficients = Window.apply(window, coefficients); //Normalize to unity (1) gain coefficients = normalize(coefficients); return coefficients; }