$30.00
In this lab, we will consider different types of digital filters and look at their characterization
in time and frequency. This will give you some insight into how digital filters are
implemented and designed and into the properties of different digital filter design algorithms.
1. Filter Implementation and Characterization
Digital filters are usually implemented using a difference equation
y[n]=(1/a0)[b0x[n] + b1x[n-1] + … + bMx[n-M] – a1y[n-1] … – aNy[n-N]]
assuming a causal filter. In MATLAB, this is implemented with the filter command:
y=filter(b,a,x)
where vector a=[ a0 … aN ], b=[ b0 … bM ], and x and y are finite-length input and output
sequences.
You can also implement a filter using the MATLAB convolution function
y=conv(x,h,’same’)
given an impulse response, which you can find by using the filter command with a unit
impulse function, e.g.
impulse = [1 zeros(1,49)];
h=filter(b,a,impulse);
will give you the impulse response up to length 50. The ‘same’ flag will give you an output
that is the same length as x, which will be comparable to what you get with the filter
command. (Without that flag you will get the result with length corresponding to the sum of
the lengths of x and h, which pads x with zeroes at the end.)
Both filter and conv assume zero values for the x signal before its start time.
Like continuous LTI systems, a digital filter can be characterized in the time domain and the
frequency domain. The MATLAB function
freqz(b,a)
will give you log magnitude and unwrapped phase plots for the filter frequency response over
positive normalized frequency [0,0.5]. (Recall that normalized frequency is periodic with
period 1, and [0,0.5] in normalized frequency corresponds to [0, π ] in radians for the DTFT.)
Look at the freqz documentation to find out how you can get values to plot over radians or
Hz.
In order to understand the behavior of different filters in different domains, we will
experiment with a moving average filter and a first difference filter. Download the text file
containing Microsoft stock price over 4 years from the class web site. Load the data using
load command, and plot it. Note that the quick changes correspond to the high frequency
component. People tend to invest based on the long-term trend, which we can find using a
moving average filter. Consider the 30-day moving average filter:
y[n]=1/30( x[n] + x[n-1] + … x[n-29] )
Implement this filter in MATLAB using both the conv and filter functions to confirm that you
get the same answer when applied on the stock data. Note that the big jump at the onset of the
filtered signal is associated with zero-padding – start your plot at sample n=30 to avoid this
artifact. Plot the original and filtered signal together, with the filtered signal plotted in red.
Does the filtered result look smoother?
A simple filter for pulling out the high frequency trends is the first difference:
y[n]=x[n]-x[n-1]
Find the a and b coefficients for this filter, use them to filter the stock signal, and plot the
result.
Plot the frequency response for both filters over the same time range and verify that the
moving average system is a low-pass filter and the first difference system is a high-pass filter.
Note the difference in scale of the two different filtered time signals.
IN-LAB CHECK-OFF: Show your TA your plot of the original and filtered stock data, the
plot of the first-difference filtered signal, and the plot of the log magnitude frequency
responses for each of the two systems. Be sure to label the axes of the plots.
2. Filter Design
MATLAB has numerous built-in functions for generating discrete time filters. In this problem
we are going to use two to look at how FIR vs. IIR systems behave in the frequency domain.
You will not be expected to understand the details of how these algorithms work; you only
need to evaluate their behavior.
Both the filter design functions in the problems below ask you to specify cut-offs in terms
of 0 < W < 1, where W=1 corresponds to half the sampling frequency. So, a cut-off frequency
of 0 < W < 1 corresponds to 0 < v < p in radians for the DTFT, and 0
WhatsApp us