FFT函数的实现(附Matlab代码)

利用fft函数,实现对100Hz和200Hz信号叠加后信号的频谱分析,分别绘制出了时域和频率的波形。

% fft module
% fft function used
% Date:2020.06.21
% Author:flypassion
clear all
close all
%%------------------ parameter ------------------%%
fs = 2e3; % sampling frequence
f1 = 1e2; % signal 1 frequence
f2 = 2e2; % signal 2 frequence
n = 4; % sampling length
%%------------------ main code ------------------%%
t = 0:1/fs:(n/f1-1/fs);
Signal1 = cos(2*pi*f1*t);
Signal2 = cos(2*pi*f2*t);
MixSignal = Signal1 + Signal2;
AmpFreRes = 20*log10(abs(fft(MixSignal))); % The amplitude frequency response(Power)
%%--------------------- plot --------------------%%
f = 0:fs/2/floor(length(AmpFreRes)/2):fs/2; % conver axis to Hz
p = AmpFreRes(1:length(f));
subplot(2,1,1)
plot(t,MixSignal);
xlabel('时间(s)');ylabel('幅度(v)');title('混合信号的时域波形');
subplot(2,1,2)
plot(f,p);
xlabel('频率(f)');ylabel('功率(dBW)');title('信号频谱图');

FFT函数的实现(附Matlab代码)_第1张图片

 

你可能感兴趣的:(通信知识点,fft,matlab)