Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Docx

Download as pdf or txt
Download as pdf or txt
You are on page 1of 9

Lab 7 Report

October XX, 2017

3 Lab Exercises: FIR Filters


In the following sections we will study how a filter can produce the following special effects:
1. Echo: FIR filters can produce echoes and reverberations because the filtering formula (1)
contains delay terms. In an image, such phenomena would be called “ghosts.”
2. Deconvolution: one FIR filter can (approximately) undo the effects of another—we will
investigate a cascade of two FIR filters that distort and then restore an image. This process is
called deconvolution.

3.1 Deconvolution
Experiment for 1-D Filters Use the function firfilt( ) to implement the following FIR filter w[n] =
x[n] − 0.9x[n − 1] (3) on the input signal x[n] defined via the MATLAB statement: xx =
256*(rem(0:100,50)< 50)<10)

(a) Plot both the input and output waveforms x[n] and w[n] on the same figure, using subplot.
Make the discrete-time signal plots with MATLAB’s stem function, but restrict the horizontal axis
to the range 0 ≤ n ≤ 75. Explain why the output appears the way it does by figuring out
(mathematically) the effect of the filter coefficients in (3).

The length of the filtered signal can be found by diving the sum of the input signal length by
two. The output looks the way it does because of the chosen ii values and the firfilt function.

This study source was downloaded by 100000855488883 from CourseHero.com on 11-13-2022 17:52:21 GMT -06:00

https://www.coursehero.com/file/25422460/Lab-7-Reportdocx/
(b) Note that w[n] and x[n] are not the same length. Determine the length of the filtered signal
w[n], and explain how its length is related to the length of x[n] and the length of the FIR filter. (If
you need a hint refer to Section 1.2.)

The length of the filtered signal can be found by diving the sum of the input signal length by
two. The firfilt function offers a larger class of filters than the FIR case. It can preform
convolution. The lengths are all finite because they’re stored as vectors of length L.

3.1.1 Restoration Filter The following FIR filter

can be use to undo the effects of the FIR filter in the previous section (see the block diagram in
Fig. 3). It performs restoration, but it only does this approximately. Use the following steps to
show how well it works when r = 0.9 and M = 22.

(a) Process the signal w[n] from (3) with FILTER-2 to obtain the output signal y[n].
(b) Make stem plots of w[n] and y[n] using a time-index axis n that is the same for both signals.
Put the stem plots in the same window for comparison—using a two-panel subplot.
(c) Since the objective of the restoration filter is to produce a y[n] that is almost identical to x[n],
make a plot of the error (difference) between x[n] and y[n] over the range 0 ≤ n < 50.

This study source was downloaded by 100000855488883 from CourseHero.com on 11-13-2022 17:52:21 GMT -06:00

https://www.coursehero.com/file/25422460/Lab-7-Reportdocx/
3.1.2 Worst-Case Error

(a) Evaluate the worst-case error by doing the following: use MATLAB’s max() function to find
the maximum of the difference between y[n] and x[n] in the range 0 ≤ n < 50.
(b) What does the error plot and worst case error tell you about the quality of the restoration of
x[n]? How small do you think the worst case error has to be so that it cannot be seen on a plot?

This study source was downloaded by 100000855488883 from CourseHero.com on 11-13-2022 17:52:21 GMT -06:00

https://www.coursehero.com/file/25422460/Lab-7-Reportdocx/
By using the max() function the maximum difference between y and x [n] can be found in the
range of 0<n<50. The answer is 22.69 and this worst case error shows that this is an acceptable
restoration. An error won’t be zero usually.

3.1.3 An Echo Filter

The following FIR filter can be interpreted as an echo filter. y1[n] = x1[n] + r x1[n − P]
Explain why this is a valid interpretation by working out the following:

(a) You have an audio signal sampled at fs = 8000 Hz and you would like to add a delayed
version of the signal to simulate an echo. The time delay of the echo should be 0.2 seconds, and
the strength of the echo should be 90% percent of the original. Determine the values of r and P
in (4); make P an integer.
(b) Describe the filter coefficients of this FIR filter, and determine its length.
(c) Implement the echo filter in (4) with the values of r and P determined in part (a). Use the
speech signal in the vector x2 found in the file labdat.mat. Listen to the result to verify that you
have produced an audible echo.
(d) (Optional) Implement an echo filter and apply it to your synthesized music from Lab #4. You
will have to change the calculation of P if you used fs = 11025 Hz. Reduce the echo time (from
0.2 secs. down to zero) and try to determine the shortest echo time that can be perceived by
human hearing.

If the audio is sampled at 8000Hz and there is a delay of about 0.2 seconds than the echo
should be 90% a strong as the original signal. R = 0.9 and P = 1600 while the length of the filter
is 24576x1, which can be found by using the whos function.

3.2 Cascading Two Systems

More complicated systems are often made up from simple building blocks. In the system of Fig.
3 two FIR filters are connected “in cascade.” For this section, assume that the the filters in Fig. 3
are described by the two equations: w[n] = x[n] − q x[n − 1] (FIR FILTER-1) y[n] = X M `=0 r `w[n −
`] (FIR FILTER-2) ✲ FIR ✲ ✲ FILTER-1 FIR FILTER-2 x[n] w[n] y[n] Figure 3: Cascading two FIR
filters: the second filter attempts to “deconvolve” the distortion introduced by the first.

This study source was downloaded by 100000855488883 from CourseHero.com on 11-13-2022 17:52:21 GMT -06:00

https://www.coursehero.com/file/25422460/Lab-7-Reportdocx/
3.2.1 Overall Impulse Response
(a) Implement the system in Fig. 3 using MATLAB to get the impulse response of the overall
cascaded system for the case where q = 0.9, r = 0.9 and M = 22. Use two calls to firfilt(). Plot the
impulse response of the overall cascaded system.
(b) Work out the impulse response h[n] of the cascaded system by hand to verify that your
MATLAB result in part (a) is correct. (Hint: consult old Homework problems.)
(c) In a deconvolution application, the second system (FIR FILTER-2) tries to undo the
convolutional effect of the first. Perfect deconvolution would require that the cascade
combination of the two systems be equivalent to the identity system: y[n] = x[n]. If the impulse
responses of the two systems are h1[n] and h2[n], state the condition on h1[n] ∗ h2[n] to
achieve perfect deconvolution.1 1Note: the cascade of FIR FILTER-1 and FILTER-2 does not
perform perfect deconvolution.

Q = 0.9 = r and M = 22.

This study source was downloaded by 100000855488883 from CourseHero.com on 11-13-2022 17:52:21 GMT -06:00

https://www.coursehero.com/file/25422460/Lab-7-Reportdocx/
Distorting and Restoring Images
If we pick q to be a little less than 1.0, then the first system (FIR FILTER-1) will cause distortion
when applied to the rows and columns of an image. The objective in this section is to show that
we can use the second system (FIR FILTER-2) to undo this distortion (more or less). Since FIR
FILTER-2 will try to undo the convolutional effect of the first, it acts as a deconvolution operator.
(a) Load in the image echart.mat with the load command. It creates a matrix called echart.
echart.mat
(b) Pick q = 0.9 in FILTER-1 and filter the image echart in both directions: apply FILTER-1 along
the horizontal direction and then filter the resulting image along the vertical direction also with
FILTER-1. Call the result ech90.
(c) Deconvolve ech90 with FIR FILTER-2, choosing M = 22 and r = 0.9. Describe the visual
appearance of the output, and explain its features by invoking your mathematical
understanding of the cascade filtering process. Explain why you see “ghosts” in the output
image, and use some previous calculations to determine how big the ghosts (or echoes) are, and
where they are located. Evaluate the worst-case error in order to say how big the ghosts are
relative to “black-white” transitions which are 0 to 255.

You see ghosts because the deconvolution was not correctly done because the convolution was
don along the axis. The ghosts persist because of the incorrect deconvolution. The first signal
was subtracted from the deconvolved signal that was filtered. The max error for the worst case
is 42.2 - max(max(maxerror)) and the max error is 17.73% for M=22.

This study source was downloaded by 100000855488883 from CourseHero.com on 11-13-2022 17:52:21 GMT -06:00

https://www.coursehero.com/file/25422460/Lab-7-Reportdocx/
3.2.3 A Second Restoration Experiment

(a) Now try to deconvolve ech90 with several different FIR filters for FILTER-2. You should set r =
0.9 and try several values for M such as 11, 22 and 33. Pick the best result and explain why it is
the best. Describe the visual appearance of the output, and explain its features by invoking your
mathematical understanding of the cascade filtering process. HINT: determine the impulse
response of the cascaded system and relate it to the visual appearance of the output image.
Hint: you can use dconvdemo to generate the impulse responses of the cascaded systems, like
you did in the Warm-up.

This study source was downloaded by 100000855488883 from CourseHero.com on 11-13-2022 17:52:21 GMT -06:00

https://www.coursehero.com/file/25422460/Lab-7-Reportdocx/
(b) Furthermore, when you consider that a gray-scale display has 256 levels, how large is the
worst-case error (from the previous part) in terms of number of gray levels? Do this calculation
for each of the three filters in part (a). Think about the following question: “Can your eyes
perceive a gray scale change of one level, i.e., one part in 256?” Include all images and plots for
the previous two parts to support your discussions in the lab report.

The worst case was for M = 33 was (14.185), for M = 11 was (144.04). Three echoes can be seen
in M = 11.

M = 33:
M = 11:

This study source was downloaded by 100000855488883 from CourseHero.com on 11-13-2022 17:52:21 GMT -06:00

https://www.coursehero.com/file/25422460/Lab-7-Reportdocx/
This study source was downloaded by 100000855488883 from CourseHero.com on 11-13-2022 17:52:21 GMT -06:00

https://www.coursehero.com/file/25422460/Lab-7-Reportdocx/
Powered by TCPDF (www.tcpdf.org)

You might also like