78 Practical MATLAB® Applications for Engineers
FIGURE 1.63
Plots of f(n), noise signal[n(t)], and [f(n) + n(t)] of Example 1.15.
Signal versus n10501002468101214161820− 10 2 4 6 8 101214 161820AmplitudeAmplitudeAmplitude [signal+noise]time index ntime index ntime index nNoise versus n1050
0 2 4 6 8 10 12 14 16 18 20[Signal+Noise] versus n>> averages
********************************************************
*******************ANALYSIS OF ERROR*******************
********************************************************
no ave 2 term ave 3 term ave 4 term ave
0.5389 0.5276 0.7011 0.9793
********************************************************
********************************************************
>> averages
********************************************************
*******************ANALYSIS OF ERROR*******************
**************************************************
no ave 2 term ave 3 term ave 4 term ave
0.5272 0.4794 0.6574 0.9033
********************************************************
********************************************************
>> averages
********************************************************
*******************ANALYSIS OF ERROR*******************
**************************************************
no ave 2 term ave 3 term ave 4 term ave
0.4144 0.3750 0.5572 0.8223
********************************************************
********************************************************
Observe that the results obtained by executing the script fi le averages three times are not
the same, but in each case the best results are achieved when the moving average uses
two terms.