0% found this document useful (0 votes)
19 views33 pages

Signal and System - Lab - Manual

Uploaded by

dhyeytanna612
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)
19 views33 pages

Signal and System - Lab - Manual

Uploaded by

dhyeytanna612
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/ 33

VISHWAKARMA GOVERNMENT ENGG COLLEGE,CHANDKHEDA

BE SEM –IV(E.C)
SUBJECT: SIGNAL AND SYSTEM( )

SRNO. TITLE

1 Introduction to MATLAB and its usages.

2 To study different functions use in signal and system.

3 To plot various signals.

4 To study Convolution and De-convolution

5 To find DFT an IDFT of given sequence using MATLAB

6 To plot the frequency response of system using MATLAB


7 find the poles and zero and plot in the polar plot using
MATLAB
8 To study magnitude and phase response of a given function
9 To write a MATLAB program for computing rational z-
transform from its poles & zeros and vice- versa
10 To write a MATLAB program for computing partial fraction
expansion of the given z-transform using filter function.
V.G.E.C.,Chandkheda Subject :Signal and System(4th sem E.C.)
EXPERIMENT No.1
AIM: Introduction to MATLAB and its usages.

Description:

• MATLAB is a high – performance language for technical computing.


• It integrates computation, visualization and programming in an easy-to-use
environment where problems and solutions are expressed in familiar
mathematical notations. It includes…
▪ Math and Computation
▪ Algorithm development
▪ Data acquisition
▪ Modeling, simulation and prototyping
▪ Scientific and Engineering graphics
▪ Application development, including GUI building.
• The MATLAB system consists of five main parts:
1. Development Environment:
2. The MATLAB Mathematical Function Library:
3. The MATLAB Language:
4. Graphics:
5. The MATLAB Application Program Interface(API):
• There are the set of tools and facilities that help you use MATLAB functions and
files. Many of these tools are GUIs. It includes
▪ MATLAB desktop
▪ Command Window
▪ Command history,
▪ Editor
▪ Debugger
▪ Browsers for viewing help
▪ Workspace, files, and the search path.
• There are vast collection of computational algorithms ranging from elementary
functions like sum, sin, cosine, and complex arithmetic, to more sophisticated
functions like matrix inverse, matrix eigenvalues, Bessel Functions and fast
Fourier Transforms.
• Some of the examples of MATLAB exercise are given here.

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

5. Use a MATLAB command to create directly from matrix B, above, the


matrices
19
D= 
7
E = 19 7

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

6. Verify Woodberry's Identity: ( A + DE ) = A


−1 −1

( A DEA ) for A = 5
−1 −1
2
3 1 
(1 + EA D )
−1

Answer:

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

From the above 7th example we can observe that operator ” .* ”


multiplies two matrices element by element instead of normal matrix
multiplication .

8. Generate following using FOR loop:


E=[1,4,9,16,25,36,49,64,81,100]

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.

angle(x) : computes the phase angle of each component of the vector x.

conv(x,h) : compute convolution of two sequences x and h.

log 10(x) : computes the logarithm to the base 10 of the elements of x.

H=freqz(b,a,w) : returns the frequency response at frequencies designed in vector w, in


radians.

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

Where a, b, c are integers.

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:

1. Unit impulse signal


• It is denoted by δ(n).
• δ(n)=1 for n=0
• δ(n)=0 otherwise

Answer:
Clc;
Close all;
Clear all;
n=-2:2;
y=[n==0];
stem(n,y,'--+r');
title('impulse response');

Output:

2. Unit step signal


• It is denoted by u(n).
• u(n)=1 for n>=0
• u(n)=0 for n<0

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:

• LIT system is completely characterized by its unit impulse response.


• If unit impulse is applied to the system then its output is denoted by h (n) which
is called impulse response of the system.
• X (n) can be represented as sum of unit impulses this sum is known as
convolution sum.
• Y(n)=x(n)*h(n)
• The different operations involved in convolution are:
1) Folding: fold a sequence of h (k).
2) Shifting: time shifting of h (-k).
3) Multiplication: x(k)*h(n-k)
4) Summation: addition of all product terms
• Convolution and De-convolution of the signals can done using MATLAB built-in
function Conv( ) and Deconv( ).
• A generalized Convolution computing code without using MATLAB built-in
function conv(x,h) is given below:

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

enter the value of n: 20

n=
20

WAVEFORM:

Figure: waveform

Date:

21
V.G.E.C.,Chandkheda Subject :Signal and System(4th sem E.C.)
Date:
EXPERIMENT − 6

AIM: To plot the frequency response of system using MATLAB

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:

enter the value of numerator: [1 3 2 4]


enter the value of denominator: [2 3 1 2]

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:

enter the sequence for Numerator [1,1,1,1]


enter the sequence for denomenator [1,2,3,4]
zeros are
-1.6506
-0.1747 + 1.5469i
-0.1747 - 1.5469i
poles are
-1.0000
-0.0000 + 1.0000i
-0.0000 - 1.0000i

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:

• The given function is X ( )=

= (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:

• The discrete Fourier transform (DFT) is itself a sequence and it corresponds to


samples, equally spaced in frequency, of the Fourier transform of the signal. A
discrete transform is a transform whose input and output values are discrete
samples, making it convenient for computer manipulation.
• There are two principal reasons for using this form of the transform.
1) The input and output of the DFT are both discrete, which makes it convenient
for computer manipulations.
2) There is a fast algorithm for computing the DFT known as the Fast Fourier
transform (FFT).
• The equation for calculating the kth sample of the output DFT X(n) of the input
sequence x(n) with N samples is

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 %

zr=input('Type in the zeros as a row vector =');

pr=input('Type in poles as a row vector= ');

% Transpose zero and pole row vectors %

z=zr';

p=pr';

k=input('Type in the gain constant= ');

[num,den]=zp2tf(z,p,k);

disp('Numerator polynomial coefficients'); disp(num);

disp('Denominator polynomial coefficients');disp(den);

Part(b). Determination of the poles and zeros drom its rational Z-Transform

num=input('Type the numerator polynomial row vector: ');

den=input('Type the denominator polynomial row vector: ');

[z,p,k]=tf2zp(num,den);

disp('Poles are : ');

disp(p);

disp('Zeros are : ');

disp(z);
29
V.G.E.C.,Chandkheda Subject :Signal and System(4th sem E.C.)
disp('System Gain : ');

disp(k);

output:

Type in the zeros as a row vector =[1 2 3]

Type in poles as a row vector= [2 3 4]

Type in the gain constant= 1

Numerator polynomial coefficients

1 -6 11 -6

Denominator polynomial coefficients

1 -9 26 -24

Type the numerator polynomial row vector: [1 2 3 4]

Type the denominator polynomial row vector: [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.

clc; % clear workspace

clear all; % clear figures

num=input('Enter num coefficients : ');

den=input('Enter den coefficients : ');

[r,p,k]=residuez(num,den); % using residual function to compute partial


fraction

disp('Residues: ');disp(r);

disp('Poles: ');disp(p);

n=input('Enter the length of output vectors: ');

x=[1, zeros(1,n-1)];

y=filter(num,den,x); % filter function to get power series

disp('Coefficient of power series expansion:');

disp(y);

32
V.G.E.C.,Chandkheda Subject :Signal and System(4th sem E.C.)

output:

Enter num coefficients : [1 2 3]

Enter den coefficients : [3 2 1]

Residues:

-1.3333 + 0.4714i

-1.3333 - 0.4714i

Poles:

-0.3333 + 0.4714i

-0.3333 - 0.4714i

Enter the length of output vectors: 3

Coefficient of power series expansion:

0.3333 0.4444 0.5926

33

You might also like