0% found this document useful (0 votes)
4 views

dsp2

The document outlines a series of experiments focused on signal processing techniques, including linear and circular convolution, frequency response analysis, power spectrum determination, and FIR/IIR filter design using MATLAB. Each experiment includes theoretical background, MATLAB code, output examples, and conclusions emphasizing the importance of these methods in signal processing applications. The experiments cover various aspects such as filter design, frequency response visualization, and power spectral density analysis.

Uploaded by

creonzero
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

dsp2

The document outlines a series of experiments focused on signal processing techniques, including linear and circular convolution, frequency response analysis, power spectrum determination, and FIR/IIR filter design using MATLAB. Each experiment includes theoretical background, MATLAB code, output examples, and conclusions emphasizing the importance of these methods in signal processing applications. The experiments cover various aspects such as filter design, frequency response visualization, and power spectral density analysis.

Uploaded by

creonzero
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

Experiment 6:

Title: Program to obtain Linear and circular Convolution

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.

MATLAB code and Output:

%Linear Convolution

clc; % Clear the command window

clear all; % Clear all variables from the workspace

% Take input sequences from the user

x = input('Enter the sequence 1:'); % First input sequence

h = input('Enter the sequence 2:'); % Second input sequence

% Perform linear convolution

y = conv(x, h); % Convolve x and h to get the output sequence y

% Plot the first input sequence

subplot(3,1,1); % Divide the figure into 3 rows, 1 column, and select 1st subplot

stem(x); % Discrete plot of sequence x

ylabel('Amplitude->');

xlabel('N->');

title('Input sequence x');

% Plot the second input sequence

subplot(3,1,2); % Select 2nd subplot

stem(h); % Discrete plot of sequence h

ylabel('Amplitude->');
xlabel('N->');

title('Input sequence h');

% Plot the convolution result

subplot(3,1,3); % Select 3rd subplot

stem(y); % Discrete plot of the convolution result y

ylabel('Amplitude->');

xlabel('N->');

title('Linear Convolution'); % Corrected quotation marks

Output:

>> convolution_ok

Enter the first sequence - [1 2 3 4]

Enter the second sequence - [4 3 2 1]

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 numerator and denominator coefficients of the transfer function

b = [1, 4]; % Numerator coefficients of H(z)

a = [1, -5]; % Denominator coefficients of H(z)

% Define the frequency range over which to evaluate the frequency response

w = -2*pi : pi/256 : 2*pi; % Frequency vector from -2π to 2π

% Compute the frequency response of the system

h = freqz(b, a, w); % Frequency response H(e^jω) over defined frequency range

% Plot the magnitude response

subplot(2, 1, 1); % Divide figure into 2 rows, 1 column; use 1st plot

plot(w, abs(h)); % Plot magnitude of the frequency response

xlabel('Frequency \omega');

ylabel('Magnitude');

title('Magnitude Response');

grid on; % Add grid for better visualization

% Plot the phase response

subplot(2, 1, 2); % Use 2nd plot

plot(w, angle(h)); % Plot phase of the frequency response

xlabel('Frequency \omega');
ylabel('Phase (Radians)');

title('Phase Response');

grid on; % Add grid for better visualization

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:

Title: Determination of the Power Spectrum of a given signal.

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:

% Define time vector

t = 0:0.001:0.6; % Time from 0 to 0.6 seconds with 1 ms sampling interval

% Create signal composed of two sine waves (50 Hz and 120 Hz)

x = sin(2*pi*50*t) + sin(2*pi*120*t);

% Add zero-mean Gaussian noise to the signal

y = x + 2*randn(size(t)); % Noisy signal

% Plot a portion of the noisy signal

figure;

plot(1000*t(1:50), y(1:50)); % Plot first 50 samples (in milliseconds)

title('Signal Corrupted with Zero-Mean Random Noise');

xlabel('Time (milliseconds)');

% Compute the FFT of the noisy signal using 512 points

Y = fft(y, 512);

% Compute Power Spectral Density (PSD)

Pyy = Y .* conj(Y) / 512; % PSD is magnitude squared of FFT normalized by N

% Define frequency vector (only half spectrum due to symmetry)

f = 1000 * (0:256) / 512; % Frequency in Hz (assuming sampling rate = 1000 Hz)

% Plot the one-sided Power Spectral Density

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:

Title: FIR Low pass Filter design

Aim :- To Design FIR LP Filter using Rectangular/Triangular/kaiser Windowing Technique.

Apparatus Used:- system m with MATLAB 6.5.

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).

3) Get the sampling frequency (f), beta value.

4) Calculate the analog pass band edge frequencies, w1 and w2. w1 = 2*fp/f w2 = 2*fs/f

5) calculate the numerator and denominator

6) Use an If condition and ask the user to choose either Rectangular Window or Triangular window or Kaiser window..

7) use rectwin,triang,kaiser commands

8) Calculate the magnitude of the frequency response in decibels (dB m=20*log10(abs(h))

9) Plot the magnitude response [magnitude in dB Vs normalized frequency (om/pi)]

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

rp = input('Enter passband ripple: '); % Example: 0.01

rs = input('Enter stopband ripple: '); % Example: 0.001

fp = input('Enter passband frequency (Hz): '); % Example: 1000

fs = input('Enter stopband frequency (Hz): '); % Example: 1500

f = input('Enter sampling frequency (Hz): '); % Example: 8000

beta = input('Enter beta value for Kaiser window: '); % Example: 5

% Normalized digital frequencies (0 to 1, where 1 = Nyquist = f/2)

wp = 2 * fp / f;

ws = 2 * fs / f;
% Estimate filter order

num = -20 * log10(sqrt(rp * rs)) - 13;

dem = 14.6 * (fs - fp) / f;

n = ceil(num / dem);

n1 = n + 1;

% Make sure filter length is even

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);

disp('Rectangular window filter response');

elseif (c == 2)

y = triang(n1);

disp('Triangular window filter response');

elseif (c == 3)

y = kaiser(n1, beta);

disp('Kaiser window filter response');

else

error('Invalid choice. Please enter 1, 2, or 3.');

end

% FIR Low Pass Filter Design

b = fir1(n, wp, y); % Design filter using selected window

[h, o] = freqz(b, 1, 256); % Frequency response

m = 20 * log10(abs(h)); % Magnitude in dB
% Plotting the frequency response

plot(o/pi, m);

title('Low Pass FIR Filter Response');

ylabel('Gain (dB)');

xlabel('Normalized Frequency (\omega/\pi)');

grid on;

Output:-

enter passband ripple 0.02

enter the stopband ripple 0.01

enter passband freq 1000

enter stopband freq 1500

enter sampling freq enter beta value

10000

enter your choice of window function 1. rectangular 2. triangular 3.kaiser: 1


Experiment 10:

Title: FIR High pass Filter design

To Design FIR HP Filter using Rectangular/Triangular/kaiser Windowing Technique.

Apparatus Used:- S yste m with MAT L A B 6.5.

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).

3) Get the sampling frequency (f), beta value.

4) Calculate the analog pass band edge frequencies, w1 and w2.

w1 = 2*fp/f w2 = 2*fs/f

5) calculate the numerator and denominator

6) Use an If condition and ask the user to choose either Rectangular Window or Triangular window or Kaiser window..

7) use rectwin,triang,kaiser commands

8) Calculate the magnitude of the frequency response in decibels (dB m=20*log10(abs(h))

9) Plot the magnitude response [magnitude in dB Vs normalized frequency (om/pi)]

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 for filter design

rp = input('Enter passband ripple: '); % Example: 0.01

rs = input('Enter stopband ripple: '); % Example: 0.001

fp = input('Enter passband frequency (Hz): '); % Example: 2000

fs = input('Enter stopband frequency (Hz): '); % Example: 1500

f = input('Enter sampling frequency (Hz): '); % Example: 8000

beta = input('Enter beta value for Kaiser window: '); % Example: 5

% Normalize the digital frequencies (0 to 1, where 1 = Nyquist = f/2)

wp = 2 * fp / f;
ws = 2 * fs / f;

% Estimate filter order using empirical formula

num = -20 * log10(sqrt(rp * rs)) - 13;

dem = 14.6 * (fs - fp) / f;

n = ceil(num / dem);

n1 = n + 1;

% Ensure filter length is even (required for linear phase)

if rem(n, 2) ~= 0

n1 = n;

n = n - 1;

end

% Window function 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);

disp('Rectangular window filter response');

elseif c == 2

y = triang(n1);

disp('Triangular window filter response');

elseif c == 3

y = kaiser(n1, beta);

disp('Kaiser window filter response');

else

error('Invalid choice. Please enter 1, 2, or 3.');

end

% FIR High Pass Filter design

b = fir1(n, wp, 'high', y); % High-pass FIR filter design using selected window
% Frequency response calculation

[h, o] = freqz(b, 1, 256); % Frequency response (h = response, o = frequency values)

m = 20 * log10(abs(h)); % Convert magnitude to decibels (dB)

% Plot frequency response

plot(o/pi, m);

title('High Pass FIR Filter Response');

ylabel('Gain (dB)');

xlabel('Normalized Frequency (\omega/\pi)');

grid on;

Output:-

enter passband ripple 0.02

enter the stopband ripple 0.01

enter passband freq 1000

enter stopband freq 1500

enter sampling freq enter beta value

10000

enter your choice of window function 1. rectangular 2. triangular 3.kaiser: 1


Experiment 11:

Title:IIR Low pass Filter design

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).

3) Get the sampling frequency (f).

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

[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.

8) Calculate the magnitude of the frequency response in decibels (dB m=20*log10(abs(h))

9) Plot the magnitude response [magnitude in dB Vs normalized frequency (om/pi)]

10) Calculate the phase response using an = angle(h)

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;

% Display input prompt

disp('Enter the IIR filter design specifications');

% User inputs

rp = input('Enter the passband ripple (dB): '); % Example: 1


rs = input('Enter the stopband ripple (dB): '); % Example: 40

wp = input('Enter the passband frequency (Hz): '); % Example: 1000

ws = input('Enter the stopband frequency (Hz): '); % Example: 1500

fs = input('Enter the sampling frequency (Hz): '); % Example: 8000

% Normalize frequencies for analog design (0 to 1 where 1 = Nyquist)

w1 = 2 * wp / fs; % Normalized passband frequency

w2 = 2 * ws / fs; % Normalized stopband frequency

% Compute the filter order and cutoff using Butterworth approximation

[n, wn] = buttord(w1, w2, rp, rs, 's'); % For analog prototype filter

% Display response type

disp('Frequency response of IIR LPF is:');

% Design analog Butterworth low pass filter

[b, a] = butter(n, wn, 'low', 's'); % Returns analog filter coefficients

% Frequency vector for plotting

w = 0 : 0.01 : pi; % Normalized frequency vector (rad/sample)

% Compute frequency response

[h, om] = freqs(b, a, w); % Frequency response of analog filter

% Convert magnitude to decibels

m = 20 * log10(abs(h));

% Plot magnitude response

subplot(2,1,1);

plot(om/pi, m);

title('Magnitude Response of IIR Low Pass Filter');

xlabel('Normalized Frequency (\omega/\pi)');

ylabel('Gain (dB)');
grid on;

% Plot phase response

an = angle(h);

subplot(2,1,2);

plot(om/pi, an);

title('Phase Response of IIR Low Pass Filter');

xlabel('Normalized Frequency (\omega/\pi)');

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:

Tite: IIR High pass Filter design

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).

3) Get the sampling frequency (f).

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 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.

8) Calculate the magnitude of the frequency response in decibels (dB m=20*log10(abs(h))

9) Plot the magnitude response [magnitude in dB Vs normalized frequency (om/pi)]

10) Calculate the phase response using an = angle(h)

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;

% Prompt user for IIR filter design specifications

disp('Enter the IIR filter design specifications');

% User inputs
rp = input('Enter the passband ripple (dB): '); % e.g., 1

rs = input('Enter the stopband ripple (dB): '); % e.g., 40

wp = input('Enter the passband frequency (Hz): '); % e.g., 2000

ws = input('Enter the stopband frequency (Hz): '); % e.g., 1000

fs = input('Enter the sampling frequency (Hz): '); % e.g., 8000

% Normalize analog frequencies (0 to 1, where 1 = Nyquist frequency)

w1 = 2 * wp / fs; % Normalized passband frequency

w2 = 2 * ws / fs; % Normalized stopband frequency

% Calculate filter order and cutoff frequency using Butterworth

[n, wn] = buttord(w1, w2, rp, rs, 's'); % Analog domain

% Design analog Butterworth High Pass Filter

[b, a] = butter(n, wn, 'high', 's'); % 's' specifies analog filter

% Frequency vector for evaluating response

w = 0 : 0.01 : pi; % Frequency range for plotting

% Compute frequency response of analog filter

[h, om] = freqs(b, a, w); % Frequency response in Laplace domain

% Convert magnitude response to decibels

m = 20 * log10(abs(h));

% Plot magnitude response

subplot(2,1,1);

plot(om/pi, m);

title('Magnitude Response of IIR High Pass Filter');

xlabel('Normalized Frequency (\omega/\pi)');

ylabel('Gain (dB)');

grid on;
% Plot phase response

an = angle(h);

subplot(2,1,2);

plot(om/pi, an);

title('Phase Response of IIR High Pass Filter');

xlabel('Normalized Frequency (\omega/\pi)');

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

Frequency response of II R HP F is:

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.

You might also like