BASIC SIMULATION
LABORATORY MANUAL
II–I SEMESTER
Prepared By
[Link], Associate Professor
DEPARTMENT OF ELECTRONICS AND COMMUNICATIONS ENGG
PEDDAPALLY-505172, Dist. Peddapalli. (T.S)
CONTENTS
[Link] Experiment Name
Generation of Various Signals and Sequences such as Unit Impulse, Unit
1.
Step, Square, Sawtooth, Triangular, Sinusoidal, Ramp, Sinc.
Operations on Signals and Sequences such as Addition, Multiplication,
2.
Scaling, Shifting, Folding.
Finding the Even and Odd parts of Signal/ Sequence and Real and Imaginary
3.
parts of Signal
4. Convolution between Signals and sequences
5. Auto Correlation and Cross Correlation between Signals and Sequences
6. Verification of Linearity Properties of a given Continuous/ Discrete System.
Verification of Time Invariance Properties of a given Continuous/ Discrete
7.
System.
Finding the Fourier Transform of a given signal and plotting its magnitude
8.
and phase spectrum
9. Waveform Synthesis using Laplace Transform.
10 Sampling Theorem Verification.
ExperimentNo-1
Generation of signals and sequences
AIM: Generate various signals and sequences (Periodic and aperiodic), such as Unit
Impulse, Unit Step, Square, Saw tooth, Triangular, Sinusoidal, Ramp, Sinc.
Software Required: Matlab software
PROGRAM:
%Generation of signals and sequences
clc;
clearall;
closeall;
% generation of unit impulse signal
t1=-1:0.01:1;
y1= (t1==0);
subplot(2,2,1);
plot(t1,y1);
xlabel('time');
ylabel('amplitude');
title('unit impulse signal');
% generation of impulse sequence
subplot(2,2,2);
stem(t1,y1);
xlabel('n');
ylabel('amplitude');
title('unit impulse sequence');
% generation of unit step signal
t2=-10:1:10;
y2=(t2>=0);
subplot (2,2,3);
plot (t2,y2);
xlabel('time');
ylabel('amplitude');
title('unit step signal');
% generation of unit step sequence
subplot(2,2,4);
stem(t2,y2);
xlabel('n');
ylabel('amplitude');
title('unit step sequence');
% generation of square wave signal
t=0:0.002:0.1;
y3=square(2*pi*50*t);
figure;
subplot(2,2,1);
plot(t,y3);
axis([0 0.1 -2 2]);
xlabel('time');
ylabel('amplitude');
title('squarewave signal');
% generation of square wave sequence
subplot(2,2,2);
stem(t,y3);
axis([0 0.1 -2 2]);
xlabel('n');
ylabel('amplitude');
title('squarewavesequence');
% generation of sawtooth signal
y4=sawtooth(2*pi*50*t);
subplot(2,2,3);
plot(t,y4);
axis([0 0.1 -2 2]);
xlabel('time');
ylabel('amplitude');
title('sawtoothwavesignal');
% generation of sawtooth sequence
subplot(2,2,4);
stem(t,y4);
axis([0 0.1 -2 2]);
xlabel('n');
ylabel('amplitude');
title('sawtoothwavesequence');
% generation of triangular wave signal
y5=sawtooth(2*pi*50*t,.5);
figure;
subplot(2,2,1);
plot(t,y5);
axis([0 0.1 -2 2]);
xlabel('time');
ylabel('amplitude');
title('triangularwavesignal');
% generation of triangular wave sequence
subplot(2,2,2);
stem(t,y5);
axis([0 0.1 -2 2]);
xlabel('n');
ylabel('amplitude');
title('triangularwavesequence');
% generation of sinusoidal wave signal
y6=sin(2*pi*40*t);
subplot(2,2,3);
plot(t,y6);
axis([0 0.1 -2 2]);
xlabel('time');
ylabel('amplitude');
title('sinsoidalwavesignal');
% generation of sinwave sequence
subplot(2,2,4);
stem(t,y6);
axis([0 0.1 -2 2]);
xlabel('n');
ylabel('amplitude');
title('sinwavesequence');
% generation of ramp signal
y7=t;
figure;
subplot(2,2,1);
plot(t,y7);
xlabel('time');
ylabel('amplitude');
title('rampsignal');
% generation of ramp sequence
subplot(2,2,2);
stem(t,y7);
xlabel('n');
ylabel('amplitude');
title('ramp sequence');
% generation of sinc signal
t3=linspace(-5,5);
y8=sinc(t3);
subplot(2,2,3);
plot(t3,y8);
xlabel('time');
ylabel('amplitude');
title('sincsignal');
% generation of sinc sequence
subplot(2,2,4);
stem(y8);
xlabel('n');
ylabel('amplitude');
title('sincsequence');
Result:
Various signals & sequences generated using Matlab software.
Output:
Experiment No-2
Basic Operations on Signals and sequences
AIM: perform the operations on signals and sequences such as addition, multiplication,
scaling, shifting, and folding
Software Required: Matlab software.
Program:
clc;clearall;
closeall;
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
% generating two input signals
t=0:.01:1;
x1=sin(2*pi*4*t);
x2=sin(2*pi*8*t);
subplot(2,2,1);
plot(t,x1);
xlabel('time');
ylabel('amplitude');
title('inputsignal1');
subplot(2,2,2);
plot(t,x2);
xlabel('time');
ylabel('amplitude');
title('inputsignal2');
% addition of signals
y1=x1+x2;
subplot(2,2,3);
plot(t,y1);
xlabel('time');
ylabel('amplitude');
title('addition of two signals');
% multiplication of signals
y2=x1.*x2;
subplot(2,2,4);
plot(t,y2);
xlabel('time');
ylabel('amplitude');
title('multiplication of two signals');
% scaling of a signal1
A=2;
y3=A*x1;
figure;
subplot(2,2,1);
plot(t,x1);
xlabel('time');
ylabel('amplitude');
title('inputsignal');
subplot(2,2,2);
plot(t,y3);
xlabel('time');
ylabel('amplitude');
title('amplified input signal');
% folding of a signal1
h=length(x1);
nx=0:h-1;
subplot(2,2,3);
plot(nx,x1);
xlabel('nx');
ylabel('amplitude');
title('inputsignal');
y4=fliplr(x1);
nf=-fliplr(nx);
subplot(2,2,4);
plot(nf,y4);
xlabel('nf');
ylabel('amplitude');
title('foldedsignal');
% shifting of a signal1
figure;
subplot(3,1,1);
plot(t,x1);
xlabel('time t');
ylabel('amplitude');
title('inputsignal');
subplot(3,1,2);
plot(t+2,x1);
xlabel('t+2');
ylabel('amplitude');
title('rightshiftedsignal');
subplot(3,1,3);
plot(t-2,x1);
xlabel('t-2');
ylabel('amplitude');
title('leftshiftedsignal');
% operations on sequences
n1=1:1:9;
s1=[1 2 3 0 5 8 0 2 4];
figure;
subplot(2,2,1);
stem(n1,s1);
xlabel('n1');
ylabel('amplitude');
title('input sequence1');
s2=[1 1 2 4 6 0 5 3 6];
subplot(2,2,2);
stem(n1,s2);
xlabel('n2');
ylabel('amplitude');
title('input sequence2');
% addition of sequences
s3=s1+s2;
subplot(2,2,3);
stem(n1,s3);
xlabel('n1');
ylabel('amplitude');
title('sumoftwosequences');
% multiplication of sequences
s4=s1.*s2;
subplot(2,2,4);
stem(n1,s4);
xlabel('n1');
ylabel('amplitude');
title('productoftwosequences');
Result: Various operations on signals and sequences are performed.
Output:
Experiment No-3
Even and odd parts of signal and sequence & Real and imaginary parts of Signal
AIM: Finding even and odd part of the signal and sequence and also find real and
imaginary parts of signal.
Software Required: Matlab software
Program:
clc;
closeall;
clear all;
% Even and odd parts of a signal
t=0:.001:4*pi;
x=sin(t)+cos(t);
subplot(2,2,1)
plot(t,x);
xlabel('t');
ylabel('amplitude')
title('inputsignal');
y=sin(-t)+cos(-t);
subplot(2,2,2)
plot(t,y);
xlabel('t');
ylabel('amplitude');
title('inputsignalwitht=-t');
even=(x+y)/2;
subplot(2,2,3);
plot(t,even);
xlabel('t');
ylabel('amplitude')
title('evenpartofthesignal');
odd=(x-y)/2;
subplot(2,2,4);
plot(t,odd);
xlabel('t');
ylabel('amplitude');
title('oddpartofthesignal');
% Even and odd parts of a sequence
x1=[0,2,-3,5,-2,-1,6];
n=-3:3;
y1=fliplr(x1);
figure;
subplot(2,2,1);
stem(n,x1);
xlabel('n');
ylabel('amplitude');
title('inputsequence');
subplot(2,2,2);
stem(n,y1);
xlabel('n');
ylabel('amplitude');
title('inputsequencewithn=-n');
even1=.5*(x1+y1);
odd1=.5*(x1-y1);
% plotting even and odd parts of the sequence
subplot(2,2,3);
stem(n,even1);
xlabel('n');
ylabel('amplitude');
title('evenpartofsequence');
subplot(2,2,4);
stem(n,odd1);
xlabel('n');
ylabel('amplitude');
title('oddpartofsequence');
% plotting real and imaginary parts of the signal x2=sin(t)
+j*cos(t);
figure;
subplot(3,1,1);
plot(t,x2);
xlabel('t');
ylabel('amplitude');
title('inputsignal');
subplot(3,1,2);
plot(t,real(x2));
xlabel('time');
ylabel('amplitude');
title('realpartofsignal');
subplot(3,1,3);
plot(t,imag(x2));
xlabel('time');
ylabel('amplitude');
title('imaginarypartofsiganl');
RESULT: Even and odd part of the signal and sequence, real and imaginary parts of
signal are computed.
Output:
Experiment No-4
Convolution between signals & sequences
Aim: Write the program for convolution between two signals and also between two
sequences.
Software Required: Matlab software
Program:
clc;
closeall;
clear all;
% program for convolution of two sequences
x=input('enter input sequence: ');
h=input('enter impulse response: ');
y=conv(x,h);
subplot(3,1,1);
stem(x);
xlabel('n');
ylabel('x(n)');
title('inputsequence');
subplot(3,1,2);
stem(h);
xlabel('n');
ylabel('h(n)');
title('impulseresponsesequence');
subplot(3,1,3);
stem(y);
xlabel('n');
ylabel('y(n)');
title('linearconvolution');
disp('linearconvolutiony=');
disp(y);
% program for signal convolution
t=0:0.1:10;
x1=sin(2*pi*t);
h1=cos(2*pi*t);
y1=conv(x1,h1);
figure;
subplot(3,1,1);
plot(x1);
xlabel('t');
ylabel('x(t)');
title('inputsignal');
subplot(3,1,2);
plot(h1);
xlabel('t');
ylabel('h(t)');
title('impulseresponse');
subplot(3,1,3);
plot(y1);
xlabel('n');
ylabel('y(n)');
title('linearconvolution');
RESULT: Convolution between signals and sequences is computed.
Output:
Enter input sequence:[1 3 4 5]
Enter impulse response:[2 1 4]
linear convolution y=
2 7 15 26 21 20
Program:
clc;closeall; clearall;
Experiment No-5
Auto correlation and Cross correlation
Aim: To compute Auto correlation and Cross correlation between signals and sequences.
Software Required: Matlab software
% two input sequences
x=input('enter input sequence');
h=input('enter the impulse suquence');
subplot(2,2,1);
stem(x);
xlabel('n');
ylabel('x(n)');
title('input sequence');
subplot(2,2,2);
stem(h);
xlabel('n');
ylabel('h(n)');
title('impulse sequence');
% cross correlation between two sequences
y=xcorr(x,h);
subplot(2,2,3);
stem(y);
xlabel('n');
ylabel('y(n)');
title('crosscorrelationbetweentwosequences');
% auto correlation of input sequence
z=xcorr(x,x);
subplot(2,2,4);
stem(z);
xlabel('n');
ylabel('z(n)');
title('autocorrelationofinputsequence');
% cross correlation between two signals
t=0:0.2:10;
x1=3*exp(-2*t);
h1=exp(t);
figure;
subplot(2,2,1);
plot(t,x1);
xlabel('t');
ylabel('x1(t)');
title('inputsignal')
; subplot(2,2,2);
plot(t,h1);
xlabel('t');
ylabel('h1(t)');
title('impulsesignal');
%crosscorrelation
subplot(2,2,3);
z1=xcorr(x1,h1);
plot(z1);
xlabel('t');
ylabel('z1(t)');
title('crosscorrelation');
%autocorrelation
subplot(2,2,4);
z2=xcorr(x1,x1);
plot(z2);
xlabel('t');
ylabel('z2(t)');title('autocorrelation');
Result: Auto correlation and Cross correlation between signals and sequences is
computed.
Output:
Enter input sequence [1 2 5 7]
Enter the impulse sequence [2 6 0 5 3]
Output:
ExperimentNo-6
Verification of Linearity of a Discrete System
AIM: Verify the Linearity of a given Discrete System.
Software Required: Matlab software7.0
Program:
%Verification of Linearity of a given System.
clc;
clearall;
close all;
n=0:40;
a1=input('enterthescalingfactora1=');
a2=input('enterthescalingfactora2=');
x1=cos(2*pi*0.1*n);
x2=cos(2*pi*0.4*n);
x3=a1*x1+a2*x2;
% y(n)=n.x(n);
y1=n.*x1;
y2=n.*x2;
y3=n.*x3;
yt=a1*y1+a2*y2;
yt=round(yt);
y3=round(y3);
if y3==yt;
disp('givensystem[y(n)=n.x(n)]isLinear'); else
disp('givensystem[y(n)=n.x(n)]isnonLinear');
end
% y(n)=x(n).^2
x1=[1 2 3 4 5];
x2=[1 4 7 6 4];
x3=a1*x1+a2*x2;
y1=x1.^2;
y2=x2.^2;
y3=x3.^2;
yt=a1*y1+a2*y2;
if y3==yt;
disp('givensystem[y(n)=x(n).^2]isLinear'); else
disp('givensystemis[y(n)=x(n).^2]nonLinear');
end
Result:
The Linearity of a given Discrete System is verified.
Output:
Enter the scaling factora 1=3
Enter the scaling factora 2=5
Given system [y(n)=n.x(n)] is Linear
Given system is [y(n)=x(n).^2] non Linear
ExperimentNo-7
Verification of Time Invariance of a Discrete System
AIM: Verify the Time Invariance of a given Discrete System.
Software Required: Matlab software
Program:
% Verification of Time Invariance of a DiscreteSystem
% a)y=x^2(n) b)y(n)=nx(n)
clc;
clearall;
closeall;
n=1:9;
x(n)=[1 2 3 4 5 6 7 8 9];
d=3;
xd=[zeros(1,d),x(n)];
y(n)=x(n).^2;
yd=[zeros(1,d),y];
disp('transformationofdelaysignalyd:');
disp(yd) dy=xd.^2;
disp('delayoftransformationsignaldy:');
disp(dy);
if dy==yd;
disp('givensystem[y(n)=x(n).^2]istimeinvariant'); else
disp('givensystemis[y(n)=x(n).^2]nottimeinvariant');
end
y=n.*x;
yd=[zeros(1,d),y(n)];
disp('transformationofdelaysignalyd:');
disp(yd);
n1=1:length(xd);
dy=n1.*xd;
disp('delayoftransformationsignaldy:');
disp(dy);
if yd==dy;
disp('givensystem[y(n)=nx(n)]isatime invariant'); else
disp('givensystem[y(n)=nx(n)]notatimeinvariant');
end
Result:
The Time Invariance of a given Discrete System is verified.
Output:
Transformation of delay signal yd:
0 0 0 1 4 9 16 25 36 49 64 81
Delay of transformation signal dy:
0 0 0 1 4 9 16 25 36 49 64 81
Given system [y(n)=x(n).^2] is time invariant transformation of delay signal yd:
0 0 0 1 4 9 16 25 36 49 64 81
Delay of transformation signal dy:
0 0 0 4 10 18 28 40 54 70 88 108
Given system [y(n)=nx(n)] not a time invariant
ExperimentNo-8
Finding the Fourier Transform of a given signal and plotting its magnitude and
phase spectrum
AIM: To find the Fourier Transform of a given signal and plotting its magnitude and
phase spectrum.
Software Required: Matlab software
Program:
clc;
clearall;
close all;
fs=1000;
N=1024;
t=[0:N-1]*(1/fs);
% input signal
x=0.8*cos(2*pi*100*t);
subplot(3,1,1);
plot(t,x);
axis([0 0.05 -1 1]);
grid;
xlabel('t');
ylabel('amplitude');
title('inputsignal');
% Fourier transform of given signal
x1=fft(x);
% magnitude spectrum
k=0:N-1;
Xmag=abs(x1);
subplot(3,1,2);
plot(k,Xmag);
grid;
xlabel('t');
ylabel('amplitude');
title('magnitudeoffftsignal');
%phase spectrum
Xphase=angle(x1);
subplot(3,1,3);
plot(k,Xphase);
grid;
xlabel('t');
ylabel('angle');
title('phaseoffftsignal');
Result: Magnitude and phase spectrum of FFT of a given signal is plotted.
Output:
Experiment No-9
Waveform Synthesis Using Laplace transforms
AIM: Finding the Laplace transform & Inverse Laplace transform of some signals.
Software Required: Matlab software
Program:
clc;
clearall;
close all;
% representation of symbolic variables
syms f t w s;
% laplace transform of t
f=t;
z=laplace(f);
disp('thelaplacetransformoff=');
disp(z);
% laplacetransformofasignal
%f1=sin(w*t);
f1=-1.25+3.5*t*exp(-2*t)+1.25*exp(-2*t);
v=laplace(f1);
disp('thelaplace transformoff1= ');
disp(v);
lv=simplify(v);
pretty(lv)
% inverse laplace transform
y1=ilaplace(z);
disp('theinverse laplacetransform of z=');
disp(y1);
y2=ilaplace(v);
disp('theinverse laplacetransform of v=');
disp(y2);
ezplot(y1);
figure;
ezplot(y2);
Output:
The laplace transform of f= 1/s^2
The laplace transform of f1= 5/(4*(s+2))+7/(2*(s+2)^2) -5/(4*s) s - 5s(s+2)2
The inverse laplace transform of z= t
The inverse laplace transform of v = 5/(4*exp(2*t))+(7*t)/(2*exp(2*t))-5/4
Output:
Experiment No-10
Sampling theorem verification
AIM: Verify the sampling theorem.
Software Required: Matlab software
Program:
clc;
clearall;
close all;
t=-10:.01:10;
T=4;
fm=1/T;
x=cos(2*pi*fm*t);
subplot(2,2,1);
plot(t,x);
xlabel('time');
ylabel('x(t)');
title('continoustimesignal');
grid;
n1=-4:1:4;
fs1=1.6*fm;
fs2=2*fm;
fs3=8*fm;
x1=cos(2*pi*fm/fs1*n1);
subplot(2,2,2);
stem(n1,x1);
xlabel('time');
ylabel('x(n)');
title('discretetimesignalwithfs<2fm');
hold on;
subplot(2,2,2);
plot(n1,x1);
grid;
n2=-5:1:5;
x2=cos(2*pi*fm/fs2*n2);
subplot(2,2,3);
stem(n2,x2);
xlabel('time');
ylabel('x(n)');
title('discretetimesignalwithfs=2fm');
hold on;
subplot(2,2,3);
plot(n2,x2);
grid;
n3=-20:1:20;
x3=cos(2*pi*fm/fs3*n3); subplot(2,2,4);
stem(n3,x3);
xlabel('time');
ylabel('x(n)');
title('discretetimesignalwithfs>2fm') hold on;
subplot(2,2,4);
plot(n3,x3) grid;
Result: Sampling theorem is verified.
OUTPUT: