Page 146 - MATLAB Recipes for Earth Sciences
P. 146
140 6 Signal Processing
xlabel('Frequency')
ylabel('Power')
We add some gaussian noise with amplitude one and explore the signal and
its periodogram.
xn12 = x12 + randn(1,length(t));
plot(t,xn12), axis([0 200 -4 4])
[Pxx,f] = periodogram(xn12,[],1024,1);
plot(f,abs(Pxx))
xlabel('Frequency')
ylabel('Power')
The Butterworth filter design technique is a widely-used method to create
filters of any order with a lowpass, highpass, bandpass and bandstop con-
figuration (Fig. 6.5). In our example, we like to design a fi ve-order lowpass
filter with a cutoff frequency of 0.08. The inputs of the function butter are
the order of the filter and the cutoff frequency normalized to the Nyquist fre-
quency, which is 0.5 in our example, that is half of the sampling frequency.
[b12,a12] = butter(5,0.08/0.5);
The frequency characteristics of the filter shows a relatively smooth transi-
tion from the passband to the stopband, but the advantage of the filter is its
low order.
[h,w] = freqz(b12,a12,1024);
f = w/(2*pi);
plot(f,abs(h)), grid
xlabel('Frequency')
ylabel('Magnitude')
We can again apply the filter to the signal by using the function filter.
However, frequency selective filters such as lowpass, highpass, bandpass
and bandstop are designed to suppress certain frequency bands, whereas
phase shifts should be avoided. The function filtfilt provides zero-phase
forward and reverse digital fi ltering. After filtering in the forward direction,
the filtered sequence is reversed and it runs back through the fi lter. The mag-
nitude of the signal is not affected by this operation, since it is either 0 or
100% of the initial amplitude, depending of the frequency. In contrast, all
phase shifts introduced by the filter are zeroed by the forward and reverse
application of the same filter. This function also helps to overcome the prob-
lems with causal indexing of filters in MATLAB. It eliminates the phase