Objective:: in All Exercises, Remember To Import The Necessary Libraries
Objective:: in All Exercises, Remember To Import The Necessary Libraries
Tp2
Objective:
The objective of this lab is to provide a practical and theoretical understanding of filters
used in signal processing, enabling students to select and adapt the appropriate type of
filter based on the signal characteristics and processing goals. Students will have the
opportunity to understand the importance of windowing in signal processing to design
effective filters. They will become familiar with comb filters, averaging filters, linear phase
filters, and notch filters by applying them to a common signal processing task.
Exercise 2
Let’s consider the following program: what do the two functions represent?
return fir_coefficients
w, h = freqz(fir_filter, worN=8000)
frequencies = w * fs / (2 * np.pi)
1. Plot the frequency response of the filter on a graph with three subplots:
• The first subplot should show the magnitude response (in dB) of the filter.
• The second subplot should display the phase response (in radians) of the filter.
• The third subplot should illustrate the group delay of the filter (in samples).
2. Add titles and axis labels to make the graphs informative.
3. Discuss the results obtained:
4. What is the passband of the filter?
5. How does the group delay vary with frequency?
6. What impact could this have on signals processed by the filter?
7. Modify the cutoff frequency and the number of taps (coefficients) to observe how this
affects the frequency response and group delay. Test at least three different cutoff
frequencies (for example, 50 Hz, 100 Hz, and 200 Hz) and different numbers of taps (for
example, 31, 51, and 101).
Exercise 3
Let the following program
def moving_average_filter(x, window_size):
DSP / 3 ING / 2024_2025 3
4. What does the window_size parameter control in the moving average filter?
5. What does the np.ones(window_size) / window_size expression do?
6. What is the role of coef in the all_pass_filter function?
7. What effect does increasing the window_size have on the filtered signal?
8. Explain the purpose of freqz and what it calculates for the filters.
9. Why does the freqz function use a high number of points (2000) for frequency?
10. What is the role of the group_delay function, and what does it represent in the filter’s
context?
11. In the all_pass_filter function, how does changing coef affect the phase response of
the filter?
12. Why is np.unwrap applied to the phase response in the all_pass_filter plot?
13. How would you modify the code to implement a low-pass filter instead of a moving
average filter?
14. Why does the group delay fluctuate at specific frequencies?
15. In practical applications, why might a non-constant group delay be problematic?
16.What are the advantages and limitations of using an all-pass filter, as implemented
here, to alter a signal's phase?
17. If the sampling rate (fs) were doubled, how would the filter responses and signal
representation change?
Exercise 4
We apply a notch filter (band-stop filter) to eliminate unwanted frequency components
in a noisy signal, specifically at 50 Hz and its harmonics (100 Hz and 150 Hz).
Using the given notch_filter function below, apply the notch filter to eliminate the
interferences at 50 Hz, 100 Hz, and 150 Hz from the noisy signal. Graphically represent
the original signal and the filtered signal to compare the effectiveness of the noise
suppression.
Exercise 5
Consider Exercise 2 from the TD series. Develop a program that computes and visualizes
the impulse response, frequency response, phase response, and group delay of the
system. Provide a commentary on the results.