Files
TC264_Library_seekfree/Example/FFT_Demo/FFT.m
SEEKFREE_Kang 090685ea66 修改例程名称
修改gpio中断例程,printf在main函数中进行打印
2021-03-11 15:21:15 +08:00

21 lines
851 B
Matlab
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

Fs = 100; % 采样频率100hz
T = 1/Fs; % 采样周期
L = 2000; % 采样数据点个数
x = (0:L-1)*T; % 采样时间表
y1 = 1024 * cos(3 * pi * x) + 512 * cos(7 * pi * x + pi / 2) + 2047 % 建立函数
y2 = fft(y1); % 做FFT运算
p = abs(y2*2)/(L) % 计算幅值,幅值等于复数的模/(L/2)
p = p(1:L/2) % 取前半部分
n = 0:L-1 % 创建横坐标
f = Fs*n/L % 计算横坐标的频率
f = f(1:L/2) % 取横坐标的前半部分 通常我们绘制幅频图只取前面一半进行绘制
%为什么取一半呢这里简单的说明一下我们可以观察计算出来的横坐标频率会看到频率是0-100的样子
%我们学过奈奎斯特定理都知道100hz的采样频率只能完整采样50hz频率的波形。
plot(f,p) % 绘制幅频图像
title('Single-Sided Amplitude Spectrum of y1(f)')
xlabel('频率(Hz)')
ylabel('幅值')