苏飞论坛

 找回密码
 马上注册

QQ登录

只需一步,快速开始

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

HttpHelper爬虫框架(V2.7-含.netcore) HttpHelper官方出品,爬虫框架讨论区 - 源码下载 - 在线测试和代码生成

HttpHelper爬虫类(V2.0) 开源的爬虫类,支持多种模式和属性 源码 - 代码生成器 - 讨论区 - 教程- 例子

查看: 5904|回复: 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里面的。


1. 开通SVIP会员,免费下载本站所有源码,不限次数据,不限时间
2. 加官方QQ群,加官方微信群获取更多资源和帮助
3. 找站长苏飞做网站、商城、CRM、小程序、App、爬虫相关、项目外包等点这里
 楼主| 发表于 2018-4-10 22:14:33 | 显示全部楼层
FFTFunction如上代码,有4个参数,第一个是输入数据(二维数组),第二个是整型,第三四个是输出数组,动态链接库为(NationalInstruments.Analysis.Enterprise.dll和NationalInstruments.Common.dll)
发表于 2018-4-11 14:41:17 | 显示全部楼层
看一下Dll的说明,应该会有说明那此是必须设置的
您需要登录后才可以回帖 登录 | 马上注册

本版积分规则

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

GMT+8, 2024-12-26 15:06

© 2014-2021

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