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 =
C#编写的FFT实现类
最新推荐文章于 2024-08-29 11:50:11 发布
这是一个使用C#编写的FFT(快速傅里叶变换)类,通过DLL调用来实现FFT运算。类库包含了初始化、执行FFT运算以及释放资源的方法,适用于数字信号处理中的频谱分析。
摘要由CSDN通过智能技术生成