1 Star 0 Fork 0

OliverKung/mcu_fft

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
mcu_fft_samp.cpp 2.07 KB
一键复制 编辑 原始数据 按行查看 历史
OliverKung 提交于 2020-02-13 00:32 . mcu_fft示例
#define Num 8192//1024pts;
#define Pi 3.1415926535897932384626433832795028841971
#define sampleTime 0.000001//1Msps
#define BaseFreq 10000
#include <iostream>
#include <fstream>
#include <iomanip>
#include<math.h>
extern "C"
{
#include "mcu_fft.h"
}
int main()
{
double data[Num] = { 0 }, dataInt[Num] = { 0 };
data[0] = 1;
double FIR_Sequence[] = { 1.59580293420777e-05,-0.000546752692664573,
0.0011539697641281,-0.00165186352705445,0.00136270810593162,
0.000301689639400425,-0.00336736150662413,0.0068516837425501,
-0.00875374001783947,0.00673016832708933,0.000624636982277882,
-0.012389500474644,0.0245743565399063,-0.030678590719918,
0.0237063633495183,0.0009328600206886,-0.0427953869544021,
0.0953194930896113,-0.147052050766303,0.184999634419181,
0.801061092948126,0.184999634419181,-0.147052050766303,
0.0953194930896113,-0.0427953869544021,0.0009328600206886,
0.0237063633495183,-0.030678590719918,0.0245743565399063,
-0.012389500474644,0.000624636982277882,0.00673016832708933,
-0.00875374001783947,0.0068516837425501,-0.00336736150662413,
0.000301689639400425,0.00136270810593162,-0.00165186352705445,
0.0011539697641281,-0.000546752692664573,1.59580293420777e-05 };
int FIR_Seq_int[sizeof(FIR_Sequence) / sizeof(FIR_Sequence[0])] = { 0 };
std::ofstream f1("dataCos.csv");
double data_af_FIR[Num] = { 0 };
for (int i = 0; i < sizeof(data) / sizeof(data[0]); i++)
{
data[i] += 0.25 * cos(sampleTime * double(i) * 2 * Pi * 10000) + 0.25 * cos(sampleTime * double(i) * 2 * Pi * 100000) + 0.25 * cos(sampleTime * double(i) * 2 * Pi * 300000) + 0.25 * cos(sampleTime * double(i) * 2 * Pi * 460000);
data_af_FIR[i] = data[i];
}
mcu_FIR_usage(data_af_FIR, FIR_Sequence, Num, 41, 32768);
double freq_Mark_USR[Num] = { 0 };
mcu_fft_usage(data, sampleTime, Num, freq_Mark_USR);
mcu_fft_usage(data_af_FIR, sampleTime, Num, freq_Mark_USR);
for (int i = 0; i < Num; i++)
{
f1 << std::fixed << std::setprecision(4) << freq_Mark_USR[i] << "," << data[i] << "," << data_af_FIR[i] << std::endl;
}
f1.close();
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C
1
https://gitee.com/OliverKung/mcu_fft.git
git@gitee.com:OliverKung/mcu_fft.git
OliverKung
mcu_fft
mcu_fft
master

搜索帮助