370 Practical MATLAB® Applications for Engineers
ynoise = 3*cos(2*pi*x/2000)+noise;
subplot(2,2,2)
plot(x,y);title(‘Sinusoid test funct ‘);
ylabel(‘Amplitude’)
axis([0 4000 -4 4]);
subplot(2,2,3)
plot(x,noise);title(‘noise vs. t’)
ylabel(‘Amplitude’)
axis([0 100 -1 3]);
xlabel(‘time’);
subplot(2,2,4)
plot(x,ynoise)
xlabel(‘time’);title(‘[sinusoid+noise] vs. t’);
ylabel(‘Amplitude’)
axis([0 1000 -6 6]);
figure(2)
subplot(2,2,1)
specgram(mtlb);title(‘spectrogram of the speech file mtlb’)
subplot(2,2,2)
psd(mtlb);title(‘power spec. den.of mtlb’)
subplot(2,2,3)
specgram(ynoise);
title(‘specgram of sinusoid+noise’)
subplot(2,2,4)
psd(ynoise);
title(‘power spec. den. of sinus.+noise’)
The script fi le specpsol is executed and the resulting plots are shown in Figures 4.20
and 4.21.
FIGURE 4.20
Plots of parts 1, 2, 3, and 4 of R.4.125.
[Speech file mtlb] versus t
4
2
− 2
− 4
0 0 3 2 1 0 0
− 1
Amplitude
1000 2000 3000 4000
noise versus t
Amplitude
50 100
time
Sinusoid test funct
4
2
− 2
− 4
0
Amplitude
0 1000 2000 3000 4000
[sinusoid+noise] versus t
6
4
2
0
− 2
− 4
− 6
0 500
Amplitude
1000
time