套MATLAB帮助的代码,观察四个正弦波的叠加的频域
不太懂fft,进一步研究去
上代码
clear all;
close all;
clc;
Fs = 100; % Sampling frequency
T = 1/Fs; % Sample time
L = 10000; % Length of signal
t = (0:L-1)*T; % Time vector
%y=exp(-t).*(sin(5*t)+sin(3*t)+sin(t)+sin(40*t));
%this is a signal of f=5Hz,3Hz,1Hz,40Hz;
%y=(sin(2*pi*5*t)+sin(2*pi*3*t)+sin(2*pi*t)+sin(2*pi*40*t));
figure(1)
plot(t,y)
title('Signals')
xlabel('time (seconds)')
NFFT = 2^nextpow2(L); % Next power of 2 from length of y
Y = fft(y,NFFT)/L;
f = Fs/2*linspace(0,1,NFFT/2+1);
% Plot single-sided amplitude spectrum.
figure(2)
plot(f,2*abs(Y(1:NFFT/2+1)))
title('Single-Sided Amplitude Spectrum of y(t)')
xlabel('Frequency (Hz)')
ylabel('|Y(f)|')
采样1000Hz
采样100Hz 10s
采样100Hz