Experiment No-1 Basic Operations On Matrices
Experiment No-1 Basic Operations On Matrices
Experiment No-1
BRIL,ECE Page 1
Basic Simulation Lab
% 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
BRIL,ECE Page 2
Basic Simulation Lab
% 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.
BRIL,ECE Page 3
Basic Simulation Lab
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
%cube of matrix a( power of the matrix)
>> x9=a^3
x9 =
-66 -33 120
-9 -87 -129
18 3 -45
x10 =
8 64 -1
-8 1 729
-1 -1 0
BRIL,ECE Page 4
Basic Simulation Lab
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
BRIL,ECE Page 5
Basic Simulation Lab
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:
BRIL,ECE Page 6
Basic Simulation Lab
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
BRIL,ECE Page 7
Basic Simulation Lab
BRIL,ECE Page 8
Basic Simulation Lab
output:
BRIL,ECE Page 9
Basic Simulation Lab
BRIL,ECE Page 10
Basic Simulation Lab
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
BRIL,ECE Page 11
Basic Simulation Lab
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');
BRIL,ECE Page 12
Basic Simulation Lab
%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');
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
BRIL,ECE Page 13
Basic Simulation Lab
%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');
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
BRIL,ECE Page 14
Basic Simulation Lab
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
BRIL,ECE Page 15
Basic Simulation Lab
BRIL,ECE Page 16
Basic Simulation Lab
BRIL,ECE Page 17
Basic Simulation Lab
Experiment No-4
Even and odd parts of signal and sequence & Real and imaginary parts
AIM: Finding even and odd part of the signal and sequence and also find real and imaginary
parts of signal.
Theory: One of characteristics of signal is symmetry that may be useful for signal analysis.
Even signals are symmetric around vertical axis, and Odd signals are symmetric about origin.
Using the definition of even and odd signal, any signal may be decomposed into a sum
of its even part, xe(t), and its odd part, xo(t), as follows
Even and odd part of a signal: Any signal x(t) can be expressed as sum of even and odd
components I e
X(t)=xe(t)+xo(t)
Program:
%%even add odd parts of signals
clc;
close all;
clear all;
t=0:0.001:10;
x1=sin(t)+cos(t);
subplot(2,2,1);
plot(t,x1);
grid;
xlabel('time');
ylabel('amplitude');
title('first signal');
BRIL,ECE Page 18
Basic Simulation Lab
x2=sin(-t)+cos(-t);
subplot(2,2,2);
plot(t,x2);
grid;
xlabel('time');
ylabel('amplitude');
title('second signal');
xe=1/2*(x1+x2);
subplot(2,2,3);
plot(t,xe);
grid;
xlabel('time');
ylabel('amplitude');
title('even part of the signal');
xo=1/2*(x1-x2);
subplot(2,2,4);
plot(t,xo);
grid;
xlabel('time');
ylabel('amplitude');
title('odd part of the signal');
BRIL,ECE Page 19
Basic Simulation Lab
RESULT: Even and odd part of the signal and sequence, real and imaginary parts of
signal are computed.
BRIL,ECE Page 20
Basic Simulation Lab
BRIL,ECE Page 21
Basic Simulation Lab
BRIL,ECE Page 22
Basic Simulation Lab
Experiment No-5
Convolution between signals& sequences
Aim: Write the program for convolution between two signals and also between two
sequences.
Theory:
y(n)=T[x(n)]
BRIL,ECE Page 23
Basic Simulation Lab
Program:
%Convolution of signals
clc;
close all;
clear all;
t=-10:0.001:10;
x1=sin(t);
subplot(3,1,1);
plot(t,x1);
grid;
xlabel('time');
ylabel('amplitude');
title('input signal');
x2=cos(t);
subplot(3,1,2);
plot(t,x2);
grid;
xlabel('time');
ylabel('amplitude');
title('impulse signal ');
y=conv2(x1,x2);
subplot(3,1,3);
plot(y);
grid;
xlabel('time');
ylabel('amplitude');
title('convolution of signal');
%Convolution of sequences
clc;
close all;
clear all;
x=[2 3 4];
h=[5 6 7];
y=conv2(x,h);
subplot(3,1,1);
stem(x);
grid;
xlabel('n');
ylabel('x(n)');
title('input sequence');
BRIL,ECE Page 24
Basic Simulation Lab
subplot(3,1,2);
stem(h);
grid;
xlabel('n');
ylabel('h(n)');
title('impulse sequence ');
subplot(3,1,3);
stem(y);
grid;
xlabel('n');
ylabel('y(n)');
title('convolution sequence');
display('the convolution sequence is:');
display(y);
Output:
BRIL,ECE Page 25
Basic Simulation Lab
BRIL,ECE Page 26
Basic Simulation Lab
Experiment No-6
Auto correlation and Cross correlation
Aim: To compute Auto correlation and Cross correlation between signals and sequences.
Correlations of sequences:
It is a measure of the degree to which two sequences are similar. Given two real-valued
sequences x(n) and y(n) of finite energy,
1. Shifting
2. Multiplication
3. Addition
These operations can be represented by a Mathematical Expression as follows:
Cross correlation +∞
Autocorrelation
+∞
BRIL,ECE Page 27
Basic Simulation Lab
Program:
BRIL,ECE Page 28
Basic Simulation Lab
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]
BRIL,ECE Page 29
Basic Simulation Lab
BRIL,ECE Page 30
Basic Simulation Lab
BRIL,ECE Page 31
Basic Simulation Lab
Software Required:
Mat lab software 7.0 and above
Theory:
LINEARITY PROPERTY:
Any system is said to be linear if it satisfies the superposition principal. superposition
principal state that Response to a weighted sum of input signal equal to the
corresponding weighted sum of the outputs of the system to each of the individual input
signals.
X(n)-----------input signal
Y(n) --------- output signal
Y(n)=T[x(n)]
Y1(n)=T[X1(n)] : Y2(n)=T[X2(n)]
Y3(n)= T [x3(n)]
BRIL,ECE Page 32
Basic Simulation Lab
Program:
clc;
clear all;
close all;
%entering two input sequences and impulse sequence
x1 = input ('type the samples of x1');
x2 = input ('type the samples of x2');
if(length(x1)~=length(x2))
disp('error: Lengths of x1 and x2 are different');
return;
end;
h = input ('type the samples of h');
%length of output sequence
N = length(x1)+length(h)-1;
disp('length of the output signal will be'); disp(N);
%entering scaling factors
a1 = input ('The scale factor a1 is');
a2 = input ('The scale factor a2 is');
x= a1*x1 + a2*x2;
%response of x and x1
y = conv(x,h);
y1 = conv(x1,h);
%scaled response of response of x2
y11 = a1 * y1;
y2 = conv(x2,h);
%scaled response of
y22 = a2*y2;
y33 = y11 + y22;
disp ('Input signal x1 is');
disp(x1);
disp ('Input signal x2 is');
disp(x2);
disp ('Output Sequence y1 is '); disp(y1);
disp ('Output Sequence y33 is '); disp(y33);
if ( y1 == y33 )
disp(' y1 = y33. Hence the LTI system is LINEAR ');
end;
BRIL,ECE Page 33
Basic Simulation Lab
Output:
Input signal x2 is
2 3 4 8
Output Sequence y is
16 86 202 347 424 286 152
BRIL,ECE Page 34
Basic Simulation Lab
Software Required:
Mat lab software 7.0 and above
Theory:
A system is called time invariant if its input – output characteristics do not change
with time
Program:
clc;
clear all;
close all;
%entering two input sequences%
x = input('Type the samples of
signal x(n)');
h = input('Type the samples of
signal h(n)');
%original response%
y = conv(x,h);
display('Enter a POSITIVE
number for delay');
%disp(or)display
d = input('Desired delay of the
signal is');
%delayed input
xd = [zeros(1,d), x];
nxd = 0 : length(xd)-1;
BRIL,ECE Page 35
Basic Simulation Lab
%delayed output%
yd = conv(xd,h);
nyd = 0:length(yd)-1;
disp('Original Input Signal x(n) is');disp(x);
disp('Delayed Input Signal xd(n) is');disp(xd);
%disp(or)display
disp('Original Output Signal y(n) is');disp(y);
disp('Delayed Output Signal yd(n) is');disp(yd);
xp = [x ,zeros(1,d)];
subplot(2,1,1);
stem(nxd,xp);
grid;
xlabel( 'Time Index n' );
ylabel( 'x(n)' );
title( 'Original Input Signal x(n)' );
subplot(2,1,2);
stem(nxd,xd);
grid;
xlabel( 'Time Index n');
ylabel( 'xd(n)' );
title( 'Delayed Input Signal xd(n)');
yp = [y ,zeros(1,d)];
figure;
subplot(2,1,1);
stem(nyd,yp);
grid;
xlabel('Time Index n');
ylabel('y(n)');
title('Original Output Signal y(n)');
subplot(2,1,2);
stem(nyd,yd);
grid;
xlabel('Time Index n');
ylabel('yd(n)');
title('Delayed Output Signal yd(n)');
BRIL,ECE Page 36
Basic Simulation Lab
Output:
BRIL,ECE Page 37
Basic Simulation Lab
BRIL,ECE Page 38
Basic Simulation Lab
BRIL,ECE Page 39
Basic Simulation Lab
Experiment No. -8
UNIT SAMPLE, UNIT STEP AND SINUSOIDAL RESPONSE OF THE
GIVEN LTI SYSTEM AND VERIFYING ITS STABILITY
AIM: Compute the Unit sample, unit step and sinusoidal response of the given LTI
system and verifying its stability
Software Required:
Mat lab software 7.0 and above
Theory:
A discrete time system performs an operation on an input signal based on predefined
criteria to produce a modified output signal. The input signal x(n) is the system
excitation, and y(n) is the system response. The transform operation is shown as,
If the input to the system is unit impulse i.e. x(n) = δ(n) then the output of the system
is known as impulse response denoted by h(n) where,
h(n) = T[δ(n)]
we know that any arbitrary sequence x(n) can be represented as a weighted sum of
discrete impulses. Now the system response is given by,
BRIL,ECE Page 40
Basic Simulation Lab
Program:
Result: The Unit sample, unit step and sinusoidal response of the given LTI system is
computed and its stability verified.
Hence all the poles lie inside the unit circle, so system is stable.
BRIL,ECE Page 41
Basic Simulation Lab
Output:
BRIL,ECE Page 42
Basic Simulation Lab
BRIL,ECE Page 43
Basic Simulation Lab
Experiment No-9
GIBBS PHENOMENON
Theory:
The Gibbs phenomenon, the Fourier series of a piecewise continuously
differentiable periodic function behaves at a jump discontinuity. Then the approximated
function shows amounts of ripples at the points of discontinuity. This is known as the
Gibbs Phenomena . partial sum of the Fourier series has large oscillations near the jump,
which might increase the maximum of the partial sum above that of the function itself.
The overshoot does not die out as the frequency increases, but approaches a finite limit
The Gibbs phenomenon involves both the fact that Fourier sums overshoot at a jump
discontinuity, and that this overshoot does not die out as the frequency increases.
Program:
clc;
clear all;
close all;
t=0:0.1:(pi*8);
y=sin(t);
subplot(5,1,1);
plot(t,y);
xlabel('k');
ylabel('amplitude');
title('gibbs phenomenon');
h=2;
k=3;
for k=3:2:9
%Fourier series of sin signal
y=y+sin(k*t)/k;
subplot(5,1,h);
plot(t,y);
xlabel('k');
ylabel('amplitude');
h=h+1;
end
BRIL,ECE Page 44
Basic Simulation Lab
Output:
BRIL,ECE Page 45
Basic Simulation Lab
Experiment No-10
AIM: To find the Fourier Transform of a given signal and plotting its magnitude and
phase spectrum.
Software Required:
Matlab software
Theory:
Fourier Transform :
The Fourier transform as follows. Suppose that ƒ is a function which is zero outside of
some interval [−L/2, L/2]. Then for any T ≥ L we may expand ƒ in
a Fourier series on the interval [−T/2,T/2], where the "amount" of the wave e2πinx/T in the
Fourier series of ƒ is given by
By definition Fourier Transform of signal f(t) is defined as
Program:
clc;
clear all;
close all;
fs=1000;
N=1024;
%length of fft sequence
t=[0:N-1]*(1/fs);
BRIL,ECE Page 46
Basic Simulation Lab
%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('input signal');
%magnitude spectrum
x1=fft(x);
k=0:N-1;
Xmag=abs(x1);
subplot(3,1,2);
plot(k,Xmag);
grid;
xlabel('t');
ylabel('amplitude');
title('magnitude of fft signal') ;
%phase spectrum
Xphase=angle(x1)*(180/pi);
subplot(3,1,3);
plot(k,Xphase);
grid;
xlabel('t');
ylabel('angleindegrees');
title('phase of fft signal');
BRIL,ECE Page 47
Basic Simulation Lab
Output:
BRIL,ECE Page 48
Basic Simulation Lab
Experiment No-11(a)
LAPLACE TRANSFORM & INVERSE LAPLACE TRANSFORM
AIM: Finding the Laplace transform & Inverse Laplace transform of some signals.
Software Required:
Matlab software
Theory:
Program:
clc;
clear all;
close all;
%representation of symbolic variables
syms f t w s;
%laplace transform of t
f=t;
z=laplace(f);
disp('the laplace transform of f = ');
disp(z);
BRIL,ECE Page 49
Basic Simulation Lab
Result: The Laplace transform & Inverse Laplace transform of signals by using matlab
software is verified.
BRIL,ECE Page 50
Basic Simulation Lab
Output:
ans =
BRIL,ECE Page 51
Basic Simulation Lab
Experiment No-11(b)
WAVEFORM SYNTHESIS USING LAPLACE TRANSFORMS
AIM: Perform the waveform synthesis using Laplace transform of a given signal.
Software Required:
Matlab software
Theory:
Consider the square wave of period ‘T’which can be represented with unit
step functions as
f(t)=u(t)-2u(t-T/2)+2u(t-T)-2u(t-3T/2)+………..
Program:
clc;
clear all;
close all;
syms s;
T=1;
%representation of laplace transform
F1=1-exp(-T*s/2);
F2=s*(1+exp(-T*s/2));
F=F1/F2;
%inverse laplace transform
f=ilaplace(F);
disp('inverse laplace transform of F=');
disp(f);
%easy plot for 'f'
ezplot(f);
Result: The waveform synthesis using Laplace transform of a given signal is plotted.
BRIL,ECE Page 52
Basic Simulation Lab
Output:
BRIL,ECE Page 53
Basic Simulation Lab
Experiment No-12
LOCATING POLES AND ZEROS IN S-PLANE & Z-PLANE
AIM: Write the program for locating poles and zeros and plotting pole-zero maps in s-
plane and z-plane for the given transfer function.
Software Required:
Matlab software
Theory:
Z-transforms
The Z -transform, like many other integral transforms, can be defined as either a
one-sided or two-sided transform.
Bilateral Z-transform
The bilateral or two-sided Z-transform of a discrete-time signal x[n] is the function
X(z) defined as
Unilateral Z-transform
Alternatively, in cases where x[n] is defined only for n ≥ 0, the single-sided or
unilateral Z-transform is defined as
BRIL,ECE Page 54
Basic Simulation Lab
Example:
Program:
clc;
clear all;
close all;
%enter the numerator and denamenator cofficients in square brackets
num=input('enter the numerator cofficients');
den=input('enter the denamenator cofficients');
%find the transfer function using built-in function 'filt'
H=filt(num,den);
%find locations of zeros
z=zero(H);
disp('zeros are at');
disp(z);
%find residues,pole locations and gain constant of H(z)
[r p k]=residuez(num,den);
disp('poles are at');
disp(p);
%plot the pole zero map in z-plane
zplane(num,den);
title('pole-zero map of LTI system in z-plane');
% ploe-zero plot in s-plane
H1=tf(num,den); % find transfer function H(s)%
[p1,z1]=pzmap(H1); % find the locations of poles and zeros%
disp('poles ar at ');
disp(p1);
disp('zeros ar at ');
disp(z1);
figure;
%plot the pole-zero map in s-plane
pzmap(H1);
disp(H1);
title('pole-zero map of LTI system in s-plane');
Result :Pole-zero maps are plotted in s-plane and z-plane for the given transfer
function.
BRIL,ECE Page 55
Basic Simulation Lab
Output:
Transfer function:
1 - z^-1 + 4 z^-2 + 3.5 z^-3
------------------------------
2 + 3 z^-1 - 2.5 z^-2 + 6 z^-3
zeros are at
0.8402 + 2.1065i
0.8402 - 2.1065i
-0.6805
poles are at
-2.4874
0.4937 + 0.9810i
0.4937 - 0.9810i
Transfer function:
s^3 - s^2 + 4 s + 3.5
-------------------------
2 s^3 + 3 s^2 - 2.5 s + 6
poles ar at
-2.4874
0.4937 + 0.9810i
0.4937 - 0.9810i
zeros ar at
0.8402 + 2.1065i
0.8402 - 2.1065i
-0.6805
BRIL,ECE Page 56
Basic Simulation Lab
BRIL,ECE Page 57
Basic Simulation Lab
BRIL,ECE Page 58
Basic Simulation Lab
Experiment No-13
GENERATION OF GAUSSIAN NOISE
AIM: Write the program for generation of Gaussian noise and computation of its mean,
mean square value, skew, kurtosis and probability distribution function.
Software Required:
Matlab software
Theory:
Program:
clc;
clear all;
close all;
%generates first set of 2000 samples of Gaussian distributed
random numbers%
x1=randn(1,2000);
%generates second set of 2000 samples of Gaussian distributed
random numbers%
x2=randn(1,2000);
%plot the joint distribution of both the sets using dot%
plot(x1,x2,'.');
title('scatter plot of gaussian distributed random numbers');
%generates two sets of 2000 samples of uniform distributed
random numbers%
x3=rand(1,2000);
x4=rand(1,2000);
figure;
plot(x3,x4,'.');
title('scatter plot of uniform distributed random numbers');
figure;
subplot(2,1,1);
%plot the histogram graph of x2
hist(x2);
title('gaussian distribution');
subplot(2,1,2);
%plot the histogram graph of x4
hist(x4);
title('uniform distribution');
ymu=mean(x2);disp('ymu');
ymsq=sum(x2.^2)/length(x2);
ysigma=std(x2);
yvar=var(x2);
yskew=skewness(x2);
ykurt=kurtosis(x2);
BRIL,ECE Page 59
Basic Simulation Lab
Output:
ymu =
0.0172
ymsq =
0.9528
ysigma =
0.9762
yvar =
0.9530
yskew =
-0.0041
ykurt =
2.9381
BRIL,ECE Page 60
Basic Simulation Lab
BRIL,ECE Page 61
Basic Simulation Lab
BRIL,ECE Page 62
Basic Simulation Lab
BRIL,ECE Page 63
Basic Simulation Lab
Experiment No-14
SAMPLING THEOREM VERIFICATION
Software Required:
Matlab software
Theory:
Sampling Theorem:
A bandlimited signal can be reconstructed exactly if it is sampled at a rate atleast
twice the maximum frequency component in it." Figure 1 shows a signal g(t) that is
bandlimited.
The maximum frequency component of g(t) is fm. To recover the signal g(t) exactly
from its samples it has to be sampled at a rate fs ≥ 2fm.
The minimum required sampling rate fs = 2fm is called ' Nyquist rate
BRIL,ECE Page 64
Basic Simulation Lab
BRIL,ECE Page 65
Basic Simulation Lab
Aliasing leads to distortion in recovered signal. This is the reason why sampling frequency
should be at least twice the bandwidth of the signal.
BRIL,ECE Page 66
Basic Simulation Lab
Program:
clc;
clear all;
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('continous time signal');
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('discrete time signal with fs<2fm');
hold on;
subplot(2,2,2);
plot(n1,x1);
grid;
BRIL,ECE Page 67
Basic Simulation Lab
n2=-5:1:5;
x2=cos(2*pi*fm/fs2*n2);
subplot(2,2,3);
stem(n2,x2);
xlabel('time');
ylabel('x(n)');
title('discrete time signal with fs=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('discrete time signal with fs>2fm')
hold on;
subplot(2,2,4);
plot(n3,x3)
grid;
BRIL,ECE Page 68
Basic Simulation Lab
OUTPUT:
BRIL,ECE Page 69
Basic Simulation Lab
Experiment No-15
REMOVAL OF NOISE BY AUTO CORRELATION/CROSS
CORRELATION
AIM: Write the program for Removal of noise by using auto correlation.
Software Required:
Matlab software
Theory:
Detection of a periodic signal masked by random noise is of great importance .The
noise signal encountered in practice is a signal with random amplitude variations. A
signal is uncorrelated with any periodic signal. If s(t) is a periodic signal and n(t) is a
noise signal then
T/2
Lim 1/T ∫ S(t)n(t-T) dt=0 for all T
T--∞ -T/2
Qsn(T)= cross correlation function of s(t) and n(t) Then Qsn(T)=0
T/2
Qff(T)= Lim 1/T ∫ f(t)f(t-T) dt
T--∞ -T/2
T/2
= Lim 1/T ∫ [s(t)+n(t)] [s(t-T)+n(t-T)] dt T--∞ -T/
=Qss(T)+Qnn(T)+Qsn(T)+Qns(T)
The periodic signal s(t) and noise signal n(t) are uncorrelated
Qsn(t)=Qns(t)=0 ;
Then Qff(t)=Qss(t)+Qnn(t)
BRIL,ECE Page 70
Basic Simulation Lab
The Auto correlation function of a periodic signal is periodic of the same frequency
and the Auto correlation function of a non periodic signal is tends to zero for large value
of T since s(t) is a periodic signal and n(t) is non periodic signal so Qss(T) is a periodic
where as aQnn(T) becomes small for large values of T Therefore for sufficiently large
values of T Qff(T) is equal to Qss(T).
Program:
clc;
clear all;
close all;
t=0:0.2:pi*8;
%input signal
s=sin(t);
subplot(6,1,1);
plot(s);
title('signal s');
xlabel('t');
ylabel('amplitude');
%generating noise
n = randn([1 126]);
%noisy signal
f=s+n;
subplot(6,1,2)
plot(f);
title('signal f=s+n');
xlabel('t');
ylabel('amplitude');
%aucorrelation of input signal
as=xcorr(s,s);
subplot(6,1,3);
plot(as);
title('auto correlation of s');
xlabel('t');
ylabel('amplitude');
%aucorrelation of noise signal
an=xcorr(n,n);
subplot(6,1,4)
plot(an);
title('auto correlation of n');
xlabel('t');
ylabel('amplitude');
BRIL,ECE Page 71
Basic Simulation Lab
BRIL,ECE Page 72
Basic Simulation Lab
BRIL,ECE Page 73
Basic Simulation Lab
Experiment No-16
EXTRACTION OF PERIODIC SIGNAL MASKED BY NOISE USING
CORRELATION
AIM: Write the program for extraction of periodic signal using correlation.
Software Required:
Matlab software
Theory:
A signal is masked by noise can be detected either by correlation techniques or by
filtering.Actually, the two techniques are equivalent. The correlation technique is a
measure of extraction of a given signal in the time domain whereas filtering achieves
exactly the same results in frequency domain.
Program:
clear all;
close all;
clc;
t=0:0.1:pi*4;
%input signal1
s=sin(t);
subplot(7,1,1)
plot(s);
title('signal s');
xlabel('t');
ylabel('amplitude');
%input signal2
c=cos(t);
subplot(7,1,2)
plot(c);
title('signal c');
xlabel('t');
ylabel('amplitude');
%generating noise signal
n = randn([1 126]);
%signal+noise
f=s+n;
subplot(7,1,3);
plot(f);
title('signal f=s+n');
xlabel('t');
ylabel('amplitude');
BRIL,ECE Page 74
Basic Simulation Lab
%crosscorrelation of signal1&signal2
asc=xcorr(s,c);
subplot(7,1,4)
plot(asc);
title(' correlation of s and c');
xlabel('t');
ylabel('amplitude');
%crosscorrelation of noise&signal2
anc=xcorr(n,c);
subplot(7,1,5)
plot(anc);
title(' correlation of n and c');
xlabel('t');
ylabel('amplitude');
%crosscorrelation of f&signal2
cfc=xcorr(f,c);
subplot(7,1,6)
plot(cfc);
title(' correlation of f and c');
xlabel('t');
ylabel('amplitude');
%extracting periodic signal
hh=asc+anc;
subplot(7,1,7)
plot(hh);
title('addition of sc+nc');
xlabel('t');
ylabel('amplitude');
BRIL,ECE Page 75
Basic Simulation Lab
Output:
BRIL,ECE Page 76
Basic Simulation Lab
Experiment No-17
VERIFICATION OF WIENER-KHINCHIN RELATION
Software Required:
Matlab software
Theory:
The wiener-khinchin theorem states that the power spectral density of a wide sense
stationary random process is the Fourier transform of the corresponding autocorrelation
function.
Continuous case:
Sxx(f)=∫rxx(T)e-j2πft dT
Where
rxx(T)=E[x(t)x*(t-T)]
Discrete case:
Sxx(f)=∑rxx[k]e-j2πkf
Where
rxx[k]=E[x(n)x*(n-k)]
BRIL,ECE Page 77
Basic Simulation Lab
Program:
clc;
clear all;
close all;
t=0:0.1:2*pi;
%input signal
x=sin(2*t);
subplot(3,1,1);
plot(x);
xlabel('time');
ylabel('amplitude');
title('input signal');
%autocorrelation of input signal
xu=xcorr(x,x);
%fft of autocorrelation signal
y=fft(xu);
subplot(3,1,2);
plot(abs(y));
xlabel('f');
ylabel('amplitude');
title('fft of autocorrelation of input signal');
%fourier transform of input signal
y1=fft(x);
%finding the power spectral density
y2=(abs(y1)).^2;
subplot(3,1,3);
plot(y2);
xlabel('f');
ylabel('magnitude');
title('PSD of input signal');
BRIL,ECE Page 78
Basic Simulation Lab
Output::
BRIL,ECE Page 79
Basic Simulation Lab
THEORY:
A stationary process (or strict(ly) stationary process or strong(ly) stationary process)
is a stochastic process whose joint probability distribution does not change when shifted in time or
space. As a result, parameters such as the mean and variance, if they exist, also do not change over
time or position..
Definition
Formally, let Xt be a stochastic process and letrepresent the cumulative distribution function of the
joint distribution of Xt at times t1…..tk. Then, Xt is said to be stationary if, for all k, for all τ, and for
all t1…..tk
The first property implies that the mean function mx(t) must be constant. The second property
implies that the correlation function depends only on the difference between t1 and t2 and only
needs to be indexed by one variable rather than two variables. Thus, instead of writing,
BRIL,ECE Page 80
Basic Simulation Lab
When processing WSS random signals with linear, time-invariant (LTI) filters, it is helpful to
think of the correlation function as a linear operator. Since it is a circulant
operator (depends only on the difference between the two arguments), its eigenfunctions are the
Fourier complex exponentials. Additionally, since the eigenfunctions of LTI operators are also
complex exponentials, LTI processing of WSS random signals is highly tractable—all computations
can be performed in the frequency domain. Thus, the WSS assumption is widely employed in signal
processing algorithms.
Applicatons:
Stationarity is used as a tool in time series analysis, where the raw data are often transformed to
become stationary, for example, economic data are often seasonal and/or dependent on the price level.
Processes are described as trend stationary if they are a linear combination of a stationary process and
one or more processes exhibiting a trend. Transforming these data to leave a stationary data set for
analysis is referred to as de-trending
Stationary and Non Stationary Random Process:
A random X(t) is stationary if its statistical properties are unchanged by a time shift in the time
origin.When the auto-Correlation function Rx(t,t+T) of the random X(t) varies with time difference T
and the mean value of the random variable X(t1) is independent of the choice of t1,then X(t) is said to
be stationary in the wide-sense or wide-sense stationary . So a continous- Time random process X(t)
which is WSS has the following properties
BRIL,ECE Page 81
Basic Simulation Lab
E*X(t)+=μX(t)= μX(t+T)
The Autocorrelation function is written as a function of T that is
RX(t,t+T)=Rx(T)
If the statistical properties like mean value or moments depends on time then the
random process is said to be non-stationary.
When dealing wih two random process X(t) and Y(t), we say that they are jointly
wide-sense stationary if each pocess is stationary in the wide-sense.
Rxy(t,t+T)=E[X(t)Y(t+T)]=Rxy(T).
PROGRAM:
clc;
clear all;
close all;
y =randn([1 40]);
my=round(mean(y));
z=randn([1 40]);
mz=round(mean(z));
vy=round(var(y));
vz=round(var(z));
t =sym('t','real');
h0=3;
x=y.*sin(h0*t)+z.*cos(h0*t);
mx=round(mean(x));
k=2;
xk=y.*sin(h0*(t+k))+z.*cos(h0*(t+k));
x1=sin(h0*t)*sin(h0*(t+k));
x2=cos(h0*t)*cos(h0*(t+k));
c=vy*x1+vz*x1;
BRIL,ECE Page 82