|
从NI找到一个快速傅里叶变换的动态链接库,编写了一个函数用于计算;[C#] 纯文本查看 复制代码 public static void FFTFunction(double[]waveform, int rateofsimpling,ref double[] x,ref double[] y)
{
int datasize = waveform.Length;
int fftnumofSamples = datasize / 2;
double[] xwaveform = new double[fftnumofSamples];
double[] magnitudes = new double[datasize];
double[] subsetOfMagnitudes = new double[fftnumofSamples];
double[] phases = new double[datasize];
double[] subsetOfPhases = new double[fftnumofSamples];
NationalInstruments.ComplexDouble[] FFTValue = new NationalInstruments.ComplexDouble[datasize];
FFTValue = NationalInstruments.Analysis.Dsp.Transforms.RealFft(waveform);
NationalInstruments.ComplexDouble.DecomposeArrayPolar(FFTValue, out magnitudes, out phases);
double scalingFactor = 1.0 / datasize;
double deltafreq = rateofsimpling * scalingFactor;
subsetOfMagnitudes[0] = magnitudes[0] * scalingFactor;
for (int i = 1; i < fftnumofSamples; i++)
{
xwaveform[i] = deltafreq * i;
subsetOfMagnitudes[i] = magnitudes[i] * scalingFactor * 2;
subsetOfPhases[i] = phases[i];
x[i] = xwaveform[i];
y[i] = subsetOfMagnitudes[i];
}
}
其次,Transforms类中如下:
[C#] 纯文本查看 复制代码 #region 程序集 NationalInstruments.Analysis.Enterprise.dll, v15.0.45.49153
// C:\Users\陈泽生\Desktop\TEST\test1\test1\bin\Debug\NationalInstruments.Analysis.Enterprise.dll
#endregion
using NationalInstruments;
using System;
using System.ComponentModel;
namespace NationalInstruments.Analysis.Dsp
{
public sealed class Transforms
{
public static ComplexDouble[] ChirpZTransform(ComplexDouble[] inputData, ComplexDouble startingPoint, ComplexDouble increment, ChirpZTransformAlgorithm algorithm);
public static ComplexDouble[] ChirpZTransform(double[] inputData, ComplexDouble startingPoint, ComplexDouble increment, ChirpZTransformAlgorithm algorithm);
public static ComplexDouble[] ChirpZTransform(ComplexDouble[] inputData, ComplexDouble startingPoint, ComplexDouble increment, ChirpZTransformAlgorithm algorithm, int numberOfBins);
public static ComplexDouble[] ChirpZTransform(double[] inputData, ComplexDouble startingPoint, ComplexDouble increment, ChirpZTransformAlgorithm algorithm, int numberOfBins);
public static ComplexDouble[] CrossSpectrum(ComplexDouble[] inputXData, ComplexDouble[] inputYData);
public static ComplexDouble[] CrossSpectrum(double[] inputXData, double[] inputYData);
public static void CrossSpectrum(double[] inputXData, double[] inputYData, out double[] realData, out double[] imaginaryData);
public static double[] DiscreteCosineTransform1D(double[] inputData);
public static double[] DiscreteCosineTransform1D(double[] inputData, int dctSize);
public static double[,] DiscreteCosineTransform2D(double[,] inputMatrix);
public static double[] DiscreteSineTransform1D(double[] inputData);
public static double[] DiscreteSineTransform1D(double[] inputData, int dstSize);
public static double[,] DiscreteSineTransform2D(double[,] inputMatrix);
public static void FastHartley(double[] data);
public static void FastHilbert(double[] data);
public static void Fft(ComplexDouble[] data);
public static ComplexDouble[] Fft(ComplexDouble[] inputData, bool shiftDC);
[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete("Use an overload of this method to achieve the same functionality.")]
public static void Fft(double[] realData, double[] imaginaryData);
public static ComplexDouble[] Fft(ComplexDouble[] inputData, bool shiftDC, int fftSize);
public static ComplexDouble[,] Fft2D(ComplexDouble[,] inputData, bool shiftDC);
public static ComplexDouble[,] Fft2D(ComplexDouble[,] inputData, bool shiftDC, int rowsForFft, int columnsForFft);
public static double[] ImpulseResponse(double[] stimulus, double[] response);
public static ComplexDouble[] InverseChirpZTransform(ComplexDouble[] inputData, ComplexDouble startingPoint, ComplexDouble increment);
public static ComplexDouble[] InverseChirpZTransform(ComplexDouble[] inputData, ComplexDouble startingPoint, ComplexDouble increment, int numberOfBins);
public static double[] InverseDiscreteCosineTransform1D(double[] inputData);
public static double[,] InverseDiscreteCosineTransform2D(double[,] inputMatrix);
public static double[] InverseDiscreteSineTransform1D(double[] inputData);
public static double[,] InverseDiscreteSineTransform2D(double[,] inputMatrix);
public static void InverseFastHartley(double[] data);
public static void InverseFastHilbert(double[] data);
public static void InverseFft(ComplexDouble[] fft);
public static ComplexDouble[] InverseFft(ComplexDouble[] fft, bool shiftDC);
[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete("Use an overload of this method to achieve the same functionality.")]
public static void InverseFft(double[] realData, double[] imaginaryData);
public static ComplexDouble[,] InverseFft2D(ComplexDouble[,] fft, bool shiftDC);
public static double[] InverseRealFft(ComplexDouble[] fft);
public static double[] InverseRealFft(ComplexDouble[] fft, bool shiftDC);
[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete("Use an overload of this method to achieve the same functionality.")]
public static double[] InverseRealFft(double[] realData, double[] imaginaryData);
public static double[,] InverseRealFft2D(ComplexDouble[,] fft, bool shiftDC);
public static void NetworkFunctions(double[,] stimulus, double[,] response, double dt, out double[] crossPowerSpectrumMagnitude, out double[] crossPowerSpectrumPhase, out double[] frequencyResponseMagnitude, out double[] frequencyResponsePhase, out double[] coherence, out double[] impulseResponse, out double df);
public static double[] PowerSpectrum(ComplexDouble[] data);
public static void PowerSpectrum(double[] data);
public static ComplexDouble[] RealFft(double[] realData);
public static ComplexDouble[] RealFft(double[] realData, bool shiftDC);
public static ComplexDouble[] RealFft(double[] realData, bool shiftDC, int fftSize);
public static ComplexDouble[,] RealFft2D(double[,] realData, bool shiftDC);
public static ComplexDouble[,] RealFft2D(double[,] realData, bool shiftDC, int rowsForFft, int columnsForFft);
}
}
调用FFTFunction时,会报错:“System.TypeInitializationException”类型的未经处理的异常在 NationalInstruments.Analysis.Enterprise.dll 中发生
其他信息: “NationalInstruments.Analysis.Dsp.Transforms”的类型初始值设定项引发异常。
请问有人知道这个怎么解决吗?函数是放在一个public class里面的。
|
|