MATLAB

PROGRAMS



Program 1: Verification Of Sampling Theorem.


clc;
T=0.04;                        % Time Period Of 50Hz Signal
t= 0:0.0005:0.02;
f=1/T;
n1=0:40;
size(n1)
x1=sin(2*pi*2*t/T);
subplot(2,2,1);
plot(200*t,x1);
title('Verification of Sampling Theorem');
title('continuous Signal');
xlabel('t');
ylabel('X(n)');
t1=0.002;                     % Greater Than Nyquist Rate
t2=0.01;                       % Equal To Nyquist Rate
t3=0.1;                         % Less Than Nyquist Rate
n=0:20;
x1=2*sin(2*pi*n*t1/T);
subplot (2,2,2);
stem(n,x1);
title('Greater Than Nyquist Rate');
xlabel('n');
ylabel('x(n)');


n=0:4;
x2=2*sin(2*sym('pi')*n*t2/T);
subplot(2,2,3);
stem(n,x2);
title('Equal To Nyquist Rate');
xlabel('n');
ylabel('x(n)');

n=0:10;
x3=2*sin(2*pi*n*t3/T);
subplot(2,2,4);
stem(n,x3)
title('Less Than Nyquist Rate');
xlabel('n');
ylabel('x(n)');



RESULT:














Program 2: Linear Convolution Of Two Sequences Using CONV Command.


clc;
x1=input('Enter The First Sequence');
subplot(3,1,1);
stem(x1);
ylabel('Amplitude');
title('Plot Of The 1st Sequence');
x2=input('Enter The 2nd Sequence');
subplot(3,1,2);
stem(x2);
ylabel('Amplitude');
title('Plot Of 2nd Sequence');
f=conv(x1,x2);
disp('Output Of Linear Convolution Is');
disp(f);
xlabel('Time Index n');
ylabel('Amplitude f');
subplot(3,1,3);
stem(f);
title('Linear Convolution Sequence Is');



RESULT:

enter the first sequence[1 2 3]
enter 2nd sequence[1 2 3 4]
output of linear conv is
1 4 10 16 17 12






 Program 3: Impulse Response Of a Given System.

clc;
clear all;
close all;

% Difference Equation Of Second Order System Is Given as
% y(n)=x(n)+0.5x(n-1)+0.85x(n-2)+y(n-1)+y(n-2)

a=input('Enter The Co-efficients Of x(n),x(n-1)....');
b=input('Enter The Co-efficients of y(n),y(n-1)....');
N=input('Enter The Number Of Samples Of Impulse Response');
[h,t]=impz(b,a,N);
plot(t,h);
title('Plot Of Impulse Response');
ylabel('Amplitude');
xlabel('Time Index n');
disp(h);
grid on;





RESULT:
enter the coefficients of x(n),x(n-1)-----[1 0.5 0.85]
enter the coefficients of y(n),y(n-1)-----[1 -1 -1]
enter the number of samples of imp response 4
1.0000
1.5000
3.3500
4.8500


Calculation
y(n) = x(n)+0.5x(n-1)+0.85x(n-2)+y(n-1)+y(n-2)
y(n) - y(n-1) - y(n-2) = x(n) + 0.5x(n-1) + 0.85x(n-2)
Taking Z transform on both sides,
Y(Z) – Z-1 Y(Z)- Z-2 Y(Z) = X(Z) + 0.5 Z-1 X(Z) + 0.85 Z-2 X(Z)
Y(Z)[1 - Z-1 - Z-2] = X(Z)[1 + 0.5 Z-1 + 0.85 Z-2 ]
But, H(Z) = Y(Z)/X(Z)
= [1 + 0.5 Z-1 + 0.85 Z-2 ]/ [1 - Z-1 - Z-2]
By dividing we get
H(Z) = 1 + 1.5 Z-1 + 3.35 Z-2 + 4.85 Z-3
h(n) = [1 1.5 3.35 4.85]




Program 4: Linear Convolution Using DFT and IDFT  OR Linear Convolution Using Circular Convolution.



clc;
clear all;
x1=input('enter the first sequence');
x2=input('enter the second sequence');
n=input('enter the no of points of the dft');
subplot(3,1,1);
stem(x1,'filled');
title('plot of first sequence');
subplot(3,1,2);
stem(x2,'filled');
title('plot the second sequnce');
n1 = length(x1);
n2 = length(x2);
m = n1+n2-1;
% Length of linear convolution
x = [x1 zeros(1,n2-1)];
% Padding of zeros to make it of
% length m
y = [x2 zeros(1,n1-1)];
x_fft = fft(x,m);
y_fft = fft(y,m);
dft_xy = x_fft.*y_fft;
y=ifft(dft_xy,m);
disp('the circular convolution result is ......');
disp(y);
subplot(3,1,3);
stem(y,'filled');
title('plot of circularly convoluted sequence');




RESULT:

enter the first sequence[1 2 1 2 1 2]
enter the second sequence[1 2 3 4]
the circular convolution result is ......
1.0000 4.0000 8.0000 14.0000 16.0000 14.0000
15.0000 10.0000 8.0000









Program 5: Circular Convolution Of Two Given Sequences.


clc;
clear all;
x1=input('enter the first sequence');
x2=input('enter the second sequence');
n1 = length(x1);
n2 = length(x2);
m = n1+n2-1;
subplot(3,1,1);
stem(x1,'filled');
title('plot of first sequence');
subplot(3,1,2);
stem(x2,'filled');
title('plot the second sequnce');
y1=fft(x1,m);
y2=fft(x2,m);
y3=y1.*y2;
y=ifft(y3,m);
disp('the circular convolution result is ......');
disp(y);
subplot(3,1,3);
stem(y,'filled');
title('plot of circularly convoluted sequence');



 RESULT:


enter the first sequence[1 2 3 4]
enter the second sequence[4 3 2 1]
the circular convolution result is ......
24 22 24 30







 Program 6: AutoCorrelation of a Given Sequence And Verification Of Its Properties.



% Read the signal
x=[1,2,3,4,5,6];
% define the axis
n=0:1:length(x)-1;
% plot the signal
stem(n,x);
xlabel('n');
% auto correlate the signal
Rxx=xcorr(x,x);
% the axis for auto correlation results
nRxx=-length(x)+1:length(x)-1;
% display the result
stem(nRxx,Rxx)
% properties of Rxx(0) gives the energy of the signal
% find energy of the signal
energy=sum(x.^2);
%set index of the centre value
centre_index=ceil(length(Rxx)/2);
% Acces the centre value Rxx(0)
Rxx_0=Rxx(centre_index);
Rxx_0=Rxx(centre_index);
% Check if the Rxx(0)=energy
if Rxx_0==energy
disp('Rxx(0) gives energy');
else
disp('Rxx(0) not gives energy');
end
Rxx_right=Rxx(centre_index:1:length(Rxx));
Rxx_left=Rxx(centre_index:-1:1);
if Rxx_right==Rxx_left
disp('Rxx is even');
else
disp('Rxx is not even');
end


 RESULT:

 x = 1 2 3 6 5 4
n = 0 1 2 3 4 5
nRxx = -5 -4 -3 -2 -1 0 1 2 3 4
5
energy = 91
centre_index = 6
Rxx(0) gives energy not proved
Rxx_right =
91.0000 76.0000 54.0000 28.0000 13.0000 4.0000
Rxx_left =
91.0000 76.0000 54.0000 28.0000 13.0000 4.0000
Rxx is even


















No comments:

Post a Comment