资源简介
傅里叶变换运算类,C#代码,虚拟示波器频谱图傅里叶变换计算类,快速FFT算法,数字信号处理,频率分布计算。
代码片段和文件信息
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace FFT_YC
{
///
/// 快速傅里叶变换
///
public class FFT
{
public double[] GetFftValueFromChData(short[] chdata)
{
double[] result = new double[0];
double[] allvalue = new double[0];//快速计算结果为双倍长度
int n = 470;// this.allChanData.Length;
short[] x = chdata;//被计算的数组
complex[] y = new complex[n];//接收复数结果的数组
if (chdata.Length >= n)
{
result = new Double[n];//接收幅值结果的数组
y = airthm.dft(x n);//重点耗时项
allvalue = airthm.amplitude(y n);
result = new double[allvalue.Length / 2];
for (int i = 0; i < result.Length; i++)
{ result[i] = allvalue[i]; }
//result[0] = 0.0d;
}
else { }
return result;
}
//double []X_sn;
double pi = System.Math.PI;
public double[] Wcreat(int N int FFT_IFFT_elect)
{
double[] Wp = new double[2 N / 2];
if (FFT_IFFT_elect == 0)
{
for (int i = 0; i < N / 2; i++)
{
Wp[0 i] = System.Math.Cos(2 * pi / N * i);
Wp[1 i] = System.Math.Sin(-2 * pi / N * i);
}
}
else
{
for (int i = 0; i < N / 2; i++)
{
Wp[0 i] = System.Math.Cos(2 * pi / N * i);
Wp[1 i] = System.Math.Sin(2 * pi / N * i);
}
}
return Wp;
}
///
/// 进行傅里叶变换
///
/// 数列/原始信号
/// 数列的长度
///
///
public double[] FFT_T(double[] X_sn int N int FFT_IFFT_elect)
{
double[] Wp = new double[2 N / 2];
FFT Xn = new FFT();
Wp = Xn.Wcreat(N FFT_IFFT_elect);
//测试
//
double tem = System.Math.Log(N 2);
int M = (int)tem;
for (int L = 1; L <= M; L++)
{
double M_Ld = System.Math.Pow(2 M - L);//计算2的M-L次方
int M_L = (int)M_Ld;
double L_1d = System.Math.Pow(2 L - 1);
int L_1 = (int)L_1d;
for (int j = 0; j < M_L; j++)
{
int J = j * (int)System.Math.Pow(2 L);
for (int k = 0; k < L_1; k++)
{
double[] T = new double[2];
double p_k = k * (int)System.Math.Pow(2 (M - L));
int P = (int)p_k;
评论
共有 条评论