Professional Documents
Culture Documents
Divyansh Signal File.. (2) - Combined
Divyansh Signal File.. (2) - Combined
for
by
Divyansh Yadav
Submitted to:
INDIA
July-December 2022
Experiment 1
Theory:
Functions used:
linespace: y = linspace(x1,x2) returns a row vector of 100 evenly spaced points between
x1 and x2.
Divyansh')
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
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
%Continuous
x = (-10:.01:10); unit = x>=0; subplot(2,1,1); plot(x,unit) title('Continuous unit Step: 102009023');
xlabel('Time'); ylabel('function');
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');
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
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');
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;
%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.
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
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.
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)];
d=conv(x,h);
Combined Graph:
b) x = [1, 2] and h= [1, 2, 4]
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)];
d=conv(x,h);
disp(d);
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.
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.
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;
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
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))];
c):
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.
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.
clc
clear all
b = [1 0]; a
= [1 -0.9];
Aim: Write a program to plot the time domain and frequency domain response of different
window functions.
clc clear
all close
all M =
45; n =
0:M-1;
logfblac= 20*log10(fblac);
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]')
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')