Download as pdf or txt
Download as pdf or txt
You are on page 1of 27

A

Practical activity Report submitted

for

Signal Systems and their processing (UEC-514)

by

Divyansh Yadav

Roll number - 102009023

Submitted to:

Dr. Geetika Dua

THAPAR INSTITUTE OF ENGINEERING AND TECHNOLOGY,

(A DEEMED TO BE UNIVERSITY), PATIALA, PUNJAB,

INDIA

July-December 2022
Experiment 1

Aim: Practice session on MATLAB.

Software Used: Matlab

Theory:

Functions used:

linespace: y = linspace(x1,x2) returns a row vector of 100 evenly spaced points between
x1 and x2.

y = linspace(x1,x2,n) generates n points. The spacing between the points is (x2-x1)/(n-1).


linspace is similar to the colon operator, “:”, but gives direct control over the number of points
and always includes the endpoints. “lin” in the name “linspace” refers to generating linearly
spaced values as opposed to the sibling function logspace, which generates logarithmically
spaced values.

Code and Graph:

x=linspace(0,2*pi,100); y=sin(x); plot(x,y,'o') xlabel('x') ylabel('y') title('Plot created by Divyansh')


Code:
x=linspace(0,2*pi,100); y=sin(x); plot(x,y,x,y,'o') xlabel('x') ylabel('y') title('Plot created by

Divyansh')

Code:x=linspace(0,4*pi,100); y=exp(-0.4*x).*sin(x); plot(x,y) xlabel('x') ylabel('y') title('Plot

created by Divyansh')

Code:
t=linspace(0,20,20); x=sin(t); y=cos(t); z=t; plot3(x,y,z) xlabel('x') ylabel('y') zlabel('z')

Experiment 2

Aim: 1.Write a program to generate the following signals


a. Unit step signal in the continuous- and discrete-time domain

b. Unit impulse signal in the discrete-time domain

c. Unit Ramp signal in the continuous- and discrete-time domain

d. Rectangular pulse of width 2 sec and amplitude oneSoftware Used:

Matlab Theory:

Functions used:

Subplot:
subplot(m,n,p) divides the current figure into an m-by-n grid and creates axes in the position
specified by p. MATLAB® numbers subplot positions by row. The first subplot is the first column
of the first row, the second subplot is the second column of the first row, and so on. If axes exist
in the specified position, then this command makes the axes the current axes.

Stem:
stem(X,Y) plots the data sequence, Y, at values specified by X. The X and Y inputs must be
vectors or matrices of the same size. Additionally, X can be a row or column vector and Y must
be a matrix with length(X) rows.

● If X and Y are both vectors, then stem plots entries in Y against corresponding
entries in X.
● If X is a vector and Y is a matrix, then stem plots each column of Y against the set of
values specified by X, such that all elements in a row of Y are plotted against the
same value.
● If X and Y are both matrices, then stem plots columns of Y against corresponding
columns of X.
Code and Graph:

a. Unit step signal in the continuous- and discrete-time domain

clc clear
%Continuous
x = (-10:.01:10); unit = x>=0; subplot(2,1,1); plot(x,unit) title('Continuous unit Step: 102009023');
xlabel('Time'); ylabel('function');

%Discontinuous subplot(2,1,2); stem(x,unit);


title('Discontinuous Unit Step: 102009023'); xlabel('Time'); ylabel('function')

b. Unit impulse signal in the discrete-time domain

clc clear
%Continuous
x = (-100:.1:100); unit = x==0; subplot(2,1,1); plot(x,unit) title('Continuous unit impulse:
102009023'); xlabel('Time'); ylabel('function');

%Discontinuous subplot(2,1,2); stem(x,unit); title('Discontinuous Unit impulse:


102009023'); xlabel('Time'); ylabel('function');

c. Unit Ramp signal in the continuous- and discrete-time domain

clc
Clear
%continuous t= (0:100); ramp=t ; subplot(2,1,1); plot(t,ramp) title('Continuous ramp:
102009023'); xlabel('Time'); ylabel('function'); grid on

% Discontinouos subplot(2,1,2); stem(t,ramp);


title('Discontinuous ramp: 102009023'); xlabel('Time'); ylabel('function'); grid on

d. Rectangular pulse of width 2 sec and amplitude one

clc clear
%Continuous
x = (-10:.01:10); func = x>=-1 & x<=1 subplot(2,1,1); plot(x,func) title('Continuous unit Step:
102009023'); xlabel('Time'); ylabel('function');

%Discontinuous subplot(2,1,2); stem(x,func); title('Discontinuous Unit Step: 102009023');


xlabel('Time'); ylabel('function');
Experiment 3
Aim: 1. Write a program to decompose x(n) = [u(n) – u(n–10)] into its even and odd components,

and also plot the respective waveforms. Software Used: Matlab Theory:

Functions used:

Subplot:
subplot(m,n,p) divides the current figure into an m-by-n grid and creates axes in the position
specified by p. MATLAB® numbers subplot positions by row. The first subplot is the first column
of the first row, the second subplot is the second column of the first row, and so on. If axes exist
in the specified position, then this command makes the axes the current axes.

Stem:
stem(X,Y) plots the data sequence, Y, at values specified by X. The X and Y inputs must be
vectors or matrices of the same size. Additionally, X can be a row or column vector and Y must
be a matrix with length(X) rows.

● If X and Y are both vectors, then stem plots entries in Y against corresponding
entries in X.
● If X is a vector and Y is a matrix, then stem plots each column of Y against the set of
values specified by X, such that all elements in a row of Y are plotted against the
same value.
● If X and Y are both matrices, then stem plots columns of Y against corresponding
columns of X.
Code and Graph:

Clc clear n =
(-20:1:20);

%u(n) u1 =
n>= 0;

%u(n-10)
u2 = n>=10;

%a=u(n)-u(n-10) a=u1-u2; subplot(3,1,1); stem(n,a); title('u(n) - u(n-10):


102009023'); xlabel('discrete steps'); ylabel('function');

%Even part
even1 = (a + fliplr(a))/2; subplot(3,1,2); stem(n,even1); title('Even : 102009023');
xlabel('discrete steps'); ylabel('function');

%Odd part
odd1 = (a - fliplr(a))/2; subplot(3,1,3); stem(n,odd1); title('Odd : 102009023');
xlabel('discrete steps'); ylabel('function')
Experiment 4
Aim: 1.Program to generate delayed and scaled signals i.e.,

a) u(t–1)
b) u(2t+1)
c) r(t–1); r(t) represents ramp signal.
d) Sinc function Software Used: Matlab Theory:

Functions used:

Subplot:
subplot(m,n,p) divides the current figure into an m-by-n grid and creates axes in the position
specified by p. MATLAB® numbers subplot positions by row. The first subplot is the first column
of the first row, the second subplot is the second column of the first row, and so on. If axes exist
in the specified position, then this command makes the axes the current axes.

Stem:
stem(X,Y) plots the data sequence, Y, at values specified by X. The X and Y inputs must be
vectors or matrices of the same size. Additionally, X can be a row or column vector and Y must
be a matrix with length(X) rows.

● If X and Y are both vectors, then stem plots entries in Y against corresponding
entries in X.
● If X is a vector and Y is a matrix, then stem plots each column of Y against the set of
values specified by X, such that all elements in a row of Y are plotted against the
same value.
● If X and Y are both matrices, then stem plots columns of Y against corresponding
columns of X.

Code and Graph:

clc
%continuous
%a
xc1=(-10:0.01:10);
uc1=xc1>=1;
subplot(4,1,1);
plot(xc1,uc1);
ylabel('U(t-1)');
xlabel('t');
title('a) U(t-1) (Divyansh-102009023)');

%b
xc2=(-10:0.01:10);
uc2=xc2>=-1;
xc2=xc2>2;
subplot(4,1,2);
plot(xc2,uc2);
ylabel('U(2t+1)');
xlabel('t');
title('b) U(2t+1) (Divyansh-102009023)');

%c
t=(0:10);
r =(t>=1).*(t-1);
subplot(4,1,3);
plot(t,r);
title('r(t-1)(Divyansh-102009023)');
xlabel('t');
ylabel('r(t-1)');

%d
t=(-10:0.001:10);
sinc1=sin(pi.*t)./(pi.*t);
subplot(4,1,4);
plot(t,sinc1);
title('Sinc (Divyansh-102009023)');
xlabel('t');
ylabel('Sinc');
Experiment 5

Aim: Let x(n) be the input to an LTI system with impulse response h(n). Obtain the output
signal y(n)= x(n) * h(n) for

a) x(n) =h(n)= [u(n) – u(n–10)]

b) x = [1, 2] and h= [1, 2, 4]

Use the inbuilt function "conv" for verifying the results.

Software Used: Matlab

Theory:

Functions used:

conv():

w = conv(u,v) returns the convolution of vectors u and v. If u and v are vectors of polynomial
coefficients, convolving them is equivalent to multiplying the two polynomials.

Code and Graph:

a) x(n) =h(n)= [u(n) – u(n–10)]

clc clear all n


= (-10:1:10);

u1 = n>=0;
u2 = n>=10;

x = u1 - u2;
h = u1 - u2;

m = length(x); n =
length(h); X = [x
zeros(1,n)]; H =
[h zeros(1,m)];

for i = 1:m+n-1 %summation


y(i)=0;
for j = 1:i
if(i-j+1) % to keep the values +ve
y(i)=y(i)+X(j)*H(i-j+1);
else
end end
end

d=conv(x,h);

subplot(2,2,1); stem(x); title('x(n): 102009023'); xlabel('n'); ylabel('u(n) - u(n-10)');

subplot(2,2,2); stem(h); title('h(n): 102009023'); xlabel('n'); ylabel('u(n) - u(n-10)');

subplot(2,2,3); stem(y); title('convolution: 102009023'); xlabel('n'); ylabel('summation y =


x(k)*h(n-k)');

subplot(2,2,4); stem(d); title('convolution: 102009023'); xlabel('n'); ylabel('conv(x,h)');

Combined Graph:
b) x = [1, 2] and h= [1, 2, 4]

clc clear all n


= (-10:1:10);

u1 = n>=0;
u2 = n>=10;

x = [1,2]; h
= [1,2,4];

m = length(x);
n = length(h);

X = [x zeros(1,n)];
H = [h zeros(1,m)];

for i = 1:m+n-1 %summation


y(i)=0;
for j = 1:i
if(i-j+1) % to keep the values +ve
y(i)=y(i)+X(j)*H(i-j+1)
else
end end
end

d=conv(x,h);
disp(d);

subplot(2,2,1); stem(x); title('x(n): 102009023'); xlabel('n'); ylabel('[1,2]');

subplot(2,2,2); stem(h); title('h(n): 102009034'); xlabel('n'); ylabel('[1,2,4]'); subplot(2,2,3);


stem(y); title('convolution: 102009023'); xlabel('n'); ylabel('summation y = x(k)*h(n-k)');

subplot(2,2,4); stem(d); title('convolution: 102009023'); xlabel('n'); ylabel('conv(x,h)'); Output:

y=
1 4 8 8
1 4 8 8

Combined Graph:
Experiment 6

Aim: a) Write a program to determine and plot continuous-time Fourier transform (CTFT) of
rectangular pulse. Also plot its magnitude response.
b) Write a program to determine and plot discrete-time Fourier transform (DTFT) of
rectangular pulse. Also plot its magnitude response.

Software Used: Matlab

Theory:

Functions used:

trapz():

trapz(Y) computes the approximate integral of Y via the trapezoidal method with unit spacing.
The size of Y determines the dimension to integrate along.

Code and Graph:

a):

clc; clear all; ctft = []; t = (-10:0.01:10); rect = (t>=-2 & t<=2); subplot(3,1,1); plot(t,rect);
title('Rectangular Pulse: 102009023'); xlabel('time'); grid on;

k = 0; for f = -10:0.01:10 k = k+1;


ctft(k) = trapz(t,rect.*exp(-j*2*pi*f*t));
end
f =(-10:0.01:10); subplot(3,1,2); plot(f,abs(ctft)); title('Magnitude Plot Fourier Transform (CTFT):
102009023'); xlabel('frequency'); grid on;
subplot(3,1,3); plot(f,angle(ctft)); title('Phase Plot Fourier Transform (CTFT): 102009023');

xlabel('frequency'); grid on;

b):

clc; clear all; n = (-10:10); rect = (n>=-2 & n<=2); subplot(3,1,1); stem(n,rect); title('Rectangular
Pulse: 102009023'); xlabel('n'); grid on;

w = -5*pi:0.1:5*pi; dtft =
zeros(1,length(w)); for k
= 1:length(w)
for n1 = 1:length(n)
dtft(k) = dtft(k) + rect(n1)*exp(-j*w(k)*n(n1));
end
end

subplot(3,1,2); plot(w/pi,abs(dtft));
title('Magnitude Plot Fourier Transform (DTFT): 102009023'); xlabel('frequency'); grid on;

subplot(3,1,3);
plot(w/pi,angle(dtft));
xlabel('frequency');
grid on;
Experiment 9

Aim: For any two user input discrete sequences


a) Compute circular convolution (without using direct command).
b)Compute linear convolution using circular convolution (as computed in a)).
c)Compute circular convolution using linear convolution and verify with the result
obtained in a).
d) Compute circular convolution using DFT-IDFT method.

Software Used: Matlab

Theory:

Functions used:

cconv():

cconv(a,b,n) circularly convolves vectors a and b. n is the length of the resulting vector. You can
also use cconv to compute the circular cross-correlation of two sequences.

Code:

a):

clc clear
all X = [1 2
3];
H = [1 2 2 1];
N = max(length(X),length(H));
x = [X zeros(1,N-length(X))];
h = [H zeros(1,N-length(H))];

for n = 1:N
Y(n) = 0; for
m = 1:N j =
n-m+1; if
(j<=0)
Y(n) = Y(n) + x(m) * h(j + N)
else
Y(n) = Y(n) + x(m) * h(j)
end
end
end
cconv(x,h,N)

b):

clc clear
all X = [1 2
3];
H = [1 2 2 1]; N =
length(X)+length(H)-1; x =
[X zeros(1,N-length(X))]; h =
[H zeros(1,N-length(H))];

for n=1:N y(n) = 0; for m = 1:N


j = n-m+1 if (j<=0) y(n) =
y(n)+x(m)*h(j+N)
else y(n) =
y(n)+x(m)*h(j) end end
end
conv(x,h)

c):

clc clear all; x = [1 2 3]; h = [1


2 2 1]; y = conv(x,h); N = 4;
%circular conv of N pts l =
length(y); p = l - N+1; for i =
1:p-1
cc(i) = y(i) + y(i+N);
end
for j = p:N
cc(j) = y(j);
end cc

d):

clc clear
all; X = [1
2 3];
H = [1 2 2 1]; N =
max(length(X),length(H)); x =
[X zeros(1,N-length(X))]; h =
[H zeros(1,N-length(H))];
X_ = fft(x);
H_ = fft(h);

Y = X_.*H_;

y = ifft(Y)
List of Experiments
S. no Experiment Date of Date of Remarks
conduction Submission
1. Practice session on MATLAB (Note
down the command execution, script
generation, function-generation and
loop implementation etc. with suitable
examples.

2. Write a program to generate: a) Unit


step b) Unit Impulse c) Unit Ramp d)
Rectangular pulse width 2 sec and
amplitude one. In both continuous and
discrete time.

3. Write a program to decompose signal


x(u) = u[n]-u[n-10] into its even and
odd components

4. Program to generate delayed and


scaled signals: a) u(t-1) b) u(2t+1) c)
r(t-1); r is
ramp d) Sinc function

5. Let x(n) be the input to an LTI system


with impulse response h(n). Obtain the
output signal y(n) = x(n)*h(n) for a)
x(n)=h(n)=[u(n)-u(n-10)] b) x= [1,2]
and h= [1,2,4], Use the inbuilt function
‘conv’ for verifying the results

6. Write a program to determine and plot


CTFT and DTFT of rectangular pulse,
also plot its magnitude response

7. Write a program to DFT of a given


sequence x(n), without using direct
commands and verify the result by
using FFT command, plot results[k]| vs
k and angle(x[k]) vs k
S. no Experiment Date of Date of Remarks
conduction Submission

8. Given a causal system y(n)= +0.9y(n-1)


+x(n); Find H(z) and generate its pole-
zero plot in z-plane. Also plot the
magnitude and phase response of the
system, i.e., the magnitude and phase
spectrum for H {𝑒𝑗𝑤}.

9. For any two user discrete sequences a)


Compute circular convolution (without
direct commands). b) Compute linear
convolution using circular convolution.
c) Compute circular convolution using
linear convolution and verify the result
obtained in (a). d)
Compute circular convolution using
DFTI DFT
10. Write a program to plot the time
domain and frequency domain response
of different window functions.

11. Design FIR LOW pass filter using


rectangular and triangular windows
with user input specifications for pass
band edge frequency, transition width,
stop band, attenuation and sampling
frequency

12. Design IIR LOW pass filter using


Butterworth prototype with user input
specifications for pass band edge
frequency, stop band edge frequency,
pass band ripple and stop band
attenuation. Use Impulse Invariant
transformation
Experiment 8

Aim: Given a causal system y(n)= + 0.9 y(n–1) + x(n);


Find H(z), and generate its pole-zero plot in the z-plane. Also, plot the magnitude and
phase response of the system i.e., the magnitude and phase spectrum for H{}. Software
Used: Matlab

Theory:

Functions used:

zplane():

zplane(z,p) plots the zeros specified in column vector z and the poles specified in column vector p in the
current figure window. The symbol 'o' represents a zero and the symbol 'x' represents a pole. The plot
includes the unit circle for reference.
If z and p are matrices, then zplane plots the poles and zeros in the columns of z and p in different colors.

Code and Graph:

clc
clear all

%y(n) = 0.9y(n-1) + x(n)


%Y(z) = 0.9z^(-1)Y(z) + X(z)
%Y(z)/X(z) = 1/(1 - 0.9z^-1)
%H(z) = 1/(1 - 0.9z^-1)

b = [1 0]; a
= [1 -0.9];

subplot(3,1,1); zplane(b,a); title('Zplane: 102009023');

w = (0:100)*pi/100; [H w] = freqz(b,a,w); magH = abs(H); phaH = angle(H); subplot(3,1,2);


plot(w/pi,magH); xlabel('frequency in pi units'); ylabel('magnitude'); title('magnitude response:
102009023');

subplot(3,1,3); plot(w/pi,phaH); xlabel('frequency in pi units'); ylabel('Phase in pi units');


title('Phase response: 102009023');
Experiment 10

Aim: Write a program to plot the time domain and frequency domain response of different
window functions.

Software Used: Matlab

Code and Graph:

clc clear
all close
all M =
45; n =
0:M-1;

% time domain windows rect = ones(1,M); han = 0.5-


0.5*cos(2*pi*n/(M-1)); ham = 0.54 - 0.46 * cos(2*pi*n/(M-1));
blac = 0.42 - 0.5 * cos(2*pi*n/(M-1)) + 0.08 * cos(4*pi*n/(M-1));
% compute frequecny response of windows
N=1024;
faxis= 0:1/N : (N-1)/N;
fftrect=fft(rect,N);
ffthan = fft(han,N);
fftham = fft(ham,N);
fftblac = fft(blac,N);

% normalise the magnitude response


frect=abs((fftrect)/max(fftrect));
fhan=abs((ffthan)/max(ffthan));
fham=abs((fftham)/max(fftham));
fblac=abs((fftblac)/max(fftblac));

%Converting magnitude response into decibel range


logfrect= 20*log10(frect); logfhan= 20*log10(fhan);
logfham= 20*log10(fham);

logfblac= 20*log10(fblac);

% time domain window


Figure subplot(221)
plot(n,rect)
title('rectangular window')
xlabel('samples')
ylabel('w[n]')

subplot(222)
plot(n,ham)
title('Hamming window')
xlabel('samples')
ylabel('w[n]')

subplot(223)
plot(n,han)
title('Hanning window')
xlabel('samples')
ylabel('w[n]')

subplot(224)
plot(n,blac)
title('Blackman window')
xlabel('samples')
ylabel('w[n]')

% Log magnitude response of windows


Figure subplot(221) plot(faxis,logfrect)
title('response of rect window')
xlabel('Normalized frequency \omega/\pi')
ylabel('|W[\omega]|,dB')

subplot(222) plot(faxis,logfham)
title('response of Hamming window')
xlabel('Normalized frequency \omega/\pi')
ylabel('|W[\omega]|,dB')

subplot(223)
plot(faxis,logfhan)
title('response of Hann
window') xlabel('Normalized
frequency \omega/\pi')
ylabel('|W[\omega]|,dB')

subplot(224) plot(faxis,logfblac)
title('response of blackman window')
xlabel('Normalized frequency \omega/\pi')
ylabel('|W[\omega]|,dB')

You might also like