苏飞论坛

 找回密码
 马上注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

分布式系统框架(V1.3) 轻松承载百亿数据,千万流量!讨论专区 - 源码下载 - 官方教程

HttpHelper万能框架(V2.3) HttpHelper官方出品,无敌框架讨论区 - 源码下载 - 在线测试和代码生成

HttpHelper爬虫类(V1.9) 最牛的爬虫类,没有爬不到只有想不到 源码 - 代码生成器 - 讨论区 - 教程- 例子

查看: 636|回复: 2

[咨询站长] 关于引用dll产生类型初始值设定项引发异常的问题

[复制链接]

该用户从未签到

发表于 2018-4-10 22:02:38 | 显示全部楼层 |阅读模式
从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里面的。

该用户从未签到

 楼主| 发表于 2018-4-10 22:14:33 | 显示全部楼层
FFTFunction如上代码,有4个参数,第一个是输入数据(二维数组),第二个是整型,第三四个是输出数组,动态链接库为(NationalInstruments.Analysis.Enterprise.dll和NationalInstruments.Common.dll)
  • TA的每日心情
    开心
    昨天 08:18
  • 签到天数: 644 天

    [LV.9]以坛为家II

    发表于 2018-4-11 14:41:17 | 显示全部楼层
    您需要登录后才可以回帖 登录 | 马上注册

    本版积分规则

    QQ|手机版|小黑屋|手机版|联系我们|关于我们|广告合作|苏飞论坛 ( 豫ICP备17001017号-1 )

    GMT+8, 2018-12-14 00:47

    © 2017-2018

    快速回复 返回顶部 返回列表