附图3的代码:
function Accumulation()
%关于时域方波函数的仿真
Fs=100; % Sampling frequency
T=1/Fs; % Sample time
L=100; % Length of signal
t=(0:L-1)*T; % Time vector
%绘制占空比为40%的方波图形
y1=zeros(1,L); y1(1:0.4*L)=1;
subplot(121); plot(t,y1);
title('占空比为40%的矩形波');
xlabel('Time'); ylabel('Amplitude');
%作出对应的频谱图形
NFFT=1024;
Y1=fft(y1,NFFT)/(0.4*L);
f1=Fs/2*linspace(0,1,NFFT/2+1);
subplot(122); plot(f1,2*abs(Y1(1:NFFT/2+1)));
title('占空比为40%的矩形波对应的频谱函数');
xlabel('Frequency (Hz)'); ylabel('|Y(f)|');