BS Lab Manual
BS Lab Manual
INDEX
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
4 Even and Odd Parts of a Sequence &Real and Imaginary Parts of a Sequence * 22-25
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:
IMPORTANCE OF MATLAB:
• 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.
• 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 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.
CONCLUSION:
Introduction to MATLAB is studied successfully.
EXPT. NO:
BASIC
➢ OPERATIONS ON MATRICES
DATE:
AIM: To write a MATLAB program for generating various Signals and Sequences
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
RESULT:
AIM: To write a MATLAB program for generating various Signals and Sequences
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');
%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');
%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');
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');
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');
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');
RESULT:
Waveforms:
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')
Waveforms:
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 :
Waveforms:
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');
Waveforms:
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 :
RESULT:
Waveforms:
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);
Waveforms:
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:
RESULT:
Waveforms:
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
Waveforms:
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');
Waveforms:
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.
• 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;
Waveforms:
Waveforms:
AIM:
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;
Waveforms:
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:
Waveforms:
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:
xlabel('frequency');
ylabel('amplitude');
title('phasespectrum of a input signal');
grid;
OUTPUT:
Input Signal
RESULT:
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)
OUTPUT:-
A. For Discrete sequences
RESULT:
AIM: To write a MATLAB program to compute Auto Correlation and Cross Correlation
between Signals of two given sequences
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)
Expected OUTPUT:
For Discrete sequences:
Enter the first sequence x[n] =
Enter the first sequence y[n] =
Autocorrelation of x(n) is
RESULT:
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;
%Program2:% 40
Response of sum of the inputs
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
OUTPUT
RESULT:
EXPT. NO:
SAMPLING THEOREM VERIFICATION
DATE:
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);
Waveforms:
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
Waveforms:
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)
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:
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 ')
subplot(4,1,4);plot(hpf'),title('HPF output')
Output Waveforms:
Speech Signal-Saying the Word-“Strong”
RESULT:
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)));
OUTPUT:
Mean =
Variance =
Mean Square Value =
Skewness =
Kurtosis =
-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
RESULT:
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);
Waveforms:
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
Waveforms:
EXPT. NO:
Pole-Zero Diagram
DATE:
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
POLE-ZERO PLOT
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: