資源簡介
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[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?????????????????{
????????????????????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?????????????????{
????????????????????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?????????????????{
????????????????????int?J?=?j?*?(int)System.Math.Pow(2?L);
????????????????????for?(int?k?=?0;?k?????????????????????{
????????????????????????double[]?T?=?new?double[2];
????????????????????????double?p_k?=?k?*?(int)System.Math.Pow(2?(M?-?L));
????????????????????????int?P?=?(int)p_k;
?????????
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件??????19469??2018-12-03?10:18??FFT.cs
-----------?---------??----------?-----??----
????????????????19469????????????????????1
- 上一篇:C#信號處理,快速FFT,傅里葉變換,頻譜圖
- 下一篇:C#圖片移動
評論
共有 條評論