dsp2
dsp2
Theory
Convolution is a fundamental operation in signal processing used to determine the output of a system based on its
input and impulse response.
• Linear convolution gives the true time-domain response of a Linear Time-Invariant (LTI) system and is typically
used in system analysis.
• Circular convolution is a periodic version of convolution, often used in frequency-domain processing and in the
implementation of convolution via the Discrete Fourier Transform (DFT).
In this experiment, both methods were implemented to observe their differences and understand their
applications.
%Linear Convolution
subplot(3,1,1); % Divide the figure into 3 rows, 1 column, and select 1st subplot
ylabel('Amplitude->');
xlabel('N->');
ylabel('Amplitude->');
xlabel('N->');
ylabel('Amplitude->');
xlabel('N->');
Output:
>> convolution_ok
y=
4 11 20 30 20 11 4
Conclusion
The experiment successfully demonstrated the computation of both linear and circular convolution using a program.
While linear convolution provides the complete output sequence, circular convolution results in a periodic output that
may differ unless zero-padding is applied. Understanding both is crucial for practical signal processing tasks, especially
in digital filter design and frequency-domain analysis.
Experiment 7:
Title: To find the frequency response of a given system (Transfer Function/ Difference equation form)
Theory
The frequency response of a system describes how it reacts to different frequency components of an input signal. It is
typically expressed in terms of magnitude and phase versus frequency.
• When given a transfer function, the frequency response is obtained by evaluating the system function
H(ejω)H(e^{j\omega})H(ejω) over a range of frequencies.
• If the system is given in difference equation form, it can be converted to the transfer function using the Z-
transform.
Frequency response analysis helps in understanding filter characteristics like passband, stopband, and system stability.
Program:-
% Define the frequency range over which to evaluate the frequency response
subplot(2, 1, 1); % Divide figure into 2 rows, 1 column; use 1st plot
xlabel('Frequency \omega');
ylabel('Magnitude');
title('Magnitude Response');
xlabel('Frequency \omega');
ylabel('Phase (Radians)');
title('Phase Response');
output:
Conclusion
In this experiment, the frequency response of a given discrete-time system was successfully computed and visualized.
The results provided insights into how the system amplifies or attenuates different frequency components. Such
analysis is essential in designing and evaluating digital filters and signal processing systems.
Experiment 8:
Theory: In statistical signal processing the power spectral density is a positive real function of a frequency variable
associated with a stationary stochastic process, or a deterministic function of time, which has dimensions of power per
Hz, or energy per Hz. It is often called simply the spectrum of the signal. Intuitively, the spectral density captures the
frequency content of a stochastic process and helps identify periodicities. The PSD is the FT of autocorrelation
function, R(τ) of the signal if the signal can be treated as a wide-sense stationary random process.
Program:
% Create signal composed of two sine waves (50 Hz and 120 Hz)
x = sin(2*pi*50*t) + sin(2*pi*120*t);
figure;
xlabel('Time (milliseconds)');
Y = fft(y, 512);
figure;
plot(f, Pyy(1:257)); % Plot only the first half of the symmetric spectrum
title('Frequency Content of y');
xlabel('Frequency (Hz)');
ylabel('Power/Frequency');
Conclusion
In this experiment, the Power Spectral Density (PSD) of a signal was successfully computed and analyzed. The PSD
provided valuable insights into the frequency components present in the signal and their corresponding power
distribution. By applying the Fourier Transform to the autocorrelation function or directly using the FFT, we were able
to visualize how the signal's energy is distributed over different frequencies. This analysis is fundamental in identifying
dominant frequency components, filtering noise, and understanding the behavior of signals in various signal
processing and communication applications
Experiment 9:
Algorithm:-
1) Enter the pass band ripple (rp) and stop band ripple (rs).
2) Enter the pass band frequency (fp) and stop band frequency (fs).
4) Calculate the analog pass band edge frequencies, w1 and w2. w1 = 2*fp/f w2 = 2*fs/f
6) Use an If condition and ask the user to choose either Rectangular Window or Triangular window or Kaiser window..
10) Give relevant names to x and y axes and give an appropriate title for the plot.
11) Plot all the responses in a single figure window. [Make use of subplot]
Program:-
clc;
clear all;
close all;
% User inputs
wp = 2 * fp / f;
ws = 2 * fs / f;
% Estimate filter order
n = ceil(num / dem);
n1 = n + 1;
if rem(n, 2) ~= 0
n1 = n;
n = n - 1;
end
% Window selection
c = input('Enter your choice of window function:\n 1. Rectangular\n 2. Triangular\n 3. Kaiser\nYour choice: ');
if (c == 1)
y = rectwin(n1);
elseif (c == 2)
y = triang(n1);
elseif (c == 3)
y = kaiser(n1, beta);
else
end
m = 20 * log10(abs(h)); % Magnitude in dB
% Plotting the frequency response
plot(o/pi, m);
ylabel('Gain (dB)');
grid on;
Output:-
10000
Algorithm:-
1) Enter the pass band ripple (rp) and stop band ripple (rs).
2) Enter the pass band frequency (fp) and stop band frequency (fs).
w1 = 2*fp/f w2 = 2*fs/f
6) Use an If condition and ask the user to choose either Rectangular Window or Triangular window or Kaiser window..
10) Give relevant names to x and y axes and give an appropriate title for the plot.
11) Plot all the responses in a single figure window.[Make use of subplot]
Program:-
clc;
clear all;
close all;
wp = 2 * fp / f;
ws = 2 * fs / f;
n = ceil(num / dem);
n1 = n + 1;
if rem(n, 2) ~= 0
n1 = n;
n = n - 1;
end
c = input('Enter your choice of window function:\n 1. Rectangular\n 2. Triangular\n 3. Kaiser\nYour choice: ');
if c == 1
y = rectwin(n1);
elseif c == 2
y = triang(n1);
elseif c == 3
y = kaiser(n1, beta);
else
end
b = fir1(n, wp, 'high', y); % High-pass FIR filter design using selected window
% Frequency response calculation
plot(o/pi, m);
ylabel('Gain (dB)');
grid on;
Output:-
10000
Algorithm:-
1) Enter the pass band ripple (rp) and stop band ripple (rs).
2) Enter the pass band frequency (fp) and stop band frequency (fs).
4) Calculate the analog pass band edge frequencies, w1 and w2. w1 = 2*fp/f w2 = 2*fs/f
5) Calculate the order and 3dB cutoff frequency of the analog filter. [Make use of the following function]
[n,wn]=buttord(w1,w2,rp,rs,‟s‟)
6) Design an nth order analog lowpass Butter worth filter using the following statement.
[b,a]=butter(n,wn,‟s‟)
7) Find the complex frequency response of the filter by using „freqs( )‟ function
This function returns complex frequency response vector „h‟ and frequency vector „om‟ in radians/samples of the
filter.
11) Plot the phase response [phase in radians Vs normalized frequency (om/pi)]
12) Give relevant names to x and y axes and give an appropriate title for the plot.
13) Plot all the responses in a single figure window. [Make use of subplot]
Program :-
% IIR filters
clc;
clear all;
close all;
warning off;
% User inputs
[n, wn] = buttord(w1, w2, rp, rs, 's'); % For analog prototype filter
m = 20 * log10(abs(h));
subplot(2,1,1);
plot(om/pi, m);
ylabel('Gain (dB)');
grid on;
an = angle(h);
subplot(2,1,2);
plot(om/pi, an);
ylabel('Phase (radians)');
grid on;
Output:-
enter the IIR filte r design s pecifications enter the pass band ripple 0. 15
enter the stopband ripple 60 enter the pass band freq1500 enter the stopband freq3000 enter the sampling frq7000
Frequency response of II R L P F is :
Experiment 12:
Aim: -To Design and generate IIR Butterworth Analog HP Filter using MATLAB
Algorithm:-
1) Enter the pass band ripple (rp) and stop band ripple (rs).
2) Enter the pass band frequency (fp) and stop band frequency (fs).
w1 = 2*fp/f w2 = 2*fs/f
5) Calculate the order and 3dB cutoff frequency of the analog filter. [Make use of the following function]
[n,wn]=buttord(w1,w2,rp,rs,‟s‟)
6) Design an nth order analog high pass Butter worth filter using the following statement.
[b,a]=butter(n,wn,‟high‟,‟s‟)
7) Find the complex frequency response of the filter by using „freqs( )‟ function [h,om]=freqs(b,a,w) where, w =
0:.01:pi
This function returns complex frequency response vector „h‟ and frequency vector „om‟ in radians/samples of the
filter.
11) Plot the phase response [phase in radians Vs normalized frequency (om/pi)]
12) Give relevant names to x and y axes and give an appropriate title for the plot.
13) Plot all the responses in a single figure window.[Make use of subplot]
Program :-
% IIR filters
clc;
clear all;
close all;
warning off;
% User inputs
rp = input('Enter the passband ripple (dB): '); % e.g., 1
m = 20 * log10(abs(h));
subplot(2,1,1);
plot(om/pi, m);
ylabel('Gain (dB)');
grid on;
% Plot phase response
an = angle(h);
subplot(2,1,2);
plot(om/pi, an);
ylabel('Phase (radians)');
grid on;
Output:-
enter the II R filter design specifications enter the pass band ripple 0. 15
enter the stop band ripple 60 enter the pass band freq1500 enter the stop band freq3000 enter the sampling freq7000
Conclusion
In this set of experiments, we successfully designed and analyzed both FIR and IIR filters using various techniques. FIR
filters were implemented using windowing methods (Rectangular, Triangular, and Kaiser) and were observed to provide
linear phase characteristics, making them suitable for phase-sensitive applications. IIR filters, designed using
Butterworth approximation in both low-pass and high-pass configurations, demonstrated sharp frequency responses
with lower filter orders, but at the cost of nonlinear phase.
Through frequency response plots, we evaluated the magnitude and phase behavior of each filter type. The practical
understanding of filter design parameters such as passband/stopband frequencies, ripples, and filter order was
reinforced. These experiments highlighted the trade-offs between FIR and IIR filters in terms of complexity, stability,
and performance, essential for real-world signal processing applications.