Vous êtes sur la page 1sur 25

LABORATORY MANUAL

SIGNALS AND SYSTEMS WITH MATLAB

Ex.1.Write a Matlab code in Command window


to generate and Display Matrix.

Program:
>> x=rand(3,4)

Program:
Output:
>> x = [ 67 75 78 12 13; 21 22 64 87 87]
x=
Output:
0.9649

0.9572

0.1419

0.7922

0.1576

0.4854

0.4218

0.9595

0.9706

0.8003

0.9157

0.6557

x=
67

75

78

12

13

21

22

64

87

87

Ex.2. Write a Matlab code in Command window


to Find (i) Complement of a Matrix (ii) Addition
of two Matrices (iii) Multiplication of Two
Matrices.
Program:

Ex.4 Write a Matlab Code to generate a Sine


wave and Plot it.
Program:
clc; % clear command window
clear all; % Remove Items from work space and

>> x= [2 5 6;7 5 3;9 8 1]

freeing up system memory

Output:

close all;

x=

t=0:0.01:1;

x=sin(2*pi*t);
plot(t,x); % plots vector Y versus vector X.
Figure:

(i)Program:
>> y=x'
Output:
y=
2

(ii) Program:
>> z=x+y
Ex.5. Write a Matlab Code to generate and
display (i) Unit Impulse (ii)Step signal
(iii)Rectangular Pulse (iv) Triangular Pulse (v)
square wave (vi) Decreasing exponential:

Output:
z=
4

12

15
(i) Unit Impulse:

12

10

11

15

11

Program:
%Unit Impulse:
Ex.3 Write a Matlab Code to generate Random
sequence.

PROF.KINJAL VAGADIA

n=-10:0.001:10;

ASSISTANT PROF.

GEC,BHAVNAGAR

LABORATORY MANUAL

SIGNALS AND SYSTEMS WITH MATLAB

delta=(n==0);
subplot(2,1,1);
plot(n,delta);% continuous time
xlabel('time-->');
ylabel('signal value');
title('unit impulse signal');
subplot(2,1,2);

(iii)Program:

stem(n,delta);% discrete time

% Rectangular pulse

xlabel('time-->');

clc;

ylabel('signal value');

clear all;

title('unit sample sequence');

close all;

Figure:

t = -1:0.0001:1; % sampling rate 10KHz


x2 = rectpuls(t,1);
subplot(212);
plot(t,x2);
xlabel('Time ');
ylabel('Signal Value');
title('Rectangular Pulse');
Figure:

(ii) step function:


Program:
clc;
clear all;

(iv) Triangular Pulse:

close all;

Program :

fs = 10;

clc;

ts = [0:1/fs:5 5:1/fs:10];
clear all;
x = [zeros(1,51) ones(1,51)];
close all;
stairs(ts,x); % draws a stairstep graph
of the elements in vector Y at the
locations specified in X.

t = -1:0.0001:1; % sampling rate 10KHz


x1 = tripuls(t,1); % duration 1

Figure:

PROF.KINJAL VAGADIA

ASSISTANT PROF.

GEC,BHAVNAGAR

LABORATORY MANUAL

SIGNALS AND SYSTEMS WITH MATLAB

subplot(211);% divides the fig. window in two


rows
and one column
plot(t,x1);
xlabel('Time -->');
ylabel('Signal Value');
title('Triangular Pulse');
clc;
Figure:
close all;
clear all;
%syms a t w
t=0:0.1:10;
y=exp(-5*t);
plot(t,y);
(vi) Decreasing Exponential:
(v) Square wave:

Program:

Program:

clc;

clc;

close all;

clear all;

clear all;

close all;

%syms a t w

t = -10:0.001:10;

t=0:0.1:10;

x = square(2*pi*t,50); % dutycycle 50%

y=exp(-5*t);

plot(t,x);

plot(t,y);

title('Square Wave');

Figure:

xlabel('Time-->');
ylabel('Signal value');
axis([-10 10 0 1.5]);% sets scaling for the x- and yaxes on the current plot.
Figure:

PROF.KINJAL VAGADIA

ASSISTANT PROF.

GEC,BHAVNAGAR

LABORATORY MANUAL

SIGNALS AND SYSTEMS WITH MATLAB

Ex.6. Write Matlab code for Trigonometric


Fourier Series representation of Rectangular
Pulse train for various number of harmonics.

subplot(3,1,3);

Program:

xlabel('Time-->');

clc;

ylabel('Signal Value');

clear all;

title('reconstructed sig. with ripples')

close all;

Figures:

plot(t,x3);

t=-2*pi:0.001:+2*pi;
% Rectangular Signal
x=square(2*pi*1/(2*pi)*t);
subplot(3,1,1);
plot(t,x);
xlabel('time-->');
ylabel('Signal value');
title('periodic rectangular signal');
N=10 (No.of harmonics)

N=5; %harmonics in the series


% fourier coefficients and basis vector
n=0:N-1;
n1=2*n+1;
for i=1:N
x1(i)=4/(pi*n1(i));
x2(i,:)=(4/(pi*n1(i)))*(sin(2*pi*1/(2*pi)*n1(i)*t));
end
% Plot discrete fourier coefficients
subplot(3,1,2);

N=15

stem(n1,x1);
xlabel('value');
ylabel('Freq. index')
title('Discrete fourier spectrum');
%Reconstruction
x3(1,:)=sum(x2);

PROF.KINJAL VAGADIA

ASSISTANT PROF.

GEC,BHAVNAGAR

LABORATORY MANUAL

N=55

SIGNALS AND SYSTEMS WITH MATLAB

Ex.7 Write a Matlab code to find DTFT and


Inverse DTFT of given sequence x[n]=[6 8 9 4 0
15].
Program:
clc;
clear all;
close all;
x=[6 8 9 4 0 15];
L=length(x)
n=0:L-1;

N=105

k=0:L-1;
wn=exp(-j*2*pi/L);
nk=n'*k;
wLnk=wn.^nk;
df=x*wLnk;
subplot(3,1,1);
stem(x,abs(df));
title('DTFT Mag');
xlabel('k');
ylabel('Magnitude');

N=500

subplot(3,1,2);
stem(x,angle(df));

PROF.KINJAL VAGADIA

ASSISTANT PROF.

GEC,BHAVNAGAR

LABORATORY MANUAL

SIGNALS AND SYSTEMS WITH MATLAB

title('DTFT phase');
xlabel('k');
ylabel('phase');
wn=exp(j*2*pi/L);
nk=n'*k;
Ex.9. Write a Matlab code to Show Continuous
and Discrete Sine Wave.

wLnk=wn.^nk;
inversdf=(x*wLnk)/L;

Program:
subplot(3,1,3);
n=-10:10; % row vector, time points,
stem(x,abs(inversdf));
theta=2*pi/20;%frequency parameter
title('Inverse DTFT');
xlabel('N');

x=0.8*sin(theta*n);%sinusoidal
column vector x

sig.

stored

ylabel('Magnitude');

stem(n,x,'b');% discrete time plot in blue colour

Figure::

hold on;% to use the same figure window

in

xlabel('n'), ylabel('x[n]');
plot(n,x,'r');% continuous time plot in red colour
Figure:

Ex.8. Write a Matlab Code for Fourier


Representation of a Sequence.
Program:
clc;
clear all;

Ex.10. Write a Matlab Code to show Sampling


and Reconstruction.

close all;

%fs > 2fM: Original signal and sampled signal


have the same frequency.

syms a f; % constructing symbolic objects.


x = a*exp(-abs(a));
fourier(x,f) % is the Fourier transform of the sym
scalar f with default independent variable x. The
default return is a function of w.
Figure:

PROF.KINJAL VAGADIA

%fs < 2fM: Sampled signal is aliased to half the


original frequency.
Program:
t1 = 0:0.001:1;
x_ana = sin(2*pi*5*t1);
figure;
plot(t1,x_ana,':');

ASSISTANT PROF.

GEC,BHAVNAGAR

LABORATORY MANUAL

SIGNALS AND SYSTEMS WITH MATLAB

hold on
stem(t1,x_ana);

(i) Time shifting using Rectangular Pulse


Program:

f_samp1 = 50;
t_samp1 = 0:1/f_samp1:1;
xs1 = sin(2*pi*5*t_samp1);
figure;
plot(t_samp1,xs1,'--b');
hold on
stem(t_samp1,xs1,'r');
f_samp2 = 7.5;
t_samp2 = 0:1/f_samp2:1;
xs2 = sin(2*pi*5*t_samp2);
figure;
plot(t_samp2,xs2,'r')
hold on
stem(t_samp2,xs2,'b')
hold off

clear all;
close all;
t = -10:0.01:10;% sampling rate
10KHz
x2 = rectpuls(t,1);
subplot(211);
plot(t,x2); %continuous time
stem(t,x2);%discrete
xlabel('Time ');

Figures:

ylabel('Signal Value');
title('Rectangular Pulse');
x3 = rectpuls(t-4,1);
subplot(212);
plot(t,x3); %continuous time
stem(t,x3);%discrete
Figure:
Continuous

Time:

Discrete Time:

Ex.11. Write a Matlab code to perform Delaying


and Advancing of signals using (i) Rectangular
Pulse (ii) Sinusoidal Signal.
(ii) Time shifting using Sinusoidal signal:

PROF.KINJAL VAGADIA

ASSISTANT PROF.

GEC,BHAVNAGAR

LABORATORY MANUAL

SIGNALS AND SYSTEMS WITH MATLAB

Program:

clear all;

clear all;

close all;

close all;

t = -5:0.001:5;

clc;

x1 = rectpuls(t,3);

t =[ -8:0.001:8];

subplot(221);

subplot(3,1,1);

plot(t,x1); %continuous time

plot (t ,( sin ( -2*t)).*(t >0) );% original signal plot


title( 'original s i g n a l' );

xlabel('Time ');
ylabel('Signal Value');

xlabel('Time-->');
title('Rectangular Pulse Continuous');
ylabel('sig.value');
subplot(222);
subplot(3,1,2);
stem(t,x1);%discrete
plot (t ,( sin ( -2*(t -2))).*((t >2)))% d e l a y i n g
x(t) by 2 s e c ond

xlabel('Time ');

title('delayed signal');

ylabel('Signal Value');
title('Rectangular Pulse Discrete');

subplot(3,1,3)
plot (t ,( sin ( -2*(t+2))) .*(t > -2)) % advanc ing
x(t) by 2 s e c ond

x2 = rectpuls(4*t,3);
subplot(223);

xlabel('time-->');

xlabel('Time ');

ylabel('sig.value'); title ('advanced signal');

ylabel('Signal Value');

Figures:

title('Time scaled Rectangular Pulse Continuous');


plot(t,x2); %continuous time
subplot(224);
xlabel('Time ');
ylabel('Signal Value');
title('Time scaled Rectangular Pulse Discrete');
stem(t,x2);%discrete
Figure:

Ex.12.Write a Matlab code to perform


Compression and Expansion of signal using (i)
Rectangular Pulse (ii) Exponential Signal (iii)
Sinusoidal Signal.
(i) Rectangular Pulse Program:
%Compression:

PROF.KINJAL VAGADIA

Program:

ASSISTANT PROF.

GEC,BHAVNAGAR

LABORATORY MANUAL

SIGNALS AND SYSTEMS WITH MATLAB

%Expansion

Figure:

clear all;
close all;
t = -5:0.001:5;
x1 = rectpuls(t,3);
subplot(221);
plot(t,x1); %continuous time
xlabel('Time ');
ylabel('Signal Value');
title('Rectangular Pulse Continuous');
subplot(222);
stem(t,x1);%discrete
xlabel('Time ');
ylabel('Signal Value');
title('Rectangular Pulse Discrete');

(ii) Exponential Signal.


Program:
clear all;
close all;
clc;
t =[ -8:0.001:8];
subplot(3,1,1);

x2 = rectpuls(t/2,3);

plot (t ,( exp ( -2*t)).*(t >0) );%exponential signal


plot

subplot(223);

title( 'original s i g n a l' );

plot(t,x2); %continuous time

xlabel('Time-->');

xlabel('Time ');

ylabel('sig.value');

ylabel('Signal Value');

subplot(3,1,2);

title('Expansion in Time Domain');

plot (t ,( exp ( -2*(t)*4)).*((t>0)))% Compressed


signal

subplot(224);
stem(t,x2);%discrete
xlabel('Time ');

title('compressed signal');
subplot(3,1,3);

ylabel('Signal Value');

plot (t ,( exp ( -2*(t)*(1/2))) .*(t>0)) % expanded


signal

title('Expansion in Time Domain');

xlabel('time-->');
ylabel('sig.value');
title ('expanded signal');

PROF.KINJAL VAGADIA

ASSISTANT PROF.

GEC,BHAVNAGAR

LABORATORY MANUAL

SIGNALS AND SYSTEMS WITH MATLAB

Figure:

(iii) Compression
Sinusoidal Signal:

Figure:

and

Expansion

using

Program:
clear all;
Ex.13. Write a Matlab code to perform Folding
in Time Domain.

close all;
clc;

Program:
t =[ -8:0.001:8];
%Time reversal: Folding
subplot(3,1,1);
clear all;
plot (t , sin(t) );%original signal plot
close all;
title( 'original s i g n a l' );
t=-5:0.001:5;
xlabel('Time-->');
subplot(3,1,2);

ylabel('sig.value');
x1=exp(t);

plot (t ,sin(t*4))% Compressed signal

subplot(221);

title('compressed signal');

plot(t,x1); %continuous time

subplot(3,1,3)

xlabel('Time ');

plot (t ,sin (t*(1/4))) % expanded signal

ylabel('Signal Value');

xlabel('time-->');

title('Original signal');

ylabel('sig.value');

subplot(222);

title ('expanded signal');

stem(t,x1);%discrete
xlabel('Time ');
ylabel('Signal Value');
title('Exponential sequence Discrete');
x2 = fliplr(x1);
subplot(223);

PROF.KINJAL VAGADIA

ASSISTANT PROF.

GEC,BHAVNAGAR

LABORATORY MANUAL

SIGNALS AND SYSTEMS WITH MATLAB

plot(t,x2); %continuous time

clear all;

xlabel('Time ');

t=-10:0.001:10;

ylabel('Signal Value');

%Original Exponential Signal:

title('time reversed');

u=(t>=0);

subplot(224);

subplot(411);

stem(t,x2);%discrete

plot(t,u);

xlabel('Time ');

x1=exp(-1.5*t).*u;

ylabel('Signal Value');

subplot(4,1,2);

title('time reversed');

plot(t,x1);

Figure:

title('x1(t)');
%Time reversed signal x1(-t)
x2=fliplr(x1);
%Even component x1e(t)
x1e=0.5*(x1+x2);
subplot(4,1,3);
plot(t,x1e);
title('even component');
%Odd component x1o(t)

t=-5:0.1:5;

x1o=0.5*(x1-x2);
subplot(4,1,4);
plot(t,x1o);
xlabel('time');
ylabel('signal value');
title('odd component');
Figure:
Ex.14. Write a Matlab code to find Even and
Odd functions of (i) Exponential signal (ii) Sine
wave.
(i)Exponential signal:
Program:
%Even_odd
clc;
close all;

PROF.KINJAL VAGADIA

ASSISTANT PROF.

GEC,BHAVNAGAR

LABORATORY MANUAL

SIGNALS AND SYSTEMS WITH MATLAB

(ii) Sine Wave:


clc;
close all;
clear all;
t=-10:0.001:10;
%Original Sine wave:
u=(t>=0);
subplot(411);
plot(t,u);

Ex.15. Write a Matlab Code to find Magnitude


and Phase Response of a system.

x1=sin(t).*u;

Program:

subplot(4,1,2);

% magnitude and phase response

plot(t,x1);

clc;

title('x1(t)');

clear all;

%Time reversed signal x1(-t)

close all;

x2=fliplr(x1);

x1=3.005;

%Even component x1e(t)

A=0.654

x1e=0.5*(x1+x2);

omega=0:0.001*pi:2*pi

subplot(4,1,3);

x2=[2.5 -1.766]

plot(t,x1e);

x3=1-(A.*exp((-j).*(omega)))

title('even component');

x3=x1./x3

%Odd component x1o(t);

x4=conj(x3);

x1o=0.5*(x1-x2);

mag=abs(x3);

subplot(4,1,4);

phase_angle=angle(x3);

plot(t,x1o);

freqz(x1,x2)

xlabel('time');

figure,plot(omega,20*log10(mag))
magnitude vs frequency

% absolute value of c
% angle of c

% plot the

ylabel('signal value');
xlabel('frequency-angular');
title('odd component');
ylabel('magnitude');
Figure:
title('magnitude vs angular-Frequency')
grid on;
figure,plot(omega,phase_angle)

PROF.KINJAL VAGADIA

ASSISTANT PROF.

GEC,BHAVNAGAR

LABORATORY MANUAL

SIGNALS AND SYSTEMS WITH MATLAB

xlabel('angular Frequency');
ylabel('Phase_angle_variations');
title('Variations in Phase vs angular-Frequencyl')
%plot phase vs frequency
grid on;
energy=x3.*x4
figure,plot(omega,20*log10(energy))
energy vs frequency

% plot

xlabel('angular Frequency');
ylabel('Energy');
title('Energy vs Frequency')
grid on;
Figure:

Ex.16.Write Matlab code to find Impulse


Response of a system.
Program:
clear all;
close ;
clc ;
n =(0:0.1:10) ;
x =[1 zeros(1,length(n)-1)];
a =[0.5 -0.55 -0.156];
b =[4 0 0];
h= filter (b,a,x);

PROF.KINJAL VAGADIA

ASSISTANT PROF.

GEC,BHAVNAGAR

LABORATORY MANUAL

SIGNALS AND SYSTEMS WITH MATLAB

subplot(2,1,1);

y2=sqrt(x2); %square root system

plot(n,h);

yt=a.*y1+b.*y2;% homogenity and superposition --o/p(2)

subplot(2,1,2);
stem (n,h);

d=y-yt;% difference between o/ps (1)and (2)

xlabel ( ' n ' );

subplot(3,1,1);

ylabel ( ' h [ n ] ' );

stem(n,y);

Figure:

axis([0 10 -5 5]);
xlabel('n-->');
ylabel('signal value');
title('o/p of system for x[n]');
subplot(3,1,2);
stem(n,yt);
axis([0 10 -5 5]);
xlabel('n-->');
ylabel('signal value');

Ex.17. Write a Matlab code for checking


Linearity of following systems (i) Square root
system (ii) Amplitude Scaling system (iii)
Logarithmic System.
(i)

Square root system

title('o/p of system for a.*x1+b.*x2 ');


subplot(3,1,3);
stem(n,d);
axis([0 10 -5 5]);

(a)Program:

xlabel('n-->');

clear all;

ylabel('difference value');

close all;

title('difference between o/ps');

clc;

Figure:

n=0:10;
a=2;
b=-3;
x1=cos(2*pi*.1*n);%i/p1
x2=cos(2*pi*.5*n); %i/p2
x=a.*x1+b.*x2;%homogenity and superposition
y=sqrt(x);% square root system---o/p(1)
y1=sqrt(x1); %square root system

PROF.KINJAL VAGADIA

(b) Program:
clc;

ASSISTANT PROF.

GEC,BHAVNAGAR

LABORATORY MANUAL

SIGNALS AND SYSTEMS WITH MATLAB

clear all;

x1=sin(2*pi*.1*n);%i/p1

close all;

x2=cos(2*pi*.5*n); %i/p2

x1=[1 6 8 9];

x=a.*x1+b.*x2;%homogenity and superposition

x2=[5 8 2 0];

y=0.5*x; %o/p(1)

y1=sqrt(x1);

y1=0.5*x1;

y2=sqrt(x2);

y2=0.5*x2;

x=x1+x2;

yt=a.*y1+b.*y2;% homogenity and superposition --o/p(2)

y=sqrt(x); %square root system


d=y-yt;% difference between o/ps (1)and (2)
y3=y1+y2;
subplot(3,1,1);
y4=y-y3;
stem(n,y);
if y4==0
axis([0 10 -5 5]);
disp('linear');
xlabel('n-->');
else
ylabel('signal value');
disp('nonlinear');
title('o/p of system for x[n]');
end
subplot(3,1,2);
stem(n,yt);
axis([0 10 -5 5]);
xlabel('n-->');
ylabel('signal value');
title('o/p of system for a.*x1+b.*x2 ');
subplot(3,1,3);
(ii)

Amplitude Scaling System:

(a) Program:
clc;
clear all;
close all;
n=0:10;

stem(n,d);
axis([0 10 -5 5]);
xlabel('n-->');
ylabel('difference value');
title('difference between o/ps');
Figure:

a=2;
b=-3;

PROF.KINJAL VAGADIA

ASSISTANT PROF.

GEC,BHAVNAGAR

LABORATORY MANUAL

SIGNALS AND SYSTEMS WITH MATLAB


Output:

(c) Program:
clc;
clear all;
close all;
x1=[1 6 8 9];
% Amplitude scaling system:

x2=[5 8 2 0];

(b) Program:

y1=0.5*(x1);

clc;

y2=0.5*(x2);

clear all;

x=7*x1+0.8*x2;

close all;

y=0.5*(x);

x1=[1 6 8 9];

y3=y1+y2;

x2=[5 8 2 0];

y4=y3-y;

y1=0.5*(x1);
y2=0.5*(x2);

if y4<0.0000000001
disp('linear');
else

x=x1+x2;
disp('nonlinear');
y=0.5*(x);
end
y3=y1+y2;

Output:

y4=y-y3;
if y4==0
disp('linear');
else
disp('nonlinear');
end

PROF.KINJAL VAGADIA

ASSISTANT PROF.

GEC,BHAVNAGAR

LABORATORY MANUAL

SIGNALS AND SYSTEMS WITH MATLAB


clc;
clear all;
close all;
b= input('coefficiens of i/p terms, b=');
a=input('coefficiens of i/p terms, a=');
x1=rand(1,10); % i/p original

(iii) Logarithmic system:


Program:

x2=[zeros(1,4) x1]% Time shifted i/p by 4 samples

clc;

y1=filter(b,a,x1);% original o/p

clear all;

y2=filter(b,a,x2);% o/p due to shifted i/p

close all;

y3=[zeros(1,4) y1]; %shifted o/p

x1=[1 6 8 9];

if y3==y2

x2=[5 8 2 0];

disp('Time Invariant');

y1=log(x1); %logarithmic system

else

y2=log(x2);

disp('Time Variant');

x=x1+x2;
end
y=log(x);
Output:
y3=y1+y2;
y4=y-y3;
if y4==0
disp('linear');
else
disp('nonlinear');
end
Output:

Ex.19. Write a Matlab code to perform Z.T of


(1/16)n and Inverse Z.T also plot pole-zero plot.
(a) Z.T. :
Program:
Ex.18. Write a Matlab Code to check Time
Invariance / Variance of a system.

clc;

Program:

clear all;

PROF.KINJAL VAGADIA

ASSISTANT PROF.

GEC,BHAVNAGAR

LABORATORY MANUAL

SIGNALS AND SYSTEMS WITH MATLAB

close all;
syms z n; % symbolic objects
x=(1/16)^n;
disp('original is (1/16^)n ');
disp('Z.T. is ');
X=ztrans((1/16)^n) %Z.T.
% inverse Z.T.
disp('inverse z.t. is');
x1=iztrans(16*z/16*z-1)
% Roots
b=[1];
a=[1 -1/16];
display('poles');
A=roots(a)
display('zeros');
B=roots(b)
zplane(b,a);

(b)Program:
clc;
clear all;
close all;
syms b n;
g = b^n;
ztrans(g)
Output:

title('pole-zero plot in z-plane');


Output:

Ex.20. Write Matlab code for Root Locus in Splane.


Program:
clc;
close all;
clear all;
x = tf([5 4 3 2],[1 0 0 0]); % transfer function: (5
s^3 + 4 s^2 + 3 s + 2)/ s^3

PROF.KINJAL VAGADIA

ASSISTANT PROF.

GEC,BHAVNAGAR

LABORATORY MANUAL

SIGNALS AND SYSTEMS WITH MATLAB

rlocus(x); %computes and plots the root locus of


the single-input,single-output LTI model SYS

close all;
clear all;
syms a t w
x = sin(a*t)*exp(-5*t);
L = laplace(x)
Output:

Ex.21. Write Matlab code to Perform Laplace


Transformation
of
(i)
exp(-a*t)
(ii)
sin(a*t)*exp(-5*t)(iii) sin(a*t)*exp(5*t).

(iii) sin(a*t)*exp(5*t).

Program:

x = sin(a*t)*exp(5*t);

(i)exp(-a*t)

L = laplace(x)

clc;

Output:

close all;
clear all;
syms a t w
x = exp(-a*t); %EXP(X) is the exponential of the
lements of X
L = laplace(x)
%LAPLACE(F) is the Laplace
ransform of the scalar sym F with default
independent variable t.
The default return
is a function of s.
Output:

Ex.22. Write Matlab code to find closed loop


transfer function.
clc;
clear all;
close all;
a=tf([2 6],[2])%Transfer function: (2s + 6)/2
b=tf([5],[3 7]) % 5/(3 s + 7)

(iii)

sin(a*t)*exp(-5*t)
Program:

k=feedback(a,b) %Transfer function: (6 s^2 + 32 s


+ 42)/(16 s + 44)

clc;

PROF.KINJAL VAGADIA

ASSISTANT PROF.

GEC,BHAVNAGAR

LABORATORY MANUAL

SIGNALS AND SYSTEMS WITH MATLAB


ylabel('signal value');
xlabel('time-->');
title('convolved signal') ;
Figure:

Ex.23. Write Matlab code for Linear


convolution of (i) Impulse and Ramp signals (ii)
Sine and Exponential signals.
(i) Impulse and Ramp signals
Program:
(ii) Sine and Exponential signals.
clc;
Program:
clear all;
close all;
x1=zeros(1,100);
x1(1,50)=1;
a=1:0.01:50;
x2=a;
y=conv(x1,x2);
subplot(2,2,1);plot(x1);
ylabel('signal value');
xlabel('time-->');
title('first signal');
subplot(2,2,2);plot(a,x2);
ylabel('signal value');
xlabel('time-->');
title('second signal');
subplot(2,2,3:4);plot(y);

PROF.KINJAL VAGADIA

clc;
clear all;
close all;
t=-40:0.1:40;
x1=sin(t);
a=1:0.1:40;
x2=exp(a);
y=conv(x1,x2)
subplot(2,2,1);plot(t,x1);
ylabel('signal value');
xlabel('time-->');
title('first signal');
subplot(2,2,2);plot(a,x2)
ylabel('signal value');
xlabel('time-->');
title('second signal');

ASSISTANT PROF.

GEC,BHAVNAGAR

LABORATORY MANUAL

SIGNALS AND SYSTEMS WITH MATLAB

subplot(2,2,3:4);plot(y);

stem(con_cir)

ylabel('signal value');

title('Circular Convolution of a1 and b1');

xlabel('time-->');

Output:

title('convolved signal');
Figure:

Figure:

Ex.24. Write Matlab code to find Linear and


Circular Convolution of two sequences.
(i)

Program:

clc;
close all;
(ii)

clear all;

Program:

a= [2 5 9 6];

clc;

b = [1 2 3];

close all;

con_lin = conv(a,b);

clear all;

subplot(2,1,1);

a= [2 5 9 6];

stem(con_lin);

b = [1 2 3 5];

title('Linear Convolution of a and b');

con_lin = conv(a,b);

a1 = [a zeros(1,6-length(a))];% padded sequence

subplot(2,1,1);

b1 = [b zeros(1,6-length(b))];% padded sequence

stem(con_lin);

con_cir = ifft(fft(a1).*fft(b1));

title('Linear Convolution of a and b');

subplot(2,1,2);

display(con_lin);

PROF.KINJAL VAGADIA

ASSISTANT PROF.

GEC,BHAVNAGAR

LABORATORY MANUAL

SIGNALS AND SYSTEMS WITH MATLAB

a1 = [a zeros(1,7-length(a))];% padded sequence

stem(con_lin);

b1 = [b zeros(1,7-length(b))];% padded sequence

title('Linear Convolution of a and b');

con_cir = ifft(fft(a1).*fft(b1));

display(con_lin);

subplot(2,1,2);

a1 = [a zeros(1,5-length(a))];% padded sequence

stem(con_cir)

b1 = [b zeros(1,5-length(b))];% padded sequence

title('Circular Convolution of a1 and b1');

con_cir = ifft(fft(a1).*fft(b1));

display(con_cir);

subplot(2,1,2);

Output:

stem(con_cir)
title('Circular Convolution of a1 and b1');
display(con_cir);
Output:

Figure:
Figure:

(iii)

Program:

clc;
close all;
clear all;

Ex.25. Write Matlab Code for finding Fourier


Transform.
Program:

a= [2 5 87];
clc;
b = [1 2 3];
clear all;
con_lin = conv(a,b);
close all;
subplot(2,1,1);

PROF.KINJAL VAGADIA

ASSISTANT PROF.

GEC,BHAVNAGAR

LABORATORY MANUAL

SIGNALS AND SYSTEMS WITH MATLAB

syms x y

Ex.27. Write Matlab code to Plot the


autocorrelation sequence of (i)sine wave with
frequency 10 Hz, sampling frequency of 1000 Hz
(ii) Exponential signal, sampling frequency of
500 Hz.

f = exp(-x^2);
fourier(f, x, y)
Output:

(i)
Auto Correlation of sine wave with
frequency 10 Hz, sampling frequency of 1000 Hz
Program:
clc;
clear all;
close all;

Ex.26. Write Matlab Code to find Fourier


Transform and Inverse Fourier Transform.

N=256 % Number of samples


f_original=10; % Original sinewave freq.

Program:
F_Samp=1000; % Sampling Frequency
clc;
n=0:N-1; % Sample index
clear all;
close all;

x=sin(2*pi*f_original*n/F_Samp); % sinusoidal
signal

syms x t y

t=[1:N]*(1/F_Samp); % time axis

f = exp(-x^2)*exp(-t^2);

subplot(2,1,1); % for figure

display('F.T. of exp(-x^2)*exp(-t^2)is ');

plot(t,x); % Plot x(t)

F=fourier(f, y) % F = FOURIER(f) is the Fourier


transform of the sym scalar f

title('Original Sinwave');

with default independent variable x. The d


xlabel('Time, [sec]');

display('Inverse F.T. of fourier(f, y)is ');


ylabel('SIGNAL VALUE');
ifourier(F) % inverse Fourier transform of the
scalar sym F with default independent variable
w.The default return is a function of x.
Output:

Rxx=xcorr(x); % autocorrelation
subplot(2,1,2); % for figure
plot(Rxx); % Plot the autocorrelation
xlabel('lags');
ylabel('Autocorrelated Value');
title('Autocorrelation function of the sinewave');
Figure:

PROF.KINJAL VAGADIA

ASSISTANT PROF.

GEC,BHAVNAGAR

LABORATORY MANUAL

SIGNALS AND SYSTEMS WITH MATLAB

(ii) Auto Correlation of Exponential signal,


sampling frequency of 500 Hz.
Program:
clc;

Ex.28. Write Matlab code to find Cross


Correlation of (i)Sinusoidal signal and Random
Noise signal (ii) Exponential signal and Random
Noise signal.

clear all;
close all;

(i)Cross Correlation of Sinusoidal signal and


Random Noise signal

N=512; % Number of samples

Program:

FS=500; % Sampling Frequency

title('Autocorrelation function');

clc;
clear all;
close all;
% cross correlation
N=512; % Number of samples
f_original_sine=10; % Frequency of the original
sinewave
F_Samp=1000; % Sampling frequency
n=0:N-1; % Sampling index
x=sin(2*pi*f_original_sine*n/F_Samp);
%
sinusoidal signal x[n]
y=x+10*randn(1,N); % Generate random noise
y(n)
subplot(3,1,1); % for figure
plot(x);
xlabel('time-->');
ylabel('Signal value');
title('Original Sinewave');
subplot(3,1,2);
plot(y); % Noise
xlabel('time-->');
ylabel('Signal value');
title('Sinewave + Noise');
Rxy=xcorr(x,y); % Estimate the cross correlation
subplot(3,1,3);
plot(Rxy);
xlabel('time-->');
ylabel('Correlated value');
title('Cross correlated signal');

Figure:

Figure:

n=0:N-1; % Sample index


x= exp(2*pi*n/FS); % Exponential signal
t=[1:N]*(1/FS); % time axis
subplot(2,1,1); % for figure
plot(t,x); % Plot x(t)
title('Original signal');
xlabel('Time, [s]');
ylabel('SIGNAL VALUE');
Rxx=xcorr(x); % autocorrelation
subplot(2,1,2); % for figure
plot(Rxx); % Plot the autocorrelation
xlabel('lags');
ylabel('Autocorrelated Value');

PROF.KINJAL VAGADIA

ASSISTANT PROF.

GEC,BHAVNAGAR

LABORATORY MANUAL

SIGNALS AND SYSTEMS WITH MATLAB

(ii) Exponential signal and Random Noise signal.


Program:
clc;
clear all;
close all;
N=512; % Number of samples
f_original_expo=10; % Frequency of the original
signal
F_samp=1000; % Sampling frequency
n=0:N-1; % Sampling index
x=exp(2*pi*f_original_expo*n/F_samp);
%
exponential signal x[n]
y=x+10*randn(1,N); % Generate random noise
y(n)
subplot(3,1,1); % for figure
plot(x);
xlabel('time-->');
ylabel('Signal value');
title('Original signal');
subplot(3,1,2);
plot(y); % Noise
xlabel('time-->');
ylabel('Signal value');
title('original signal + Noise');
Rxy=xcorr(x,y); % Estimate the cross correlation
subplot(3,1,3);
plot(Rxy);
xlabel('time-->');
ylabel('Correlated value');
title('Cross correlated signal');
Figure:

PROF.KINJAL VAGADIA

ASSISTANT PROF.

GEC,BHAVNAGAR

Vous aimerez peut-être aussi