Page 141 - MATLAB Recipes for Earth Sciences
P. 141
6.8 Frequency Response 135
clear
t = (1:100)';
x8 = 2*sin(2*pi*t/20);
A running mean over eleven elements is designed and this filter is applied
to the input signal.
b8 = ones(1,11)/11;
m8 = length(b8);
y8 = filter(b8,1,x8);
The phase is corrected for causal indexing.
y8= y8(1+(m8-1)/2:end-(m8-1)/2,1);
y8(end+1:end+m8-1,1)=zeros(m8-1,1);
Both input and output of the filter are plotted.
plot(t,x8,t,y8)
The filter obviously reduces the amplitude of the sine wave. Whereas the
input signal has an amplitude of 2, the output has an amplitude of
max(y8)
ans =
1.1480
The filter reduces the amplitude of a sine with a period of 20 by
1-max(y8(40:60))/2
ans =
0.4260
i.e., approximately 43%. The elements 40 to 60 are used for computing the
maximum value of y8 in order to avoid edge effects. On the other hand, the
filter does not affect the phase of the sine wave, i.e., both input and output
are in phase.
The same filter, however, has a different impact on a different signal. Let
us design another sine wave with a similar amplitude, but with a different
period of 15.
clear
t = (1:100)';
x9 = 2*sin(2*pi*t/15);
Applying a similar filter and correcting the output for the phase shift of the