DSP Proj Lab
DSP Proj Lab
DSP Proj Lab
EEE-324
Lab Project
Question No#1:
Design a digital FIR lowpass filter (with the following specifications):
Choose an appropriate window function from Table 7.1 of book “Digital signal
processing using MATLAB” 3rd edition by Vinay K. Ingle and John G. Proakis.
(i) Plot the impulse response and frequency responses of the designed filter.
(ii) Chose an input signal of your choice (plot it as well) and show filtered
signal. Do this for both: first by adjusting frequency of input signal within
pass band and then adjusting it into stop band.
Objectives:
The purpose of this project is to design a digital FIR lowpass filter based on the given
specifications:
Uses:
LPF are used to remove noise, smooth signals, anti-aliasing in analog-to-digital
conversion, and extract desired frequency components from a signal while attenuating
unwanted high-frequency components.
Advantages:
The benefit of an FIR low pass filter is its linear
phase response, which preserves the phase
relationships of different frequency components in the filtered signal. This
characteristic is important in applications where phase coherence is essential, such as
audio processing.
Applications:
1. Signal Conditioning: In signal
processing applications, lowpass FIR
filters are used to preprocess signals by
removing high-frequency noise or
interference. This helps improve the signal quality and enhance subsequent
analysis or processing steps.
Impulse Response:
The impulse response of a system, often denoted as h(t) or h[n], refers to the output of
the system when an impulse function is applied as the input. An impulse function is a
signal that is zero everywhere except at a single point, where it has a value of one.
Impulse Response
MATLAB Implementation:
In MATLAB, you can implement the impulse response of a system using the built-in
`impulse` function. The `impulse` function calculates the response of a linear time-
invariant (LTI) system to an impulse input, i.e:
Frequency Response:
The frequency response of a system is a measure of how the system responds to
different frequencies in the input signal. It describes the system's behavior as a
function of frequency and provides important information about its filtering
characteristics and amplitude/phase response.
Visualization:
The frequency response is commonly visualized using a Bode plot, which
shows the magnitude response and phase response as a function of frequency.
The magnitude response is typically plotted on a logarithmic scale (in
decibels) to show the gain/attenuation.
The phase response is plotted in degrees to show the phase shift.
Advantages:
By manipulating the frequency response, we can achieve desired signal processing
goals, such as removing unwanted frequencies, emphasizing specific frequency
ranges, or compensating for phase distortions.
Additionally, the specific implementation details and tools used may vary based on
your application and the software or hardware platform you are working with.
From book
MATLAB Implementation:
As for this task, the Hamming window (w_ham) is created using the
hamming() function with a length of M. The window function is multiplied
element-wise with the ideal impulse response to obtain the actual impulse
response (h).
w=hamming(M) returns the M-point Hamming window function in array w
Tasks:
(i) Plot the impulse response and frequency responses of the
designed filter.
MATLAB Code:
%PART A
% filter specifiaction
wp = 0.2*pi;
ws = 0.3*pi;
Rp = 0.25; %dB
As = 50; %dB
%calculate filter order
tr_width = ws - wp;
M = ceil(6.6*pi/tr_width) + 1
M = 67
n=[0:1:M-1];
% Ideal LPF cutoff frequency
wc = (ws+wp)/2,
%ideal impulse response
hd = ideal_lp(wc,M);
%apply window function
w_ham= (hamming(M))';
h = hd .* w_ham;
%frequency response
[db,mag,pha,grd,w] = freqz_m(h,[1]);
H=freqz_m(h,[1]);
delta_w = 2*pi/1000;
% plots
figure;
stem(n,hd,'b', 'LineWidth', 2);
title('Ideal Impulse Response')
axis([0 M-1 -0.1 0.3]);
xlabel('n');
ylabel('hd(n)')
figure;
stem(n,w_ham,'b', 'LineWidth', 2);
title('Hamming Window')
axis([0 M-1 0 1.1]);
xlabel('n');
ylabel('w(n)')
figure;
stem(n,h,'r', 'LineWidth', 2);
title('Actual Impulse Response')
axis([0 M-1 -0.1 0.3]);
xlabel('n');
ylabel('h(n)')
figure;
plot(w/pi,db,'b', 'LineWidth', 2);
title('Magnitude Response in dB');grid
axis([0 1 -100 10]);
xlabel('frequency in pi units');
ylabel('Decibels')
figure;
plot(w,H,'r', 'LineWidth', 2);
xlabel('Frequency');
ylabel('Magnitude (dB)');
title('Frequency Response');
grid on;
Explanation:
This code is used to design a low-pass filter & to plot impulse & frequency response,
using the windowing method. The step-to-step explanation of the functionality is as
below:
figure;
plot(t, xstop, 'g', 'LineWidth', 2);
axis([0 1 0 2]);
xlabel('Time');
ylabel('Amplitude');
title('Input Signal (Stopband)');
grid on;
figure;
plot(t, ystop, 'b', 'LineWidth', 2);
axis([0 1 0 2]);
xlabel('Time');
ylabel('Amplitude');
title('Filtering a Signal within the Stopband');
grid on;
Explanation:
This code demonstrates the application of the previously designed low-pass filter to
input signals within the passband and stopband. In detail explanation is as follows:
2. Generation of Input Signals: Two input signals are generated, one as xpass
representing a sinusoidal signal with a frequency fpass within the passband,
and second as xstop represents a sinusoidal signal with a frequency fstop
within the stopband.
3. Filtering the Input Signals: The input signals are convolved with the filter
impulse response h using the conv function. The 'same' parameter ensures
that the output signal has the same length as the input signal. The filtered
signals are stored in ypass and ystop respectively.
4. Plotting the Input and Filtered Signals: The code includes four plot commands
to visualize the input signals and the filtered signals. The first two plots show
the input signal within the passband (xpass) and the corresponding filtered
signal (ypass). The next two plots display the input signal within the stopband
(xstop) and the filtered signal (ystop).
Critical Analysis:
FIR filters are widely utilized due to their numerous advantages. They benefit from
efficient design algorithms, inherent stability when implemented in a non-recursive
form, the ability to achieve linear phase easily, seamless extensibility to multirate
scenarios, and robust hardware support. This project demonstrates the capabilities of
the DSP System Toolbox for planning lowpass FIR filters with diverse characteristics.
The fundamental concept behind the window design approach involves selecting an
appropriate ideal frequency-selective filter, which inherently possesses a noncausal
and infinite-duration impulse response. Subsequently, the impulse response is
truncated (or windowed) to obtain a linear-phase and causal FIR filter. Thus, the key
focus of this method lies in choosing suitable windowing functions and ideal filters.
For this particular project, the filter specifications, filter length (M), and Hamming
window function (w(n)) were chosen. Initially, the project explored a continuous low-
pass filter and simulated its behavior using a digital filter. A band-stop filter, also
known as a band-rejection filter, is designed to block a specific band of frequencies
while leaving others unaltered. On the other hand, a band-pass filter (BPF) allows
frequencies within a certain range to pass through while rejecting those outside the
range.
In Part (i) of the project, the execution focused on analyzing the filter characteristics
without an input signal. However, in Part (ii), an input signal of our choosing was
employed to evaluate the performance of the Hamming window.
Overall, this project highlights the strengths and functionality of FIR filters,
emphasizes the significance of appropriate windowing functions and ideal filters, and
showcases the design capabilities available in the DSP System Toolbox.
References:
“Digital signal processing using MATLAB” 3rd edition by Vinay K. Ingle and
John G. Proakis
https://www.sciencedirect.com/topics/engineering/lowpass-filter
https://www.elprocus.com/fir-filter-for-digital-signal-processing/
http://signalsandsystems.wikidot.com/impulse-response