Signal and System - Lab - Manual
Signal and System - Lab - Manual
BE SEM –IV(E.C)
SUBJECT: SIGNAL AND SYSTEM( )
SRNO. TITLE
Description:
EXAMPLES:
1. From the command line, evaluate these expressions (a-d) using the
following values, t=3.25, x=4.5,y=6.97,z=1.03
a) M = 4x2 + 3y + 10
b) N = +2
c) O =
2
V.G.E.C.,Chandkheda Subject :Signal and System(4th sem E.C.)
d) P = 4 -
Answer:
Clc;
Close all;
Clear all;
t=3.25;
x=4.5;
y=6.97;
z=1.03;
M=4*x^2+3*y+10
N=exp(log10(y))+2*z^x
O=sqrt(1/(x+y)+1/(t+z))
P=4*exp(-pi/2)-abs(sin(x/(pi*y)))
Output:
2. Do as directed:
a) Create a vector X with a starting value of 0.0 and an ending value
of 50, with increments of 0.1 between values
b) Create a vector Y with a starting value of 0.1 and an ending value
of 50 and with the same number of elements as in X. The elements
must be evenly spaced.
Answer:
Clc;
Close all;
Clear all;
3
V.G.E.C.,Chandkheda Subject :Signal and System(4th sem E.C.)
X=0:0.1:50
Y=linspace(.1,50,length(X))
Output:
3. Do as directed:
a) Using MATLAB commands create an array, labeled A, consisting of
the first 10 prime numbers listed in increasing order.
b) Using MATLAB commands on the array A to create the matrix B
13 17 19 23 29
B=
13 11 7 5 3
Answer:
Clc;
Close all;
Clear all;
A=primes(30);
B=[A(6:10);A(6:-1:2)]
4
V.G.E.C.,Chandkheda Subject :Signal and System(4th sem E.C.)
Output:
4. Do as directed:
a) Use MATLAB commands to find the transpose of B, which you
name C
b) Use MATLAB to Compute B*C and C*B.
Answer:
Clc;
Close all;
Clear all;
A=primes(30);
B= [A(6:10);A(6:-1:2)];
C=B';
BC=B*C;
CB=C*B;
Output:
5
V.G.E.C.,Chandkheda Subject :Signal and System(4th sem E.C.)
Answer:
Clc;
Close all;
Clear all;
D=B(:,3)
E=B(:,3)'
Output:
6
V.G.E.C.,Chandkheda Subject :Signal and System(4th sem E.C.)
Clc;
Close all;
Clear all;
A=[5 2;3 1];
D=[19;7];
E=[19 7];
A1=inv(A+D*E)
A2=inv(A)-(inv(A)*D*E*inv(A))*inv(1+E*inv(A)*D)
Output:
7
V.G.E.C.,Chandkheda Subject :Signal and System(4th sem E.C.)
7. Compute B*C, C *B and C.*C. Compare the result and comment on it.
Answer:
Clc;
Clear all;
A=primes(30);
B= [A(6:10);A(6:-1:2)];
C=B'
BC=B*C
CB=C*B
CC=C.*C
Output:
8
V.G.E.C.,Chandkheda Subject :Signal and System(4th sem E.C.)
Answer:
Clc;
Close all;
Clear all;
for i=1:10
E(i)=i^2
end
Output:
9
V.G.E.C.,Chandkheda Subject :Signal and System(4th sem E.C.)
10
V.G.E.C.,Chandkheda Subject :Signal and System(4th sem E.C.)
EXPERIMENT No.2
AIM: TO STUDY FUNCTIONS OF MATLAB USED IN SIGNAL AND SYSTEM.
abs(x) : computes the absolute value of the elements of x. when x is complex, abs(x) is the
complex magnitude of the element of x.
[H,w] = freqz(b,a,N) : returns an N-point frequency response vector and N-point frequency
vector w in radians, where N is an integer and b, a are numerator and denominator
coefficient vector.
Fft(x,N) : computes DFT of the sequence x using radix-2, N point FFT algorithm.
Ifft(X,N) : computes IDFT of the sequence X using radix-2, N point FFT algorithm.
Plot(t,a) : this plot the continuous graph of any function a verses time t.
Stem(t,a) : this gives the plot of any function a verses time t at discrete values.
Subplot(a,b,c) : If we want to plot more graphs in one page then we can use this function.
This gives the graphs in the form of matrix of a rows and b columns.
Tf (num,den) : This gives the transfer function of polynomials n(s) and d(s), when these
polynomials are ordered in descending powers of s. The resulting variable h is TF object
containing the numerator and denominator data.
Tf2zp (b,a) : It converts transfer function filter parameters to zero-pole gain form.
Disp (x) : This displays an array, without printing the array name.
Zplane (z,p) : This function displays the poles and zeros of discrete-time system.
11
V.G.E.C.,Chandkheda Subject :Signal and System(4th sem E.C.)
EXPERIMENT No.3
AIM: To plot various signals.
Description:
Answer:
Clc;
Close all;
Clear all;
n=-2:2;
y=[n==0];
stem(n,y,'--+r');
title('impulse response');
Output:
12
V.G.E.C.,Chandkheda Subject :Signal and System(4th sem E.C.)
Answer:
Clc;
Close all;
Clear all;
n=0:5;
y=[n>=0];
stem(n,y,'-*g');
title('step response');
Output:
3. Ramp signal
• It is denoted by r(t).
• R(nT)=nT
Answer:
Clc;
Close all;
13
V.G.E.C.,Chandkheda Subject :Signal and System(4th sem E.C.)
Clear all;
n=0:5;
y=[n>=0];
x=n.*y;
stem(n,x,':+c');
title('ramp response');
Output:
4. Exponential signal
• It is denoted by e(n)
• e(n)= Aαn
• A is positive.
• α can be >1 or <1
Answer:
Clc;
Close all;
Clear all;
n=-2:0.5:4;
x=exp(n);
14
V.G.E.C.,Chandkheda Subject :Signal and System(4th sem E.C.)
stem(n,x,'-.dm');
title('exponential responce');
Output:
5. Sine signal
• It represents sinusoidal nature.
• X(n)= sin(wn +Ø)
Answer
Clc;
Close all;
Clear all;
n=-5:0.5:5;
x=sin(n);
subplot(2,1,1);
stem(n,x,'-sk');
title('sine discrete response')
subplot(2,1,2);
plot(n,x,'-sk');
title('sine continuous response');
Output:
15
V.G.E.C.,Chandkheda Subject :Signal and System(4th sem E.C.)
6. Cosine signal
• It represents sinusoidal nature.
• X(n)= cos(wn +Ø)
Answer:
Clc;
Close all;
Clear all;
n=-5:0.5:5;
y=cos(n);
subplot(2,1,1);
stem(n,y,'-sk');
title('cos discrete response')
subplot(2,1,2);
plot(n,x,'-sk');
title('cos continuous response');
Output:
16
V.G.E.C.,Chandkheda Subject :Signal and System(4th sem E.C.)
17
V.G.E.C.,Chandkheda Subject :Signal and System(4th sem E.C.)
Date:
EXPERIMENT No.4
AIM: To study Convolution and De-convolution.
Description:
Answer:
Clc;
Close all;
Clear all;
x=input('Enter x: ')
h=input('Enter h: ')
m=length(x);
n=length(h);
X=[x,zeros(1,n)];
H=[h,zeros(1,m)];
for i=1:n+m-1
Y(i)=0;
for j=1:m
if(i-j+1>0)
Y(i)=Y(i)+X(j)*H(i-j+1);
end
end
end
Y
18
V.G.E.C.,Chandkheda Subject :Signal and System(4th sem E.C.)
stem(Y);
ylabel('Y[n]');
xlabel('----->n');
title('Convolution of Two Signals without conv function');
Output:
19
V.G.E.C.,Chandkheda Subject :Signal and System(4th sem E.C.)
Date:
EXPERIMENT No.5
AIM: To find DFT an IDFT of given sequence using MATLAB
PROGRAMME:
clc
x=input('enter the value of x:- ')
L=length(x);
n=input('enter the value of n: ')
y=fft(x,n); % it computes DFT of the sequence x using radix -2
subplot(4,1,1);
stem(x);
xlabel('n');
ylabel('x(n)');
title('FFT')
a=abs(y);
subplot(4,1,2);
stem(a);
xlabel('N');
ylabel('mag of Y');
title('Magnitude')
b=angle(y); % it computes the phase angle of each component of the vector y
subplot(4,1,3);
stem(b);
xlabel('N');
ylabel('phase of Y');
title('Angle')
z=ifft(y,n); % it computes IDFT of the sequence y using radix -2
subplot(4,1,4);
stem(z);
xlabel('n');
ylabel('z(n)');
title('IFFT')
xlim([1 L])
20
V.G.E.C.,Chandkheda Subject :Signal and System(4th sem E.C.)
COMMAND WINDOW:
enter the value of x:- [1 2 3 4 ]
x=
1 2 3 4
n=
20
WAVEFORM:
Figure: waveform
Date:
21
V.G.E.C.,Chandkheda Subject :Signal and System(4th sem E.C.)
Date:
EXPERIMENT − 6
PROGRAMME:
clc
n=input('enter the value of numerator: ')
d=input('enter the value of denominator: ')
y=tf(n,d)
w=0:0.05:2*pi;
h=freqz(n,d,w) % it returns the frequency response at frequencies desidnated in vector w
subplot(4,1,1);
stem((w/pi), abs(h));
xlabel('freq');
ylabel('mag')
title('magnitude response')
subplot(4,1,2);
stem((w/pi),angle(h))
xlabel('freq');
ylabel('angle')
title('angle respomse')
subplot(4,1,3);
l=real(h)
stem(l)
xlabel('freq');
ylabel('real')
title('real.mag respomse')
subplot(4,1,4);
m=imag(h)
stem(m)
xlabel('freq');
ylabel('imag');
title('imag.mag respomse')
22
V.G.E.C.,Chandkheda Subject :Signal and System(4th sem E.C.)
COMMAND WINDOW:
Transfer function:
s^3 + 3 s^2 + 2 s + 4
---------------------
2 s^3 + 3 s^2 + s + 2
WAVEFORM
Figure: waveform
23
V.G.E.C.,Chandkheda Subject :Signal and System(4th sem E.C.)
Date:
EXPERIMENT No.7
AIM: To find the poles and zero and plot in the polar plot using MATLAB
PROGRAMME:
clc
xn=input('enter the sequence for Numerator ')
yn=input('enter the sequence for denomenator ')
hn=tf(yn,xn); %gives the TF of polynomials yn , xn
[z,p,k] = tf2zp(yn,xn) ; % it converts TF filter parameters to pole-zeros gain form
disp('zeros are ')
disp(z); % it display an array
disp('poles are ')
disp(p);
zplane(z,p);
xlabel('Real part’);
ylabel('Imaginary part');
COMMAND WINDOW:
24
V.G.E.C.,Chandkheda Subject :Signal and System(4th sem E.C.)
WAVEFORM:
Figure: waveform
25
V.G.E.C.,Chandkheda Subject :Signal and System(4th sem E.C.)
Date:
EXPERIMENT No.8
AIM: To study magnitude and phase response of a given function.
X( )=
Description:
= (Let z = )
Answer:
[a]=[1];
[b]=[1,-0.8];
w=0:0.01:2*pi;
freqz(a,b,w)
Output:
26
V.G.E.C.,Chandkheda Subject :Signal and System(4th sem E.C.)
Date:
EXPERIMENT No.8
AIM: To Study Discrete Fourier Transform and Inverse Discrete Fourier Transform.
1) x(n)={0,1 ,2,3}. Find 4-point DFT of this sequence. Perform this by
developing a function for the same in MATLAB.
2) Verify that the output in Q 1 is the DFT of the input by finding out its inverse
Fourier transform. Develop your function to find the inverse DFT.
Description:
Answer:
1) DFT
clear all;
close all;
x=input('Enter the sequence')
N=length(x);
for k=1:N
y(k)=0;
for n=1:N
y(k)=y(k)+x(n)*exp((-2*pi*j*(n-1)*(k-1))/N);
end
end
end
Output:
27
V.G.E.C.,Chandkheda Subject :Signal and System(4th sem E.C.)
2) IDFT
close all;
clear all;
y=input('enter a sequence')
N=length(y);
for n=1:N
x(n)=0;
for k=1:N
x(n)=x(n)+y(k)*exp((2*j*pi*(k-1)*(n-1))/N);
end
end
z=x/N;
Output:
:
28
V.G.E.C.,Chandkheda Subject :Signal and System(4th sem E.C.)
EXPERIMENT No.9
AIM: To write a MATLAB program for computing rational z-transform from its
poles & zeros and vice- versa
Part(a). Determination of the rational Z-Transform from Its poles and zeros %
z=zr';
p=pr';
[num,den]=zp2tf(z,p,k);
Part(b). Determination of the poles and zeros drom its rational Z-Transform
[z,p,k]=tf2zp(num,den);
disp(p);
disp(z);
29
V.G.E.C.,Chandkheda Subject :Signal and System(4th sem E.C.)
disp('System Gain : ');
disp(k);
output:
1 -6 11 -6
1 -9 26 -24
Poles are :
4.0000
3.0000
2.0000
Zeros are :
30
V.G.E.C.,Chandkheda Subject :Signal and System(4th sem E.C.)
-1.6506
-0.1747 + 1.5469i
-0.1747 - 1.5469i
System Gain :
31
V.G.E.C.,Chandkheda Subject :Signal and System(4th sem E.C.)
Date:
EXPERIMENT No.10
AIM: To write a MATLAB program for computing partial fraction expansion of
the given z-transform using filter function.
disp('Residues: ');disp(r);
disp('Poles: ');disp(p);
x=[1, zeros(1,n-1)];
disp(y);
32
V.G.E.C.,Chandkheda Subject :Signal and System(4th sem E.C.)
output:
Residues:
-1.3333 + 0.4714i
-1.3333 - 0.4714i
Poles:
-0.3333 + 0.4714i
-0.3333 - 0.4714i
33