C#编写的FFT实现类

这是一个使用C#编写的FFT(快速傅里叶变换)类,通过DLL调用来实现FFT运算。类库包含了初始化、执行FFT运算以及释放资源的方法,适用于数字信号处理中的频谱分析。
摘要由CSDN通过智能技术生成
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics; //需要在工程中引用  Numerics函数集
using System.Text;
using System.Threading.Tasks;
using System.Runtime.InteropServices;

namespace Device.RA.Controls.Content
{
    public class FFT2 : XCommon.Disposable
    {
        const string DLLName = "FFTProcDll.dll";
        [DllImport(DLLName, CallingConvention = CallingConvention.Cdecl)]
        static extern IntPtr Fft_Init(int order);
        [DllImport(DLLName, CallingConvention = CallingConvention.Cdecl)]
        static extern void FftCtl_Destory(IntPtr FftHandle);

        //FFT运算处理
        [DllImport(DLLName, CallingConvention = CallingConvention.Cdecl)]
        static extern unsafe void FftCtl_ddcFFT(IntPtr FftHandle, byte[] DdcDatInput, ref float[] SpecDatOut, int Point, ref int MaxValue, int WinOpt = 0);

        IntPtr _ptr;
        float[] _result;

        public void Initialize(int length)
        {
            _ptr = Fft_Init((int)Math.Log(length, 2));
            _result = new float[length];
        }

        public unsafe float[] Execute(byte[] data)
        {
            int max = Int32.MinValue;
            //fixed (float* pFloat = _result)
            {
                
                FftCtl_ddcFFT(_ptr, data, ref _result, _result.Length, ref max);
            }
            return _result;
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (_ptr != IntPtr.Zero)
                {
                    FftCtl_Destory(_ptr);
                    _ptr = IntPtr.Zero;
                }
            }
        }
    }
    public class FFT
    {
        /// <summary>
        /// FFT Class
        /// </summary>
        public FFT() { }

        #region Private Properties

        private double mFFTScale = 1.0;
        private UInt32 mLogN = 0;       // log2 of FFT size
        private UInt32 mN = 0;          // Time series length
        private UInt32 mLengthTotal;    // mN + mZp
        private UInt32 mLengthHalf;     // (mN + mZp) / 2
        private FFTElement[] mX;        // Vector of linked list elements

        // Element for linked list to store input/output data.
        private class FFTElement
        {
            public double re =
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值