0% found this document useful (0 votes)
195 views23 pages

Basic Simulation: Laboratory Manual

The document describes generating various periodic and aperiodic signals and sequences using MATLAB. It defines signals like unit impulse, unit step, ramp, square, sawtooth, triangular, sinusoidal and sinc. Code is provided to generate these signals and plot them as both continuous-time and discrete-time sequences. Signals generated include unit impulse, unit step, square wave, sawtooth wave, triangular wave, sinusoidal wave and ramp. The plots show the signals versus time and their sequences versus sample number.

Uploaded by

ranjith
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
195 views23 pages

Basic Simulation: Laboratory Manual

The document describes generating various periodic and aperiodic signals and sequences using MATLAB. It defines signals like unit impulse, unit step, ramp, square, sawtooth, triangular, sinusoidal and sinc. Code is provided to generate these signals and plot them as both continuous-time and discrete-time sequences. Signals generated include unit impulse, unit step, square wave, sawtooth wave, triangular wave, sinusoidal wave and ramp. The plots show the signals versus time and their sequences versus sample number.

Uploaded by

ranjith
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 23

BASIC SIMULATION

LABORATORY MANUAL

II – I SEMESTER
Department of ECE BS LAB MANUAL

CONTENTS
S.No Experiment Name Pg.No

1. Basic Operations on Matrices. 1

2. Generation of Various Signals and Sequences (Periodic and Aperiodic), such as 5


Unit Impulse, Unit Step, Square, Saw tooth, Triangular, Sinusoidal, Ramp, Sinc.

3. Operations on Signals and Sequences such as Addition, Multiplication, 12


Scaling, Shifting, Folding, Computation of Energy and Average Power

4. Finding the Even and Odd parts of Signal/Sequence and Real and Imaginary 20
parts of Signal

5. Convolution between Signals and sequences 25

6. Auto Correlation and Cross Correlation between Signals and Sequences 29

7. Verification of Linearity and Time Invariance Properties of a given 33


Continuous/Discrete System.

8. Computation of Unit sample, Unit step and Sinusoidal responses of the 37


given LTI system and verifying its physical realiazability and stability
properties.

9. Gibbs Phenomenon 40

10 Finding the Fourier Transform of a given signal and plotting its magnitude and 42
phase spectrum

11 Waveform Synthesis using Laplace Transform. 45

12 Locating the Zeros and Poles and plotting the Pole-Zero maps in S-plane and Z- 49
Plane for the given transfer function.

13 Generation of Gaussian noise (Real and Complex), Computation of its mean, 53


M.S. Value and its Skew, Kurtosis, and PSD, Probability Distribution Function

14 Sampling Theorem Verification. 55

15 Removal of noise by Autocorrelation / Cross correlation 58

16 Extraction of Periodic Signal masked by noise using Correlation. 62

17 Verification of Weiner-Khinchine Relations. 66

18 Checking a Random Process for Stationarity in Wide sence 70




Experiment No-1

BASIC OPERATIONS ON MATRICES


AIM: Generate a matrix and perform basic operation on matrices using MATLAB software.
Software Required: MATLAB software
Theory:
MATLAB treats all variables as matrices. Vectors are special forms of matrices and contain
only one row or one column. Whereas scalars are special forms of matrices and contain only
one row and one column. A matrix with one row is called row vector and a matrix with
single column is called column vector.
The first one consists of convenient matrix building functions, some of which are
given below.
1. eye - identity matrix
2. zeros - matrix of zeros
3. ones - matrix of ones
4. diag - extract diagonal of a matrix or create diagonal matrices
5. triu - upper triangular part of a matrix
6. tril - lower triangular part of a matrix
7. rand - ran
commands in the second sub-category of matrix functions are
1. size- size of a matrix
2. det -determinant of a square matrix
3. inv- inverse of a matrix
4. rank- rank of a matrix
5. rref- reduced row echelon form
6. eig- eigen values and eigenvectors
7. poly- characteristic polynomialdomly generated matrix
Program:
% Creating a column
vector >> a=[1;2;3]
a=
1
2
3

% Creating a row vector


>> b=[1 2 3]
b=
123
% Creating a matrix
 m=[1 2 3;4 6 9;2 6 9]
m=
123
469
269
% Extracting sub matrix from matrix
>> sub_m=m(2:3,2:3)
sub_m =
69
69
% Extracting column vector from matrix
>> c=m (:,2)
c=
2
6
6
% Extracting row vector from
matrix >> d=m (3,:)
d=
269
% creation of two matrices a and b
>> a=[2 4 -1;-2 1 9;-1 -1 0]
a=
2 4 -1
-2 1 9
-1 -1 0
>> b=[0 2 3;1 0 2;1 4 6]
b=
023
102
146
% matrix multiplication
>> x1=a*b
x1 =
3 0 8
10 32 50
-1 -2 -5
% element to element multiplication
>> x2=a.*b
x2 =
0 8 -3
-2 0 18
-1 -4 0
% matrix addition
>> x3=a+b
x3 =
262
-1 1 11
036
% matrix subtraction
>> x4=a-b
x4 =
2 2 -4
-3 1 7
-2 -5 -6
% matrix division
>> x5=a/b
x5 =
-9.0000 -3.5000 5.5000
12.0000 3.7500 -5.7500
3.0000 0.7500 -1.7500
% element to element division
>> x6=a./b
Warning: Divide by zero.
x6 =
Inf 2.0000 -0.3333
-2.0000 Inf 4.5000
-1.0000 -0.2500 0
% inverse of matrix a
>> x7=inv(a)
x7 =
-0.4286 -0.0476 -1.7619
0.4286 0.0476 0.7619 -
0.1429 0.0952 -0.4762
% transpose of matrix a
>> x8=a'
x8 =
2 -2 -1
4 1 -1
-1 9 0

RESULT: Matrix operations are performed using Matlab software.


Experiment No-2
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
Theory: If the amplitude of the signal is defined at every instant of time then it is called
continuous time signal. If the amplitude of the signal is defined at only at some instants of
time then it is called discrete time signal. If the signal repeats itself at regular intervals then it
is called periodic signal. Otherwise they are called aperiodic signals.
EX: ramp,Impulse,unit step, sinc- Aperiodic signals
square,sawtooth,triangular sinusoidal – periodic signals.

Ramp sinal: The ramp function is a unitary real function, easily computable as the mean of
the independent variable and its absolute value.This function is applied in engineering. The
name ramp function is derived from the appearance of its graph.
t when

r(t)=
0 else

Unit impulse signal: One of the more useful functions in the study of linear systems is the
"unit impulse function."An ideal impulse function is a function that is zero everywhere but
at the origin, where it isinfinitely high. However, the area of the impulse is finite
Y(t)= 1 when t=0
=0 other wise
Unit step signal: The unit step function and the impulse function are considered to be
fundamental functions in engineering, and it is strongly recommended that the reader
becomes very familiar with both of these functions.
0 if t < 0
u(t)= 1 if t > 0
If t=0

Sinc signal: There is a particular form that appears so frequently in communications


engineering, that we give it its own name. This function is called the "Sinc function”.
The Sinc function is defined in the following manner:
if and sinc(0) =1
The value of sinc(x) is defined as 1 at x = 0, since
PROCEDURE:-

Open MATLAB


Open new M-file


Type the program


Save in current directory


Compile and Run the program


For the output see command window\ Figure window

PROGRAM:

%Generation of signals and sequences %


clc;
clear all;
close all;
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
%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('square wave signal');
%generation of square wave sequence
subplot(2,2,2);
stem(t,y3);
axis([0 0.1 -2 2]);
xlabel('n');
ylabel('amplitude');
title('square wave sequence');

%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

%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('sawtooth wave signal');
%generation of sawtooth sequence
subplot(2,2,4);
stem(t,y4);
axis([0 0.1 -2 2]);
xlabel('n');
ylabel('amplitude');
title('sawtooth wave sequence');
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

%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(' triangular wave signal');
%generation of triangular wave sequence
subplot(2,2,2);
stem(t,y5);
axis([0 0.1 -2 2]);
xlabel('n');
ylabel('amplitude');
title('triangular wave sequence');
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
%generation of sinsoidal 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(' sinsoidal wave signal');
%generation of sin wave sequence
subplot(2,2,4);
stem(t,y6);
axis([0 0.1 -2 2]);
xlabel('n');
ylabel('amplitude');
title('sin wave sequence');
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

%generation of ramp signal


y7=t;
figure;
subplot(2,2,1);
plot(t,y7);
xlabel('time');
ylabel('amplitude');
title('ramp signal');
%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(' sinc signal');
%generation of sinc sequence
subplot(2,2,4);
stem(y8);
xlabel('n');
ylabel('amplitude');
title('sinc sequence');

Result: Various signals & sequences generated using Matlab software.


output:
Experiment No-3
Basic Operations on Signals and sequences
AIM: perform the operations on signals and sequences such as addition, multiplication,
scaling, shifting, folding and also compute energy and power.
Software Required: Matlab software.

Theory:
Signal Addition
Addition: any two signals can be added to form a third signal,
z (t) = x (t) + y (t)

Multiplication :

Multiplication of two signals can be obtained by multiplying their values at every instants.
z(t) = x (t) y (t)

Time reversal/Folding:

Time reversal of a signal x(t) can be obtained by folding the signal about t=0.
Y(t)=y(-t)
Signal Amplification/Scaling : Y(n)=ax(n) if a < 1 attnuation
a >1 amplification

Time shifting: The time shifting of x(n) obtained by delay or advance the signal in time by
using y(n)=x(n+k)
If k is a positive number, y(n) shifted to the right i e the shifting delays the signal
If k is a negative number, y(n ) it gets shifted left. Signal Shifting advances the signal
Energy:
E=sum(abs(x).^2)

Average power:
P=(sum(abs(x).^2))/length(x)

Program:
clc;
clear all;
close all;
%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('input signal 1');
subplot(2,2,2);
plot(t,x2);
xlabel('time');
ylabel('amplitude');
title('input signal 2');

%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('input signal')
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('input signal')
y4=fliplr(x1); nf=-
fliplr(nx);
subplot(2,2,4);
plot(nf,y4);
xlabel('nf');
ylabel('amplitude');
title('folded signal');

%shifting of a signal 1
figure;
subplot(3,1,1);
plot(t,x1);
xlabel('time t');
ylabel('amplitude');
title('input signal');
subplot(3,1,2);
plot(t+2,x1);
xlabel('t+2');
ylabel('amplitude');
title('right shifted signal');
subplot(3,1,3);
plot(t-2,x1);
xlabel('t-2');
ylabel('amplitude');
title('left shifted signal');
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

13
Dept. of ECE, MRCET BS LAB MANUAL

%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('sum of two
sequences');

% multiplication of sequences
s4=s1.*s2;
subplot(2,2,4);
stem(n1,s4);
xlabel('n1');
ylabel('amplitude');
title('product of two sequences');
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

% program for energy of a sequence


z1=input('enter the input sequence');
e1=sum(abs(z1).^2);
disp('energy of given sequence is');e1

% program for energy of a


signal t=0:pi:10*pi;
z2=cos(2*pi*50*t).^2;
e2=sum(abs(z2).^2);
disp('energy of given signal is');e2

% program for power of a sequence p1=


(sum(abs(z1).^2))/length(z1);
disp('power of given sequence is');p1

% program for power of a signal


p2=(sum(abs(z2).^2))/length(z2);
disp('power of given signal is');p2

14
Dept. of ECE, MRCET BS LAB MANUAL

OUTPUT:
enter the input sequence[1 3 2 4 1]
energy of given sequence is
e1 = 31
energy of given signal is

e2 = 4.0388
power of given sequence is
p1 = 6.2000
power of given signal is
p2 = 0.3672

Result: Various operations on signals and sequences are performed.


Output:

16
Dept. of ECE, MRCET BS LAB MANUAL

You might also like