0% found this document useful (0 votes)
14 views17 pages

DSP Lab Experiments and Analysis

The document outlines various DSP lab experiments, detailing aims and MATLAB code for generating and analyzing signals, including unit impulse, step, ramp, triangular, rectangular, and custom waveforms. It also covers signal transformations, convolution, DTFT computation, Z-Transform, and the design of IIR filters using different methods. Each section includes code snippets and visualizations for better understanding of the concepts.

Uploaded by

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

DSP Lab Experiments and Analysis

The document outlines various DSP lab experiments, detailing aims and MATLAB code for generating and analyzing signals, including unit impulse, step, ramp, triangular, rectangular, and custom waveforms. It also covers signal transformations, convolution, DTFT computation, Z-Transform, and the design of IIR filters using different methods. Each section includes code snippets and visualizations for better understanding of the concepts.

Uploaded by

nalluribalaji326
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

DSP LAB EXPERIMENTS

1.
AIM: To generate and observe various signals (unit impulse, unit step, unit
ramp, triangular pulse, rectangular pulse, and arbitrary signal) and study their
time transformations (shifting, folding, and scaling).
CODE:
clc;
clear all;
close all;
n = -50:1:50;

a1 = 1;
a2 = 0;
x1 = a1 .* (n == 0) + a2 .* (n ~= 0);
subplot(6, 4, 1)
stem(n, x1, 'g')
title('Signal x1 (n = 0 -> 1, else 0)')

n1 = n + 10;
subplot(6, 4, 2)
stem(n1, x1, 'r')
title('Shifted x1 by 10')

n2 = -n;
subplot(6, 4, 3);
stem(n2, x1, 'b');
title('Reversed x1')

n3 = n / 2;
subplot(6, 4, 4);
stem(n3, x1, 'c');
title('Scaled x1 by 0.5')

n = -50:1:50;
a1 = 1;
a2 = 0;
x2 = a1 .* (n >= 0) + a2 .* (n < 0);
subplot(6, 4, 5)
stem(n, x2)
title('Signal x2 (n >= 0 -> 1, else 0)')

n1 = n + 10;
subplot(6, 4, 6)
stem(n1, x2, 'r')
title('Shifted x2 by 10')

n2 = -n;
subplot(6, 4, 7);
stem(n2, x2, 'b');
title('Reversed x2')

n3 = n / 2;
subplot(6, 4, 8);
stem(n3, x2, 'c');
title('Scaled x2 by 0.5')

n = -50:1:50;
a1 = n;
a2 = 0;
x3 = a1 .* (n >= 0) + a2 .* (n < 0);
subplot(6, 4, 9);
stem(n, x3);
title('Signal x3 (n = 0 -> n, else 0)')

n1 = n + 10; %advance by 10 units


subplot(6, 4, 10)
stem(n1, x3, 'r')
title('Shifted x3 by 10')

n2 = -n;
subplot(6, 4, 11);
stem(n2, x3, 'b');
title('Reversed x3')

n3 = n / 2;
subplot(6, 4, 12);
stem(n3, x3, 'c');
title('Scaled x3 by 0.5')

n = -50:1:50;
T = 10;
a1 = 1 - (2 * abs(n) / T);
a2 = 0;
x4 = a1 .* (abs(n) <= (T / 2)) + a2 .* (abs(n) > (T /
2));
subplot(6, 4, 13);
stem(n, x4)
title('Signal x4 (Triangle waveform)')

n1 = n + 10; %advance by 10 units


subplot(6, 4, 14)
stem(n1, x4, 'r')
title('Shifted x4 by 10')

n2 = -n;
subplot(6, 4, 15);
stem(n2, x4, 'b');
title('Reversed x4')

n3 = n / 2;
subplot(6, 4, 16);
stem(n3, x4, 'c');
title('Scaled x4 by 0.5')

n = -50:0.1:50;
T = 10;
a1 = 1;
a2 = 0;
x5 = a1 .* (abs(n) <= (T / 2)) + a2 .* (abs(n) > (T /
2));
subplot(6, 4, 17);
stem(n, x5)
title('Signal x5 (Rectangular Pulse)')

n1 = n + 10; %advance by 10 units


subplot(6, 4, 18)
stem(n1, x5, 'r')
title('Shifted x5 by 10')

n2 = -n;
subplot(6, 4, 19);
stem(n2, x5, 'b');
title('Reversed x5')

n3 = n / 2;
subplot(6, 4, 20);
stem(n3, x5, 'c');
title('Scaled x5 by 0.5')

n = -50:1:50;
x6 = [zeros(1, 50) 1 2 3 2 zeros(1, 47)];
subplot(6, 4, 21);
stem(n, x6)
title('Signal x6 (Custom waveform)')

n1 = n + 10; %advance by 10 units


subplot(6, 4, 22)
stem(n1, x6, 'r')
title('Shifted x6 by 10')

n2 = -n;
subplot(6, 4, 23);
stem(n2, x6, 'b');
title('Reversed x6')

n3 = n / 2;
subplot(6, 4, 24);
stem(n3, x6, 'c');
title('Scaled x6 by 0.5')
2.
AIM: To determine and plot the even and odd components of a signal and
calculate the energy and power of the given signal.
CODE:
clc;
clear all;
close all;
n = -100:1:100;
u = @(n) 1.0*(n >= 0);
a = 0.5;
x = @(n) a.^(n) .* u(n);
xo = @(n) (x(n) - x(-n)) / 2;
xe = @(n) (x(n) + x(-n)) / 2;

subplot(3, 1, 1)
stem(n, x(n))
title('Original Signal x(n)')
xlabel('n')
ylabel('x(n)')

subplot(3, 1, 2)
stem(n, xo(n))
title('Odd Component xo(n)')
xlabel('n')
ylabel('xo(n)')

subplot(3, 1, 3)
stem(n, xe(n))
title('Even Component xe(n)')
xlabel('n')
ylabel('xe(n)')

E = sum(abs(x(n)).^2);
p = (1 / length(n)) * E;
3.
AIM: To compute and plot the convolution of two discrete signals x[n]
y[n]using MATLAB.
CODE:
clc;
clear all;
close all;
x = [1 1 1 1];
y = [1 2 1 2];
z = conv(x, y);

subplot(3, 1, 1)
stem(x)
title('Signal x[n]')
xlabel('n')
ylabel('x[n]')

subplot(3, 1, 2)
stem(y)
title('Signal y[n]')
xlabel('n')
ylabel('y[n]')

subplot(3, 1, 3)
stem(z)
title('Convolution Result z[n]')
xlabel('n')
ylabel('z[n]')
4.
AIM: To compute and plot the Discrete-Time Fourier Transform (DTFT) of a
given discrete signal x[n], and visualize its magnitude and phase spectra.
clc;
clear all;
close all;
x = [1 2 2 1];
len = length(x);
n = 0:len-1;
w = linspace(-pi, pi, 1000);
X = zeros(size(w));
for k = 1:length(w)
X(k) = sum(x .* exp(-1j*w(k)*n));
end
X_mag_dtft = abs(X);
X_phase_dtft = angle(X);

subplot(2, 1, 1);
plot(w, X_mag_dtft, 'r');
title('Magnitude of DTFT');
xlabel('Frequency (w)');
ylabel('|X(w)|');

subplot(2, 1, 2);
plot(w, X_phase_dtft, 'g');
title('Phase of DTFT');
xlabel('Frequency (w)');
ylabel('∠X(w)');
5.

AIM: To compute and plot the Discrete-Time Fourier Transform (DTFT) of a


first-order difference equation response, analyze its magnitude and phase
spectra, and understand the frequency domain representation of the signal.
CODE:
clc;
clear all;
close all;
% y(n)-ay(n-1)=x(n)
N = 100;
n = 0:N-1;
a = 1/2;
x = a.^n .* (n >= 0);
w = linspace(-pi, pi, 1000);
X = zeros(size(w));
for k = 1:length(w)
X(k) = sum(x .* exp(-1j*w(k)*n));
end

figure
subplot(2, 1, 1);
plot(w, abs(X));
title('Magnitude of DTFT');
xlabel('Frequency (w)');
ylabel('|X(w)|');

subplot(2, 1, 2);
plot(w, angle(X));
title('Phase of DTFT');
xlabel('Frequency (w)');
ylabel('∠X(w)');
6.
AIM: To compute and plot the response of a first-
order difference equation y(n)-3y(n-1)-4y(n-2)=x(n)
+2x(n-1) using MATLAB, analyze its impulse response
in the time domain, and study its frequency response
by plotting the magnitude and phase spectra.

CODE:
clc;
clear all;
close all;
% y(n)-3y(n-1)-4y(n-2)=x(n)+2x(n-1)
x = [1 zeros(1, 9)];
b = [1 2];
a = [1 -3 -4];
h = filter(b, a, x);
stem(h)
title('221FA05045 Impulse Response h[n]');
xlabel('n');
ylabel('h[n]');

N = length(h);
n = 0:N-1;
w = linspace(-pi, pi, 1000);
H = zeros(size(h));
for k = 1:length(w)
H(k) = sum(h .* exp(-1j*w(k)*n));
end

figure
subplot(2, 1, 1);
plot(w, abs(H));
title('Magnitude of Frequency Response |H(w)|');
xlabel('Frequency (w)');
ylabel('|H(w)|');

subplot(2, 1, 2);

title('Phase of Frequency Response ∠H(w)');


plot(w, angle(H));

xlabel('Frequency (w)');
ylabel('∠H(w)');

7.
AIM :To compute the Z-Transform of a given discrete-
time sequence and obtain its inverse Z-Transform.

Code:
clc;
close all;
clear all;
%a=1/2;
n=-2:1:3;
h1=[2 3 4 1 -2 4];
%H1=0;
syms z
H1=sum(h1.*z.^(-n));
display(H1)
h1_n=iztrans(H1);
display(h1_n)
8.
AIM: To compute the Z-Transform of an exponentially
decaying signal and determine its inverse.

CODE:
clc;
close all;
clear all;
%syms a
a=1/2;
n=0:1:10;
h1=a.^n.*(n>=0);
%H1=0;
syms z
H1=sum(h1.*z.^(-n));
display(H1)
h1_n=iztrans(H1);
display(h1_n)
H=1/(1-a.*z^(-1));
display(iztrans(H))
9.
AIM :To compute and plot the pole-zero diagram of a
discrete-time system.

Code :
clc;
clear all;
close all;
b=[1];
b=[1,-1];
a=[1, -0.9];
a=[1, -3/4, 1/8];
zplane(b,a);
10.
AIM: Design and Implementation of IIR Filters (Butterworth and
Chebyshev Type-I) using Bilinear Transformation

Code : Butterworth

clc;
clear all;
close all;
T=1;
rp=0.8;%input('Enter the Passband ripple: ');
rs=0.2;%input('Enter the Stopband ripple: ');
wp=0.4*pi;%input('Enter the Passband edge frequency:
');
ws=0.8*pi;%input('Enter the Stopband edge frequency:
');
p_att=-20*log10(rp);
s_att=-20*log10(rs);
p_wa=wp/T;
s_wa=ws/T;
%fs=1000;%input('Enter the Sampling frequency: ');
[N,wn]=buttord(p_wa,s_wa,p_att,s_att,'s');
[b,a]=butter(N,wn,'s');
[bz,az]=bilinear(b,a,1/T);
w=-0:0.01:pi;
H_z=freqz(bz,az,w);
plot(w,abs(H_z))
Code : Chebyshev Type-I

clc;
clear all;
close all;
T=1;
rp=0.8;%input('Enter the Passband ripple: ');
rs=0.2;%input('Enter the Stopband ripple: ');
wp=0.4*pi;%input('Enter the Passband edge frequency:
');
ws=0.8*pi;%input('Enter the Stopband edge frequency:
');
p_att=-20*log10(rp);
s_att=-20*log10(rs);
p_wa=wp/T;
s_wa=ws/T;
%fs=1000;%input('Enter the Sampling frequency: ');
[N,wn]=cheb1ord(p_wa,s_wa,p_att,s_att,'s');
[b,a]=cheby1(N,p_att,wn,'s');
[bz,az]=bilinear(b,a,1/T);
w=-0:0.01:pi;
H_z=freqz(bz,az,w);
plot(w,abs(H_z))
11.
AIM : Design and Implementation of IIR Filters
(Butterworth and Chebyshev Type-I) using Impulse
Invariant Transformation.

Code : Butterworth

clc;
clear all;
close all;
T=1;
rp=0.8;%input('Enter the Passband ripple: ');
rs=0.2;%input('Enter the Stopband ripple: ');
wp=0.4*pi;%input('Enter the Passband edge frequency:
');
ws=0.8*pi;%input('Enter the Stopband edge frequency:
');
p_att=-20*log10(rp);
s_att=-20*log10(rs);
p_wa=wp/T;
s_wa=ws/T;
%fs=1000;%input('Enter the Sampling frequency: ');
[N,wn]=buttord(p_wa,s_wa,p_att,s_att,'s');
[b,a]=butter(N,wn,'s');
[bz,az]=impinvar(b,a,1/T);
w=-0:0.01:pi;
H_z=freqz(bz,az,w);
plot(w,abs(H_z))

Code : Chebyshev Type-I

clc;
clear all;
close all;
T=1;
rp=0.8;%input('Enter the Passband ripple: ');
rs=0.2;%input('Enter the Stopband ripple: ');
wp=0.4*pi;%input('Enter the Passband edge frequency:
');
ws=0.8*pi;%input('Enter the Stopband edge frequency:
');
p_att=-20*log10(rp);
s_att=-20*log10(rs);
p_wa=wp/T;
s_wa=ws/T;
%fs=1000;%input('Enter the Sampling frequency: ');
[N,wn]=cheb1ord(p_wa,s_wa,p_att,s_att,'s');
[b,a]=cheby1(N,p_att,wn,'s');
[bz,az]=impinvar(b,a,1/T);
w=-0:0.01:pi;
H_z=freqz(bz,az,w);
plot(w,abs(H_z))

Common questions

Powered by AI

The even component of a signal, xe(n), is symmetric around the y-axis, whereas the odd component, xo(n), is antisymmetric. These components are calculated as xe(n) = (x(n) + x(-n)) / 2 for the even component and xo(n) = (x(n) - x(-n)) / 2 for the odd component . This decomposition is crucial for analyzing complex signals as it simplifies the study by breaking the signal into simpler constituent parts that exhibit clear symmetry properties.

A pole-zero diagram represents the poles and zeros of a system's transfer function in the complex plane. Poles indicate the values that can cause the system's response to grow without bound, thus affecting stability. Zeros affect the frequency response by contributing to frequency attenuation. Analyzing the proximity of poles to the unit circle helps assess system stability, while the arrangement of zeros informs frequency response characteristics and hence filter design . Understanding this diagram is crucial for the design and tuning of filters and control systems.

Calculating the energy and power of a signal helps understand the signal's strength over time and its ability to perform work in a system. For a discrete signal x(n), the energy is given by E = sum(abs(x(n)).^2); the power, being average energy per sample, is p = E / length(n). These measures are crucial in communication systems to determine efficient bandwidth utilization and transmitter power requirements. Efficient energy spread signifies better utilization of frequency resources.

The Z-Transform translates a discrete-time signal from the time domain to a complex frequency domain, helping in the analysis and characterization of linear time-invariant systems. It simplifies convolution and difference equations into algebraic problems. The inverse Z-Transform is evaluated to retrieve the time-domain signal using methods like partial fraction expansion or contour integral methods . This is crucial for filtering, system analysis, and stabilization evaluation in systems.

Using MATLAB to compute and visualize the DTFT facilitates the analysis of signal frequency content by providing clear and precise graphical representations of its magnitude and phase spectra. MATLAB's computational capabilities allow efficient processing of the DTFT, making it easier to identify critical frequencies and understand the impact of phase shifts . This visualization aids in the design of filters, equalizers, and spectral analysis, thereby enhancing signal processing tasks such as noise cancellation and data compression.

Convolution of two discrete signals results in a third signal that represents the area of overlap between the signals as they pass over each other, which effectively combines their effects. For example, if x[n] = [1, 1, 1, 1] and y[n] = [1, 2, 1, 2], the convolution z[n] = conv(x, y) provides a new sequence signifying how these signals would interact linearly and time-variantly . Convolution is fundamental in filtering operations, where it simulates the effect of a filter on a signal, allowing for modifications in frequency components and amplitudes.

Impulse invariance maps the impulse response of a continuous-time filter to its discrete counterpart by sampling, preserving the original filter's time-domain characteristics. This method maintains the zeros of the continuous filter but can introduce frequency warping, especially in high-frequency components. Challenges include aliasing and less control over magnitude response in high frequencies compared to bilinear transformation . Despite these challenges, impulse invariance is useful in applications where time-domain behavior preservation is crucial.

Shifting a discrete signal involves delaying or advancing it in the time domain. For example, the unit impulse signal is defined such that x1[n] = 1 when n = 0, otherwise x1[n] = 0; shifting this by 10 results in x1[n+10], which means the original impulse appears at n = -10 . Shifting is significant as it models practical scenarios like the introduction of delays in communication systems. It also allows alignment of signals for analytical purposes such as correlation and convolution analysis.

The magnitude spectrum of the DTFT indicates how signal energy is distributed across different frequencies, providing insight into signal strength and dominant frequencies. The phase spectrum, on the other hand, offers information on the signal's phase shift at each frequency component, which affects how different signal components interfere with each other. This dual representation is essential in signal processing and communications for filtering, signal reconstruction, and phase correction tasks .

Designing IIR filters with the bilinear transformation involves establishing a frequency mapping between the continuous to discrete domains while preserving the locations of critical frequency points. For Butterworth filters, this means an emphasis on a maximally flat response, while Chebyshev prioritizes ripple in either pass or stop bands for sharper cutoffs . Applications of these filters are extensive in digital signal processing, including noise reduction, signal smoothing, and limiting signal bandwidth. The filters' properties aid in designing systems for specific frequency performance requirements.

You might also like