public void BasicWndZeroPad() { // Same Input Signal as Example 1, except everything is a power of two double amplitude = 1.0; double frequency = 32768; UInt32 length = 1024; double samplingRate = 131072; double[] inputSignal = mdsplib.DSP.Generate.ToneSampling(amplitude, frequency, samplingRate, length); // Apply window to the Input Data & calculate Scale Factor double[] wCoefs = mdsplib.DSP.Window.Coefficients(mdsplib.DSP.Window.Type.Hamming, length); double[] wInputData = inputSignal.Multiply(wCoefs); double wScaleFactor = mdsplib.DSP.Window.ScaleFactor.Signal(wCoefs); // Instantiate & Initialize a new DFT FFT fft = new FFT(); fft.Initialize(length, length * 3); // Zero Padding = 1024 * 3 // Call the FFT and get the scaled spectrum back Complex[] cSpectrum = fft.Direct(wInputData); // Convert the complex spectrum to note: Magnitude Squared Format // See text for the reasons to use Mag^2 format. double[] lmSpectrum = cSpectrum.Magnitude(); // Properly scale the spectrum for the added window lmSpectrum = lmSpectrum.Multiply(wScaleFactor); // For plotting on an XY Scatter plot generate the X Axis frequency Span double[] freqSpan = Util.FFT.FrequencySpan(samplingRate, length); // At this point a XY Scatter plot can be generated from, // X axis => freqSpan // Y axis => lmSpectrum }
public void PhaseUnwrap() { // Generate a Phase Ramp between two signals double[] resultPhase = new double[600]; double[] unwrapPhase = new double[600]; UInt32 length = 2048; double[] wCoeff = mdsplib.DSP.Window.Coefficients(mdsplib.DSP.Window.Type.FTHP, length); // Instantiate & Initialize a new DFT FFT fft = new FFT(); fft.Initialize(length, 3 * length); for (Int32 phase = 0; phase < 600; phase++) { double[] inputSignalRef = mdsplib.DSP.Generate.ToneCycles(7.0, 128, length, phaseDeg: 45.0); double[] inputSignalPhase = mdsplib.DSP.Generate.ToneCycles(7.0, 128, length, phaseDeg: phase); inputSignalRef = inputSignalRef.Multiply(wCoeff); inputSignalPhase = inputSignalPhase.Multiply(wCoeff); // Call the DFT and get the scaled spectrum back of a reference and a phase shifted signal. Complex[] cSpectrumRef = fft.Direct(inputSignalRef); Complex[] cSpectrumPhase = fft.Direct(inputSignalPhase); // Magnitude Format - Just as a test point double[] lmSpectrumTest = cSpectrumRef.Magnitude(); UInt32 peakLocation = mdsplib.DSP.Analyze.FindMaxPosition(lmSpectrumTest); // Extract the phase of 'peak value' bin double[] resultArrayRef = cSpectrumRef.PhaseDegrees(); double[] resultArrayPhase = cSpectrumPhase.PhaseDegrees(); resultPhase[phase] = resultArrayPhase[peakLocation] - resultArrayRef[peakLocation]; } unwrapPhase = mdsplib.DSP.Analyze.UnwrapPhaseDegrees(resultPhase); }
public void DirectInverse() { UInt32 length = 2048; FFT fft = new FFT(); fft.Initialize(length); double[] wCoeff = mdsplib.DSP.Window.Coefficients(mdsplib.DSP.Window.Type.Hann, length); double[] inputSignal = mdsplib.DSP.Generate.ToneSampling(1.0, 4000, 44100, length); double[] inputSignalRef = inputSignal.Multiply(inputSignal); Complex[] cSpectrum = fft.Direct(inputSignalRef); double[] lmSpectrum = cSpectrum.Magnitude(); Complex[] cSpectrumI = fft.Inverse(cSpectrum); }