0% found this document useful (0 votes)
30 views75 pages

BS Lab Manual

Basic Simuolation lab Manual, MATLAB Programs on Signals & Systems

Uploaded by

gfiveu898
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)
30 views75 pages

BS Lab Manual

Basic Simuolation lab Manual, MATLAB Programs on Signals & Systems

Uploaded by

gfiveu898
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/ 75

(19A04303) BASIC SIMULATION LAB

INDEX

Exp. Sign. of Staff


Date Name of the Experiment Marks
No. with date

Average Marks obtained:

Remarks:

Signature
JAWAHARLAL NEHRU TECHNOLOGICAL UNIVERSITY ANANTAPUR
B.Tech – II-I Sem LTPC
2 0 0 1
19A04303 BASIC SIMULATION LAB
Course Objectives:
• To provide practical exposure with generation and simulation of basic signals using standardized
tools.
• To teach analysing signals and sequences using Fourier, Laplace and Z-transforms.
• To enable to write programs for signal processing applications.
List of Experiments:
1. Write a program to generate various Signals and Sequences: Periodic and Aperiodic, Unit Impulse,
Unit Step, Square, Saw tooth, Triangular, Sinusoidal, Ramp, Sinc function.
2. Perform operations on Signals and Sequences: Addition, Multiplication, Scaling, Shifting, Folding,
Computation of Energy and Average Power.
3. Write a program to find the trigonometric & exponential Fourier series coefficients of a rectangular
periodic signal. Reconstruct the signal by combining the Fourier series coefficients with appropriate
weightages- Plot the discrete spectrum of the signal.
4. Write a program to find Fourier transform of a given signal. Plot its amplitude and phase spectrum.
5. Write a program to convolve two discrete time sequences. Plot all the sequences.
6. Write a program to find autocorrelation and cross correlation of given sequences.
7. Write a program to verify Linearity and Time Invariance properties of a given Continuous/Discrete
System.
8. Write a program to generate discrete time sequence by sampling a continuous time signal. Show
that with sampling rates less than Nyquist rate, aliasing occurs while reconstructing the signal.
9. Write a program to find magnitude and phase response of first order low pass and high pass filter.
Plot the responses in logarithmic scale.
10. Write a program to find response of a low pass filter and high pass filter, when a speech signal is
passed through these filters.
11. Write a program to generate Complex Gaussian noise and find its mean, variance, Probability
Density Function (PDF) and Power Spectral Density (PSD).
12. Generate a Random data (with bipolar) for a given data rate (say 10kbps). Plot the same for a time
period of 0.2 sec.
13. To plot pole-zero diagram in S-plane/Z-plane of given signal/sequence and verify its stability.

Note: All the experiments are to be simulated using MATLAB or equivalent software.

Course Outcomes:
CO1: Understand the basic concepts of programming in MATLAB and explain use of built-in
functions to perform assigned task. (L1)
CO2: Generate signals and sequences, Input signals to the systems to perform various operations
(L2)
CO3: Analyze signals using Fourier, Laplace and Z-transforms. (L3)
CO4: Compute Fourier transform of a given signal and plot its magnitude and phase spectrum. (L3)
CO5: Verify Sampling theorem, Determine Convolution and Correlation between signals and
sequences. (L5)
19A04303 BASIC SIMULATION LAB

CONTENTS

S. No. Name of the Experiment Page No.

Introduction to MATLAB 1-2

1 Basic Operations on Matrices* 3-7

2 (A) Generation of Various Signals


8-13
(B) Generation of Various Sequences

3 (A) Operations on Signals 14-17

(B) Operations on Sequences 18-21

4 Even and Odd Parts of a Sequence &Real and Imaginary Parts of a Sequence * 22-25

5 (A) Trigonometric Fourier Series 26-29

(B) Exponential Fourier Series 30-33

6 Demonstration of GIBB’s Phenomenon* 34-37

7 Fourier Transform 38-41

8 Linear Convolution 42-45

9 Auto Correlation and Cross Correlation 46-49

10 Linearity and Time Invariance 50-52

11 Sampling Theorem 53-55

12 LPF & HPF 56-57

13 Speech Signal Processing 58-60

14 Complex Gaussian Noise 61-62

15 Generation of Random Data 63-65

16 Pole-Zero Diagram in S-Plane/Z-Plane 66-69

* Marked experiments are beyond syllabus


LABORATORY INSTRUCTIONS

1. While entering the Laboratory, the students should follow the dress code. (White apron, Female
Students should tie their hair back).
2. The students should bring their observation book, record, calculator, necessary stationery items and
graph sheets if any for the lab classes without which the students will not be allowed for doing the
experiment.
3. If any damage or breakage is noticed, it should be reported to the concerned in charge immediately.
4. The theoretical calculations and the updated register values should be noted down in the observation
book and should be corrected by the lab in-charge on the same day of the laboratory session.
5. Each experiment should be written in the record note book only after getting signature from the lab
in-charge in the observation note book.
6. Record book must be submitted in the successive lab session after completion of experiment.
7. Shutdown the systems properly while leaving the lab.
8. Arrange chairs/stools properly while leaving the lab.
9. 100% attendance should be maintained for the laboratory classes.
BASIC SIMULATION LAB

INTRODUCTION TO MATLAB

INTRODUCTION:

• MATLAB is a mathematical software package which is used extensively in


academia and industry.
• MATLAB stands for MATrix LABoratory
• It is one of the leading Scientific and Technical computing software, used by many
engineers and scientists.
• This was developed by CLEVE MOLER, a professor of mathematics and computer
science.
• Over the last two decades MATLAB has evolved into a much powerful and versatile
package, useful for a wide variety of academic, research and industrial applications.

IMPORTANCE OF MATLAB:

• As a matrix-based system it is great tool for simulation and data analysis.


• It is simple, powerful and easy to learn programming language as it provides
extensive online help.
• Unlike other high-level languages like FORTRAN, C, etc., it does not require any
variable declaration and dimension statements at the beginning.
• MATLAB programs written for solving complex problems take a fraction of time
and look very small in general when compared to the codes of high-level language.
• It also enables the users to write their own functions for easy customization.
• It is excellent and very powerful for two- and three-dimensional graphics and
animation.
• It is an indispensable Graphical User Interface (GUI) tool and used for proper
understanding of concepts in advanced subjects like mathematics, signals and
systems, control systems, digital signal processing, VLSI design, etc,.
• It also provides several optional ‘tool boxes’ such as statistics toolbox, control
system toolbox, signal processing toolbox, etc. where toolbox provides a set of
functions written for specific application.
• It is compatible, with most operating systems such as windows, Linux, etc.
• It uses matrix notation it replaces several ‘for’ loops which are usually found in C
type of codes.

GETTING STARTED WITH MATLAB:


• LAUNCHING MATLAB: If MATLAB is installed on your computer, you can
possibly find the MATLAB icon as a shortcut on your desktop of the windows-
based system, after you login to the computer using your user id and the password.

• MATLAB DESKTOP LAYOUT: When you launch MATLAB for the first time,
the MATLAB desktop appears with a default layout. You can change the desktop
configuration to suits your need.

DEPARTMENT OF ECE Page 1


BASIC SIMULATION LAB

• THE COMMAND WINDOW: It is the place where you enter all MATLAB
commands at the “command prompt” (>>). MATLAB executes the commands and
display the result of each operation performed.

• THE COMMAND HISTORY WINDOW: All the commands entered recently at


the command prompt are stored in the “command History” window, for future use,
until you select and delete them purposefully.

• THE CURRENT DIRECTORY WINDOW: It displays the list of all files and
folders under the current directory, which happens to be the ‘work’ sub-directory,
by default, under the MATLAB root directory.

• CHANGING THE CURRENT DIRECTORY: A new directory called ‘set path’


window shows all directories and subdirectories which are visible to MATLAB.

1. Click on ‘add folder’. A new window called ‘Browser for Folder’


2. Click on up or down arrow buttons until the ‘E’ drive appears, select
it by clicking once on it.
3. Click on ‘Make New Folder ‘and ‘slab’ in the ‘folder’ window and
say OK
4. The set path window now should look like the one that the new
directory is added to the MATLAB search path.
5. Click on ‘save’ and then ‘close’
6. Type cd E:\slab at the command prompt and press ’Enter’ and can
start creating new files

• MATLAB EDITOR AND DEBUGGER :


1. Create a new file called a ‘.m’, into which the MATLAB commands,
comments and the data can be entered.
2. Edit all that is written into the file using the usual commands such
as cut, copy, etc.,
3. Import data such as ASCII text or a huge matrix, from an external
environment in to the file.
4. Save the file in a chosen directory.
5. Debug the MATLAB commands by running the program either line
in a step mode or run a portion of the program by setting break
points.
6. Open an existing .m file for a possible modification.

CONCLUSION:
Introduction to MATLAB is studied successfully.

DEPARTMENT OF ECE Page 2


BASIC SIMULATION LAB

EXPT. NO:
BASIC
➢ OPERATIONS ON MATRICES
DATE:

AIM: To write a MATLAB program for generating various Signals and Sequences

TOOLS REQUIRED: System with MATLAB SOFTWARE

PROCEDURE:
• Open MATLAB
• Open new M-file
• Type the program
• Save in current directory
• Compile and Run the program
• For output see command window/figure
PROGRAM:
clc; clear; close all;
a=[1,2,3;4,5,6;7,8,9];% Matrix generation
b=a’; % Transpose
c=a+b; %Addition
d=a-b; %subtraction
e=a*b; %Multiplication
f=a.*b; % Array Multiplication
g=a/b; % Division
h=a\b; % Left Division→b/a
i=det(a); % Determinant
j=rank(a); % Rank
jj=diag(a) % diagonal elements of A
k=trace(a); % Sum of diagonal elements
l=inv(a); % inverse
m=eig(a); %eigen values
n=mean(a); % average of elements column wise
o=sort(a); %sorting of elements column wise in ascending order
p=max(a); %finding maximum values column wise
q=ones(3,2); % A 3X2 matrix with all ones
r=zeros(1,4); % A 1X4 ,matrix with all zeros
t=eye(3); % A 3X3 identity matrix

DEPARTMENT OF ECE Page 3


BASIC SIMULATION LAB

DEPARTMENT OF ECE Page 4


BASIC SIMULATION LAB

DEPARTMENT OF ECE Page 5


BASIC SIMULATION LAB

DEPARTMENT OF ECE Page 6


BASIC SIMULATION LAB

RESULT:

DEPARTMENT OF ECE Page 7


BASIC SIMULATION LAB

DEPARTMENT OF ECE Page 8


BASIC SIMULATION LAB

GENERATION OF VARIOUS SIGNALS EXPT. NO:


➢ AND SEQUENCES DATE:

AIM: To write a MATLAB program for generating various Signals and Sequences

TOOLS REQUIRED: System with MATLAB SOFTWARE

PROCEDURE:
• Open MATLAB
• Open new M-file
• Type the program
• Save in current directory
• Compile and Run the program
• For output see command window/figure

PROGRAM:
Unit Impulse Function
%unit impulse function% Model graph:
%Continuous%
clc; clear all; close all;
t = -10 : 0.1 : 10;
Xt = (t==0);
subplot(2,1,1);
plot(t, Xt);
axis([-11 11 -0.5 1.5]);
xlabel('time');
ylabel('amplitude');
title('unit impulse function');

%Discrete%
n= -10:10;
Xn=(n==0);
subplot(2,1,2);
stem(n,Xn);
axis([-11 11 -0.5 1.5]);
xlabel('Samples');
ylabel('amplitude');
title('unit impulse discrete function');

DEPARTMENT OF ECE Page 9


BASIC SIMULATION LAB

Unit Step Function


%unit step function% Model graph:
%Continuous%
clc; clear all; close all;
t=-10:0.1:10;
Xt=(t>=0);
subplot(2,1,1);
plot(t,Xt);
axis([-11 11 -0.5 1.5]);
xlabel('time');
ylabel('amplitude');
title('unit step function');

%Discrete%
n=-10:10;
Xn=(n>=0);
subplot(2,1,2);
stem(n,Xn);
axis([-11 11 -0.5 1.5]);
xlabel('Samples');
ylabel('amplitude');
title(' discrete unit step function');

Unit Ramp Function


%unit ramp function% Model graph:
%Continuous%
clc; clear all; close all;
t= -10:0.1:10;
Xt=(t>=0).*t;
subplot(2,1,1);
plot(t,Xt);
axis([-11 11 -1 11]);
xlabel('time');
ylabel('amplitude');
title('unit ramp function');

%Discrete%
n=-10:10;
Xn=(n>=0).*n;
subplot(2,1,2);
stem(n,Xn);
axis([-11 11 -1 11]);
xlabel(' Samples ');
ylabel('amplitude');
title(' discrete unit ramp function');

DEPARTMENT OF ECE Page 10


BASIC SIMULATION LAB

Sinusoidal Signal
%sinusoidal function% Model graph:
%Continuous%
clc; clear; close all;
t=0:0.001:1;
Xt=sin(2*pi*t);
figure,
subplot(2,1,1);
plot(t,Xt);
axis([-.5 1.5 -1.5 1.5])
xlabel('time'); ylabel('amplitude');
title('sinusoidal signal');
%Discrete%
n=0:10;
Xn=sin(pi*n/4);
subplot(2,1,2);
stem(n,Xn);
axis([-0.5 11 -1.5 1.5])
xlabel(' Samples ');
ylabel('amplitude');
title('sinusoidal sequence');

Square Signal
%square wave% Model graph:
%Continuous%
clc; clear; close all;
t=0:0.001:1;
Xt=square(2*pi*t);
figure,
subplot(2,1,1);
plot(t,Xt);
axis([-.5 1.5 -1.5 1.5])
xlabel('time'); ylabel('amplitude');
title('square wave signal');
%Discrete%
n=0:10;
Xn=square(pi*n/4);
subplot(2,1,2);
stem(n,Xn);
axis([-0.5 11 -1.5 1.5])
xlabel(‘Samples');ylabel('amplitude');
title('square wave sequence');

DEPARTMENT OF ECE Page 11


BASIC SIMULATION LAB

Saw tooth Signal


%sawtooth signal%%Continuous% Model graph:
clc; clear; close all;
t=0:0.001:1;
Xt=sawtooth(2*pi*t);
figure,
subplot(2,1,1);
plot(t,Xt);
axis([-.5 1.5 -1.5 1.5])
xlabel('time');ylabel('amplitude');
title('sawtooth signal');
%Discrete%
n=0:10;
Xn=sawtooth(pi*n/4);
subplot(2,1,2);
stem(n,Xn);
axis([-0.5 11 -1.5 1.5])
xlabel(‘Samples');
ylabel('amplitude');
title('sawtooth sequence');

Triangular Wave
%Triangular signal%%Continuous% Model graph:
clc; clear; close all;
t=0:0.001:1;
Xt=sawtooth(2*pi*t,.5);
figure,
subplot(2,1,1);
plot(t,Xt);
axis([-.5 1.5 -1.5 1.5])
xlabel('time');ylabel('amplitude');
title('Triangular Wave');
%Discrete%
n=0:10;
Xn=sawtooth(pi*n/4,.5);
subplot(2,1,2);
stem(n,Xn);
axis([-0.5 11 -1.5 1.5])
xlabel('Samples');
ylabel('amplitude');
title('Triangular wave sequence');

DEPARTMENT OF ECE Page 12


BASIC SIMULATION LAB

Sinc Signal
%Sinc signal%%Continuous% Model graph:
clc; clear; close all;
t=-5:0.01:5;
Xt=sinc(t);
figure,
subplot(2,1,1);
plot(t,Xt); axis([-5.5 5.5 -0.5 1.5])
xlabel('time');
ylabel('amplitude');
title('Sinc signal');
%Discrete%
n=-12:12;
Xn=sinc(n/4);
subplot(2,1,2);
stem(n,Xn);axis([-13 13 -0.5 1.5])
xlabel('Samples');
ylabel('amplitude');
title('Sinc sequence');

VIVA -VOCE QUESTIONS:


1. How do you define a signal?
2. What are the characteristics of a signal?
3. What type of information can a signal carry?
4. What is a analog signal? Why can’t it be stored in a computer?
5. What is the difference between the energy and the power signal?
6. Difference between causal and anti-causal?
7. Define unit step signal? Where do we use?
8. Derive the Relationship among signals.

RESULT:

DEPARTMENT OF ECE Page 13


BASIC SIMULATION LAB

Waveforms:

DEPARTMENT OF ECE Page 14


BASIC SIMULATION LAB

OPERATIONS ON SIGNALS, COMPUTATION EXPT. NO:


OF ENERGY AND AVERAGE POWER DATE:

AIM: To write a MATLAB program to perform the operations on signals.

TOOLS REQUIRED: System with MATLAB SOFTWARE

PROCEDURE:

• Open MATLAB
• Open new M-file
• Type the program
• Save in current directory
• Compile and Run the program
• For output see command window/figure

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

DEPARTMENT OF ECE Page 15


BASIC SIMULATION LAB

Waveforms:

DEPARTMENT OF ECE Page 16


BASIC SIMULATION LAB

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');
%program for energy of a signal
t=0:pi:10*pi;
z2=cos(2*pi*50*t).^2;
e=sum(abs(z2).^2); disp('energy of given signal is');e
% program for power of a signal
p=(sum(abs(z2).^2))/length(z2);
disp('power of given signal is');p
OUTPUT :

Power of the signal

Energy of the signal

DEPARTMENT OF ECE Page 17


BASIC SIMULATION LAB

Waveforms:

DEPARTMENT OF ECE Page 18


BASIC SIMULATION LAB

OPERATIONS ON SEQUENCES, EXPT. NO:


COMPUTATION OF ENERGY AND AVERAGE DATE:
POWER

AIM: To write a MATLAB program to perform the operations on sequences.


TOOLS REQUIRED: System with MATLAB SOFTWARE

PROCEDURE:

• Open MATLAB
• Open new M-file
• Type the program
• Save in current directory
• Compile and Run the program
• For output see command window/figure
PROGRAM:
clc;
clear all;
close all;
s1=input(‘Enter the Sequence 1: ‘); %Both s1 and s2 sequences are same length
n=0:length(s1) -1;
s2=input(‘Enter the Sequence 2: ‘);
subplot(4,1,1); stem(n,s1); xlabel('samples'); ylabel('amplitude'); title('first sequence');
subplot(4,1,2);stem(n,s2); xlabel('samples'); ylabel('amplitude');
title('second sequence');
s3=s1+s2; % Sum
subplot(4,1,3);stem(n,s3); xlabel('samples'); ylabel('amplitude');
title('sum of the sequences');
s4=s1.*s2; % Multiplication
subplot(4,1,4);stem(n,s4); xlabel('samples'); ylabel('amplitude');
title('multiplication of sequences');

s5=3*s1 ; % Amplitude Scaling


s6=s1/3 ; % Signal attenuation
figure,
subplot(3,1,1) ; stem(n,s1) ; xlabel('samples'); ylabel('amplitude');
title('original Sequence');
subplot(3,1,2) ; stem(n,s5) ; xlabel('samples'); ylabel('amplitude');
title('Amplitude Scaled');
subplot(3,1,3) ; stem(n,s6) ; xlabel('samples'); ylabel('amplitude');title('Attenuated ') ;

DEPARTMENT OF ECE Page 19


BASIC SIMULATION LAB

Waveforms:

DEPARTMENT OF ECE Page 20


BASIC SIMULATION LAB

s7=upsample(s1,2); % Signal Exapansion


s8=downsample(s1,3); % Signal Compression
n1 = 0:length(s7)-1;
n2 = 0:length(s8)-1;
figure,
subplot(3,1,1) ; stem(n,s1) ; xlabel('samples'); ylabel('amplitude');
title('original Sequence');
subplot(3,1,2) ; stem(n1,s7) ; xlabel('samples'); ylabel('amplitude'); title(' Enlarged ')
subplot(3,1,3) ; stem(n2,s8) ; xlabel('samples'); ylabel('amplitude');
title('Compressed ')

n3=n+2; % delaying by 2
n4=n-3; % advanced by 3
s9=fliplr(s1);
n5=fliplr(-n);
figure,
subplot(4,1,1) ; stem(n,s1) ; xlabel('samples'); ylabel('amplitude') ;
title('original Sequence');
subplot(4,1,2) ; stem(n3,s1) ; xlabel('samples'); ylabel('amplitude');
title('delayed Sequence');
subplot(4,1,3) ; stem(n4,s1) ; xlabel('samples'); ylabel('amplitude');
title('advanced Sequence');
subplot(4,1,4) ; stem(n5,s9) ; xlabel('samples'); ylabel('amplitude');
title('time reversed Sequence');

E = sum(s1.^2);
P = sum(s1.^2)/length(s1);
fprintf('The energy and power of the signal are %2.4f and %2.4f \n', E, P);

OUTPUT :

Enter the sequence 1:

Enter the sequence 2:

VIVA -VOCE QUESTIONS:


1. Define discrete time system.
2. Why should you design a discrete time system?
3. What is the other name of a signal multiplier system?
4. What is meant by attenuation of the signal?
5. What happens to the signal when it is folded about the time origin?
6. What do mean by real-time signal processing?

RESULT:

DEPARTMENT OF ECE Page 21


BASIC SIMULATION LAB

Waveforms:

DEPARTMENT OF ECE Page 22


BASIC SIMULATION LAB

s
EXPT. NO:
Even and Odd & Real & Imaginary Parts of
a Signal DATE:

AIM: To write a MATLAB program to find the Even & odd and Real & Imaginary parts of
the signal.
TOOLS REQUIRED: System with MATLAB SOFTWARE

PROCEDURE:

• Open MATLAB
• Open new M-file
• Type the program
• Save in current directory
• Compile and Run the program
• For output see command window/figure

PROGRAM:
clc;
close all;
clear all;
t=-5:0.1:5;
y1=exp(2*t);
y2=exp(-2*t);
ye=(y1+y2)/2;
yo=(y1-y2)/2;
yc=complex(y1,y2);
ycr=real(yc);
yci=imag(yc);
figure(1);
subplot(2,1,1);
stem(t,y1);
title('sequence 1');
xlabel('t');
ylabel('x(t)');
subplot(2,1,2);
stem(t,y2);
title('sequence 2');
xlabel('t');
ylabel('y2(t)');
figure(2);
subplot(2,1,1);
stem(t,ye);

DEPARTMENT OF ECE Page 23


BASIC SIMULATION LAB

Waveforms:

DEPARTMENT OF ECE Page 24


BASIC SIMULATION LAB

title('even function');
xlabel('t');
ylabel('ye(t)');
subplot(2,1,2);
stem(t,yo);
title('odd function');
xlabel('t');
ylabel('yo(t)');
figure(3);
subplot(3,1,1);
stem(yc);
title('complex');
xlabel('t');
ylabel('yc(t)');
subplot(3,1,2);
stem(ycr);
title('real part of yc');
xlabel('t');
ylabel('ycr(t)');
subplot(3,1,3);
stem(yci);
title('imaginary part of yc');
xlabel('t');
ylabel('yci(t)');

VIVA QUESTIONS:

1. Define Symmetry property of signals


2. How a signal can be decomposed in to even and odd parts
3. List out the properties of signals
4. What is half wave symmetry?
5. What is quarter wave symmetry?

RESULT:

DEPARTMENT OF ECE Page 25


BASIC SIMULATION LAB

Waveforms:

DEPARTMENT OF ECE Page 26


BASIC SIMULATION LAB

s
EXPT. NO:
Trigonometric Fourier Series
DATE:

AIM: To write a MATLAB program to find the trigonometric Fourier series coefficients of a
rectangular periodic signal. Reconstruct the signal by combining the Fourier series coefficients
with appropriate weightages and also Plot the discrete spectrum of the signal.
TOOLS REQUIRED: System with MATLAB SOFTWARE

PROCEDURE:

• Open MATLAB
• Open new M-file
• Type the program
• Save in current directory
• Compile and Run the program
• For output see command window/figure

PROGRAM:
clc
clear all
close all
%% generation of periodic signal (time period axis etc)
T = 4; %time period (can be user defined)
w = (2*pi)/T;
t = -5:0.01:5;
N = 70; %number of harmonics (can be user defined)
n=1:N; %discrete axis
%% signals - choose 1 and comment other!
y = @(t)square(w.*t);
%% computation of a0,an and bn i.e trigonometric coeffecients
a0 = (1/T)*integral(y,0,T,'ArrayValued',true);
w = (2*pi)/T;
n = 1:N;
mul = @(t)cos(n'*w.*t);
mul2 = @(t)sin(n'*w.*t);
sig1 = @(t)y(t).*mul(t);
sig2=@(t)y(t).*mul2(t);
a = (2/T).*integral(sig1,0,T,'ArrayValued',true); %integral function takes function handles
only
b = (2/T).*integral(sig2,0,T,'ArrayValued',true);
%% Reconstruction of trigonometric F.S
z1=0;
w = (2*pi)/T;
for k = 1:N
z1 = z1 + a(k)*cos(k*w.*t)+b(k)*sin(k*w.*t);
end

DEPARTMENT OF ECE Page 27


BASIC SIMULATION LAB

Waveforms:

DEPARTMENT OF ECE Page 28


BASIC SIMULATION LAB

z = a0 + z1;
err = immse(y(t),z);
%% plot figures
figure('Name','F.S trigonometric Series and reconstruction')
subplot(3,2,1);
stem(n,a);
title('Magnitude of an');
xlabel('Discrete axis');
ylabel('Magnitude');
subplot(3,2,2);
stem(n,b);
title('Magnitude of bn');
xlabel('Discrete axis');
ylabel('Magnitude');
subplot(3,2,3)
stem(n,phase(a));
title('Phase of an');
xlabel('Discrete axis');
ylabel('Phase');
subplot(3,2,4)
stem(n,phase(b));
title('Phase of bn');
xlabel('Discrete axis');
ylabel('Phase');
subplot(3,2,5);
plot(t,y(t),'linewidth',2);
title('Original signal');
xlabel('Time axis');
ylabel('Amplitude');
subplot(3,2,6);
plot(t,z,'linewidth',2);
title('reconstructed signal');
xlabel('Time axis');
ylabel('Amplitude');

DEPARTMENT OF ECE Page 29


BASIC SIMULATION LAB

Waveforms:

DEPARTMENT OF ECE Page 30


BASIC SIMULATION LAB

EXPT. NO:
Exponential Fourier Series
DATE:

AIM: To write a MATLAB program to find the Exponential Fourier series coefficients of a
rectangular periodic signal. Reconstruct the signal by combining the Fourier series coefficients
with appropriate weightages and also Plot the discrete spectrum of the signal.

TOOLS REQUIRED: System with MATLAB SOFTWARE


PROCEDURE:

• Open MATLAB
• Open new M-file
• Type the program
• Save in current directory
• Compile and Run the program
• For output see command window/figure
PROGRAM:
clc
clear all
close all
%% generation of periodic sequence (time period axis etc)
T = 4; %time period (can be user defined)
w = (2*pi)/T;
t = -5:0.01:5;
N = 70; %number of harmonics (can be user defined)
n=1:N; %discrete axis
%% signals - choose 1 and comment other!
y = @(t)square(w.*t);
%% Calculation of Exponential Fourier Series Coefficients
w = (2*pi)/T;
n = 1:N;
C0 = (1/T).*integral(y,0,T,'ArrayValued',true);
mul = @(t)exp(-1j*n'*w.*t);
mul2 = @(t)exp(1j*n'*w.*t);
sig = @(t)y(t).*mul(t);
sig2 = @(t)y(t).*mul2(t);
Cn = (1/T).*integral(sig,0,T,'ArrayValued',true);
Cn_neg = (1/T).*integral(sig2,0,T,'ArrayValued',true);
%% reconstruction as per the series with doubling for complex values (amplitude)
w = (2*pi)/T;
z1 = 0;
for k = 1:N
z1 = z1 + Cn(k).*exp(1j*k*w.*t);
end
z_com = z1 + C0;
z_com = z_com*2;

DEPARTMENT OF ECE Page 31


BASIC SIMULATION LAB

Waveforms:

DEPARTMENT OF ECE Page 32


BASIC SIMULATION LAB

%% checks if signal has any negative cycles


if y(t) >=0
z_f = real(z_com) - C0;
else
z_f = z_com;
end
%% mean square error computation
err_com = immse(y(t),real(z_f));
figure('Name','Complex F.S coeffecients and reconstruction');
subplot(3,2,1);
stem(n,abs(Cn));
title('Amplitude spectrum Cn');
xlabel('Discrete axis');
ylabel('Magnitude');
subplot(3,2,2);
stem(n,phase(Cn));
title('Phase of Cn');
xlabel('Discrete axis');
ylabel('Phase');
subplot(3,2,3);
stem(n,abs(Cn_neg));
title('Amplitude spectrum C-n');
xlabel('Discrete axis');
ylabel('Magnitude');
subplot(3,2,4);
stem(n,phase(Cn_neg));
title('Phase of C-n');
xlabel('Discrete axis');
ylabel('Phase');
subplot(3,2,5);
plot(t,y(t),'linewidth',2);
title('Original signal');
xlabel('Time axis');
ylabel('Amplitude');
subplot(3,2,6);
plot(t,real(z_f),'linewidth',2);
title('reconstructed signal');
xlabel('Time axis');
ylabel('Amplitude');

VIVA -VOCE QUESTIONS:


1. What is Fourier series expansion of Signals?
2. List out the diritchlets conditions
3. What are the properties of CTFS?
4. How to calculate the Co-efficients in TFS
5. What is the relation between TFS & EFS
RESULT:

DEPARTMENT OF ECE Page 33


BASIC SIMULATION LAB

Waveforms:

DEPARTMENT OF ECE Page 34


BASIC SIMULATION LAB

DEMONSTRATION OF GIBB’S EXPT. NO:


PHENOMENON DATE:

AIM:

To demonstrate Gibbs Phenomenon using MATLAB

TOOLS REQUIRED: System with MATLAB SOFTWARE

PROCEDURE:

• Open MATLAB
• Open new M-file
• Type the program
• Save in current directory
• Compile and Run the program
• For output see command window/figure

PROGRAM:

%% Gibb's phenomenon.
t=linspace(-2,2,2000);
u=linspace(-2,2,2000);
sq=[zeros(1,500),2*ones(1,1000),zeros(1,500)];
k=2;
N=[1,3,7,19,49,70];
for n=1:6;
an=[];
for m=1:N(n)
an=[an,2*k*sin(m*pi/2)/(m*pi)];
end;
fN=k/2;
for m=1:N(n)
fN=fN+an(m)*cos(m*pi*t/2);
end;
nq=int2str(N(n));
subplot(3,2,n),plot(u,sq,'r','LineWidth',2);hold on;
plot(t,fN,'LineWidth',2); hold off; axis([-2 2 -0.5 2.5]);grid;
xlabel('Time'), ylabel('y_N(t)');title(['N= ',nq]);
end;

DEPARTMENT OF ECE Page 35


BASIC SIMULATION LAB

Waveforms:

DEPARTMENT OF ECE Page 36


BASIC SIMULATION LAB

VIVA QUESTIONS
1. What is the Fourier series of Square Pulse?
2. What is Gibbs Phenomenon?
3. What is meant by discrete Spectrum?
4. What is the duality property of CTFS

RESULT:

DEPARTMENT OF ECE Page 37


BASIC SIMULATION LAB

Waveforms:

DEPARTMENT OF ECE Page 38


BASIC SIMULATION LAB

EXPT. NO:
FOURIER TRANSFORM OF A GIVEN SIGNAL
AND PLOTTING ITS MAGNITUDE AND PHASE DATE:
SPECTRUM

AIM: To find the Fourier transform of a given signal and plotting its magnitude and phase
spectrum.

TOOLS REQUIRED:
System with MATLAB software.

PROCEDURE:

• Open MATALB
• Open new M-file
• Type the program
• Save in current directory
• Compile and run the program
• For the output see the command window / figure window

PROGRAM:

clc; clear all; close all;


syms x y
f = exp(-x^2);
disp('Original Function is');f
subplot(3,1,1); ezplot(f);
xlabel('time'); ylabel('amplitude'); title('Time domain Signal');
grid;
z=fourier(f, x, y);
disp('Fourier Transform of input signal');z
iz=ifourier(z,y,x);
disp('Inverse Fourier Transform ');
simplify(iz);iz
mg=abs(z);
subplot(3,1,2);
ezplot(mg);
xlabel('frequency');
ylabel('amplitude');
title('magnitude spectrum of a input signal');
grid;
pha=atan(imag(z)/real(z));
subplot(3,1,3);
ezplot(pha);

DEPARTMENT OF ECE Page 39


BASIC SIMULATION LAB

Theoretical Calculations & Waveforms:

DEPARTMENT OF ECE Page 40


BASIC SIMULATION LAB

xlabel('frequency');
ylabel('amplitude');
title('phasespectrum of a input signal');
grid;

OUTPUT:
Input Signal

Fourier Transform of input signal

Inverse Fourier Transform of input signal

VIVA VOCE QUESTIONS:


6. Distinguish between Fourier series and Fourier transform.
7. Distinguish between Fourier transform and discrete fourier transform.
8. What does the DFT do to a signal?
9. State Euler’s theorem.

RESULT:

DEPARTMENT OF ECE Page 41


BASIC SIMULATION LAB

Theoretical Calculations & Waveforms:

DEPARTMENT OF ECE Page 42


BASIC SIMULATION LAB

LINEAR CONVOLUTION BETWEEN EXPT. NO:


SEQUENCES AND SIGNALS DATE:

AIM: To write a MATLAB program to compute linear convolution of two given


sequences.

TOOLS REQUIRED: System with MATLAB SOFTWARE.

PROCEDURE:

• Open MATALB
• Open new M-file
• Type the program
• Save in current directory
• Compile and run the program
• For the output see the command window / figure window

PROGRAM:
% Discrete Sequences
clc; clear all; close all;
x=input(' Enter the first sequence x[n]=');
h=input('Enter the second sequence h[n]=');
y=conv(x, h);
figure;
subplot(3,1,1);stem(x);ylabel ('Amplitude---');xlabel ('n---');title ('x(n) Vs n');
subplot(3,1,2);stem(h);ylabel ('Amplitude---');xlabel ('n---');title ('h(n) Vs n');
subplot(3,1,3);stem(y);ylabel ('Amplitude---');xlabel ('n---');title ('convolved sequene');
disp('Linear convolution of x[n] and h[n] is ');
disp(y)

% Continuous time signals


clc; clear all; close all;
t=0:0.01:2;
x=sin(2*pi*t);
h=square(2*pi*t);
y1=conv(x,h);
t1=linspace(0,2*max(t),2*length(t)-1);
figure,
subplot(3,1,1); plot(t,x); % signal 1
subplot(3,1,2); plot(t,h); % signal 2
subplot(3,1,3); plot(t1,y1); % convolved signal

DEPARTMENT OF ECE Page 43


BASIC SIMULATION LAB

Theoretical Calculations & Waveforms:

DEPARTMENT OF ECE Page 44


BASIC SIMULATION LAB

OUTPUT:-
A. For Discrete sequences

Enter the first sequence x[n] =

Enter the second sequence h[n] =

Linear convolution of x[n] and h[n] is

VIVA VOCE QUESTIONS:


1. Define convolution.
2. What is the significance of convolution?
3. How are the LTI system classified in general?
4. When do u call a system linear?
5. Is polynomial multiplication is same as the convolution?

RESULT:

DEPARTMENT OF ECE Page 45


BASIC SIMULATION LAB

Theoretical Calculations & Waveforms:

DEPARTMENT OF ECE Page 46


BASIC SIMULATION LAB

AUTO CORRELATION AND CROSS EXPT. NO:


CORRELATION BETWEEN SIGNALS DATE:

AIM: To write a MATLAB program to compute Auto Correlation and Cross Correlation
between Signals of two given sequences

TOOLS REQUIRED: System with MATLAB SOFTWARE.

PROCEDURE:
• Open MATALB
• Open new M-file
• Type the program
• Save in current directory
• Compile and run the program
• For the output see the command window / figure window

PROGRAM:

% Discrete Sequences
clc; clear all; close all;
x=input(' Enter the first sequence x[n]= ');
y=input ('Enter the second sequence y[n]= ');
z1=conv(x,fliplr(x)); % Autocorrelation of x\
z2=conv(x,fliplr(y)); % cross-correlation of x and y
figure;
subplot(4,1,1); stem(x); ylabel ('Amplitude'); xlabel ('n--'); title ('x(n) Vs n');
subplot(4,1,2); stem(y); ylabel ('Amplitude'); xlabel ('n---'); title ('y(n) Vs n');
subplot(4,1,3); stem(z1); ylabel ('Amplitude'); xlabel ('n---');
title ('Autocorrelation of x(n)');
subplot(4,1,4); stem(z2); ylabel ('Amplitude'); xlabel ('n---');
title ('Cross correlation of x(n) and y(n)');
disp('Autocorrelation of x(n) is');
disp(z1)
disp('Crosscorelation of x(n) and y(n) is');
disp(z2)

% Continuous time signals


t=0:0.01:2;
x=sin(2*pi*t);
y=square(2*pi*3*t);
z1=conv(x,fliplr(x));
z2=conv(x,fliplr(y));
t1=linspace(0,2*max(t),2*length(t)-1);
figure,

DEPARTMENT OF ECE Page 47


BASIC SIMULATION LAB

Theoretical Calculations & Waveforms:

DEPARTMENT OF ECE Page 48


BASIC SIMULATION LAB

subplot(4,1,1); plot(t,x); title('signal 1');axis([0 2 -1.5 1.5])


subplot(4,1,2); plot(t,y); title('signal 2'); axis([0 2 -1.5 1.5])
subplot(4,1,3); plot(t1,z1); title('autocorrelation of signal 1'); axis([0 4 -110 110])
subplot(4,1,4); plot(t1,z2); title('crosscorrelation of signals'); axis([0 4 -30 30])

Expected OUTPUT:
For Discrete sequences:
Enter the first sequence x[n] =
Enter the first sequence y[n] =
Autocorrelation of x(n) is

Cross correlation of x(n) and y(n) is

VIVA -VOCE QUESTIONS:

1. Define correlation and types of correlation.


2. Compare and correlation and convolution.
3. How do u define the auto correlation between two CT signals?
4. Expand RADAR and SONAR.
5. Explain the need to compare two signals in a digital communication
application.
6. Is the cross correlation between two periodic sequences periodic?

RESULT:

DEPARTMENT OF ECE Page 49


BASIC SIMULATION LAB

Verification of Linearity and Time EXPT. NO:


Invariance Properties of a given
DATE:
Continuous/ Discrete System

AIM: To write a MATLAB program to verify linearity & Time invariance properties of a
given signal.

TOOLS REQUIRED:
System with MATLAB SOFTWARE
PROCEDURE :
• Open MATALB
• Open new M-file
• Type the program
• Save in current directory
• Compile and run the program
• For the output see the command window / figure window
Response of sum of the inputs
PROGRAM:Program1:% 200
clc; clear all;close all;
n=0:40; a=2; b=1; 0

x1=cos(2*pi*0.1*n); -200
0 5 10 15 20 25 30 35 40
x2=cos(2*pi*0.4*n); sum of the Responses of the individual inputs
x=a*x1+b*x2; 200

y=n.*x;
0
y1=n.*x1;
y2=n.*x2; -200
0 5 10 15 20 25 30 35 40
yt=a*y1+b*y2; difference signal
d=y-yt; 1

d=round(d); 0
if sum(abs(d))
disp('Given system does not satisfy -1
0 5 10 15 20 25 30 35 40
the linearity property ');
else Given system satisfies the linearity property
disp('Given system satisfies the
linearity property ');
end
subplot(3,1,1), stem(n,y);
title('Response of sum of the
inputs')
grid;
subplot(3,1,2), stem(n,yt);
title('sum of the Responses of the
individual inputs')
grid;
subplot(3,1,3), stem(n,d);
title('difference signal');grid;

DEPARTMENT OF ECE Page 50


BASIC SIMULATION LAB

%Program2:% 40
Response of sum of the inputs

clc;clear all;close all;


n=0:40; a=2; b=-3; 20

x1=cos(2*pi*0.1*n); 0
x2=cos(2*pi*0.4*n); 0 5 10 15 20 25 30 35 40
sum of the Responses of the individual inputs
x=a*x1+b*x2; 0
y=x.^2;
-0.5
y1=x1.^2;
y2=x2.^2; -1
0 5 10 15 20 25 30 35 40
yt=a*y1+b*y2; difference signal
d=y-yt; 40

d=round(d); 20
ifsum(abs(d))
disp('Given system does not satisfy the 0
0 5 10 15 20 25 30 35 40
linearity property ');
else
disp('Given system satisfies the linearity Given system does not satisfy the linearity
property '); property
end
subplot(3,1,1), stem(n,y);
title('Response of sum of the inputs')
grid;
subplot(3,1,2), stem(n,yt); title('sum of
the Responses of the individual
inputs')
grid;
subplot(3,1,3), stem(n,d);
title('difference signal');
grid;

%Program3:%
clc;close all;clear all;
n=0:40;
D=10;
x=3*cos(2*pi*0.1*n)-
2*cos(2*pi*0.4*n);
xd=[zeros(1,D), x];
y=n.*xd(n+D);
n1=n+D;
x1=3*cos(2*pi*0.1*n1)-
2*cos(2*pi*0.4*n1);
yd=n1.*x1;
d=y-yd;
d=round(d);
ifsum(abs(d))
Given system is time variant

DEPARTMENT OF ECE Page 51


BASIC SIMULATION LAB

disp('Given system is time


variant');
else
disp('Given system is time
invariant');
end
subplot(3,1,1),stem(y),grid;
title('response of the delayed
input');
subplot(3,1,2),stem(yd),grid;
title('Delayed output');
subplot(3,1,3),stem(d),grid;
title('difference signal');

OUTPUT

VIVA VOCE QUESTIONS:


1. Classify the discrete time systems.
2. State the principle of superposition in words.
3. Define an LTI system.
4. Can you really work with time variant systems, in reality?
5. Give an example for both linear and the non linear systems.

RESULT:

DEPARTMENT OF ECE Page 52


BASIC SIMULATION LAB

EXPT. NO:
SAMPLING THEOREM VERIFICATION
DATE:

AIM: To write a MATLAB program to compute sampling theorem verification.

TOOLS REQUIRED:
System with MATLAB SOFTWARE

PROCEDURE :

• Open MATALB
• Open new M-file
• Type the program
• Save in current directory
• Compile and run the program
• For the output see the command window / figure window

PROGRAM:

%sampling theorem%
clc;clear all;close all;
t=0:0.001:1;
f=8;
x=cos(2*pi*f*t);
plot(t,x); title('Original Signal');
%when fs>2fm%
fs1=8*f;
ts1=1/fs1;
n1=0:ts1:1;
xs1=cos(2*pi*f*n1);
figure;
plot(n1,xs1,'r'); title('Over sampled signal');
hold on;
plot(t,x);
hold off;
%when fs=2fm%
fs2=2*f;
ts2=1/fs2;
n2=0:ts2:1;
xs2=cos(2*pi*f*n2);
figure;
plot(n2,xs2,'r');title('Critical sampled signal');
hold on;
plot(t,x);

DEPARTMENT OF ECE Page 53


BASIC SIMULATION LAB

Waveforms:

DEPARTMENT OF ECE Page 54


BASIC SIMULATION LAB

hold off;
%when fs<2fm%
fs3=1.7*f;
ts3=1/fs3;
n3=0:ts3:1;
xs3=cos(2*pi*f*n3);
figure;
plot(n3,xs3,'r'); title('Under sampled signal');
hold on;
plot(t,x);
hold off;

OUTPUT

VIVA VOCE QUESTIONS:


1. Define sampling theorem.
2. Name a few advantages of DSP over the analog signal processing?
3. What is meant by tolerance of a component?
4. What does the sampler do?
5. What is aliasing?
6. What is Nyquist plot?
7. What is an anti-aliasing filter? Why it is called so
RESULT:

DEPARTMENT OF ECE Page 55


BASIC SIMULATION LAB

Waveforms:

DEPARTMENT OF ECE Page 56


BASIC SIMULATION LAB

EXPT. NO:
LPF & HPF
DATE:

AIM: To write a MATLAB program to find magnitude and phase response of first order low
pass and high pass filter. Also plot the responses in logarithmic scale.

TOOLS REQUIRED:
System with MATLAB SOFTWARE

PROGRAM
lpFilt = designfilt('lowpassfir','PassbandFrequency',0.4,...
'StopbandFrequency',0.6,'PassbandRipple',1,...
'StopbandAttenuation',80,...
'DesignMethod','equiripple');
hfvt = fvtool(lpFilt);
hpFilt = designfilt('highpassfir','StopbandFrequency',0.25, ...
'PassbandFrequency',0.35,'PassbandRipple',0.5, ...
'StopbandAttenuation',65,'DesignMethod','equiripple');
fvtool(hpFilt)

VIVA VOCE QUESTIONS:

1. Define Bandwidth
2. What is a low pass filter?
3. What is a high pass filter?
4. Define passband
5. Define transition band

RESULT:

DEPARTMENT OF ECE Page 57


BASIC SIMULATION LAB

EXPT. NO:
Speech Signal Processing
DATE:

AIM: To write a MATLAB program to find response of a low pass filter and high pass
filter, when a speech signal is passed through these filters.

TOOLS REQUIRED:
System with MATLAB SOFTWARE
PROCEDURE: -
• Open MATALB
• Open new M-file
• Type the program
• Save in current directory
• Compile and run the program
• For the output see the command window / figure window
PROGRAM: -
clc;clear; close all;
load(fullfile(matlabroot,'examples','signal','strong.mat'))
% soundsc(her,fs), disp('press any key to continue')
% pause
% soundsc(him,fs)
disp('press any key to continue')
soundsc(her,fs);pause,
x = her';
y=x+.25*rand(1,length(x));
z=y';soundsc(z,fs);pause,
lp=fir1(50,.35,'low');figure,freqz(lp)
lpf=filter(lp,[10 1],y);
soundsc(lpf',fs);pause
hp = fir1(50,.35,'high');figure,freqz(hp)
hpf=filter(hp,3,y);
soundsc(hpf',fs);
figure
subplot(4,1,1);plot(x),title('original "strong" ')
subplot(4,1,2);plot(z),title('noisy signal ')
subplot(4,1,3);plot(lpf'),title('LPF output ')

DEPARTMENT OF ECE Page 58


BASIC SIMULATION LAB

subplot(4,1,4);plot(hpf'),title('HPF output')
Output Waveforms:
Speech Signal-Saying the Word-“Strong”

DEPARTMENT OF ECE Page 59


BASIC SIMULATION LAB

VIVA VOCE QUESTIONS:


1. What is frequency range of Speech Signal?
2. What is Noise?
3. Define Magnitude Spectrum
4. What is a Filter?

RESULT:

DEPARTMENT OF ECE Page 60


BASIC SIMULATION LAB

EXPT. NO:
GENERATION OF GAUSSIAN NOISE
DATE:

AIM: To Generate Gaussian Noise and to compute its Mean, M.S. Values, Skew, kurtosis,
PS and PDF.

TOOLS REQUIRED:
System with MATLAB SOFTWARE
PROCEDURE:-

• Open MATALB
• Open new M-file
• Type the program
• Save in current directory
• Compile and run the program
• For the output see the command window / figure window

PROGRAM:-
clear all; clc; close all;
L=100000; %Sample length for the random signal
X=wgn(1,L,-6,'complex');%-6dB power
subplot(4,1,1)
plot(real(X));
v=var(X);
mu=mean(X);
sigma=std(X);
ms=mean(X.^2);
sk=skewness(X);
krt=kurtosis(X);
title(['White noise : \mu_x=',num2str(mu),' \sigma^2=',num2str(sigma^2)])
xlabel('Samples')
ylabel('Sample Values')
subplot(4,1,2)
plot(imag(X));
grid on;
n=100; %number of Histrogram bins
[f,x]=hist(real(X),n);
subplot(4,1,3),bar(x,f/trapz(x,f)); hold on;
%Theoretical PDF of Gaussian Random Variable
g=(1/(sqrt(2*pi)*sigma))*exp(-((x-mu).^2)/(2*sigma^2));
plot(x,g,'r','linewidth',2);hold off; grid on;
title('Theoretical PDF and Simulated Histogram of White Gaussian Noise');
legend('Histogram','Theoretical PDF');
xlabel('Bins'); ylabel('PDF f_x(x)');
xdft=fft(X);
xpsd=10*log10(abs(fftshift(xdft)));

DEPARTMENT OF ECE Page 61


BASIC SIMULATION LAB

norm_freq=linspace(-0.5, 0.5, length(X));


subplot(4,1,4), plot(norm_freq,xpsd); title('Power Spectral Density');
fprintf('\n Mean =%2.4f \n',mu);
fprintf('\n Variance =%2.4f \n',sigma^2);
fprintf('\n Mean Square Value =%2.4f \n',ms);
fprintf('\n Skewness =%2.4f \n',sk);
fprintf('\n Kurtosis =%2.4f \n',krt);

OUTPUT:
Mean =
Variance =
Mean Square Value =
Skewness =
Kurtosis =

White noise : x =0.0047289  2=1.0002


5
Sample Values

-5
0 1 2 3 4 5 6 7 8 9 10
Samples 4
x 10
Theoretical PDF and Simulated Histogram of White Gaussian Noise
0.8
Histogram
0.6 Theoretical PDF
PDF f (x)
x

0.4

0.2

0
-5 -4 -3 -2 -1 0 1 2 3 4 5
Bins
Power Spectral Density
40

20

-20
-0.5 -0.4 -0.3 -0.2 -0.1 0 0.1 0.2 0.3 0.4 0.5

VIVA VOCE QUESTIONS:


1. What are the different types of noises present in communication systems?
2. Give the formulae to calculate mean, variance, skewness and kurtosis?
3. What is the significance of the parameters variance, skewness and
kurtosis?
4. Distinguish between Probability Density Function and Probability
Distribution functions.

RESULT:

DEPARTMENT OF ECE Page 62


BASIC SIMULATION LAB

EXPT. NO:
Random Bipolar Data Generation
DATE:

AIM: To write a MATLAB program to find response of a low pass filter and high pass
filter, when a speech signal is passed through these filters.

TOOLS REQUIRED:
System with MATLAB SOFTWARE
PROCEDURE: -
• Open MATALB
• Open new M-file
• Type the program
• Save in current directory
• Compile and run the program
• For the output see the command window / figure window
PROGRAM: -
clc;clear;close all;
tic;h = randi([0 1],1,100);toc
disp('The random Binary Sequence is:')
disp(h)
clf;tic
n=1;
l=length(h);
h(l+1)=1;
while n<=length(h)-1;
t=n-1:0.001:n;
if h(n) == 0
if h(n+1)==0
y=-(t<n-0.5)-(t==n);
else
y=-(t<n-0.5)+(t==n);
end
d=plot(t,y);grid on;
title('Line code BIPOLAR RZ');
set(d,'LineWidth',2.5);
hold on;
axis([0 length(h)-1 -1.5 1.5]);
else
if h(n+1)==0
%y=(t>n-1)-2*(t==n);
y=(t<n-0.5)-1*(t==n);
else
%y=(t>n-1)+(t==n-1);
y=(t<n-0.5)+1*(t==n);
end
%y=(t>n-1)+(t==n-1);

DEPARTMENT OF ECE Page 63


BASIC SIMULATION LAB

Waveforms:

DEPARTMENT OF ECE Page 64


BASIC SIMULATION LAB

d=plot(t,y);grid on;
title('Line code BIPOLAR RZ');
set(d,'LineWidth',2.5);
hold on;
axis([0 length(h)-1 -1.5 1.5]);
end
n=n+1;
%pause;
end
toc

OUTPUT:

VIVA QUESTION
1. What is data rate?
2. What is baud rate?
3. Define Data
4. What is Line Coding?

RESULT

DEPARTMENT OF ECE Page 65


BASIC SIMULATION LAB

Waveforms:

DEPARTMENT OF ECE Page 66


BASIC SIMULATION LAB

EXPT. NO:
Pole-Zero Diagram
DATE:

AIM: To write a MATLAB program to plot pole-zero diagram in S-plane/Z-plane of given


signal/sequence and verify its stability.

TOOLS REQUIRED:
System with MATLAB SOFTWARE
PROCEDURE: -
• Open MATALB
• Open new M-file
• Type the program
• Save in current directory
• Compile and run the program
• For the output see the command window / figure window
PROGRAM: -
clc;
close all;
clear all;
N=[10 20 0];
D=[1 7 20 28 19 5];
G=tf(N,D)
P=pole(G)
Z=zero(G)
figure;
pzmap(G);
grid on;
if (real(P)<0)
disp('System is stable');
else
disp ('system is unstable');
end

OUTPUT

DEPARTMENT OF ECE Page 67


BASIC SIMULATION LAB

POLE-ZERO PLOT

DEPARTMENT OF ECE Page 68


BASIC SIMULATION LAB

VIVA QUESTION:
1. What is transfer function?
2. Define stability of a System.
3. How stability can be identified using pole-zero plot
4. ROC properties of Laplace transform
5. ROC properties of Z-transform

RESULT:

DEPARTMENT OF ECE Page 69

You might also like