AUTO AND CROSS- CORRELATION OF SIGNAL, NOISE AND NOISY SIGNAL
clear all; clc; close all
%Auto correlation and cross correlation fumctions
N = 96;
n = 1 : N;
x = cos(0.25 *pi *n);
rx = conv(x,fliplr(x));
disp('ACF of X=')
min(min(corrcoef(x,x)))
k = -28 : 28;
subplot(3,1,1);
stem(k,rx(68 : 124));
xlabel(' log index');
ylabel(' Amplitude');
title(' clean signal ACF');
w=rand(1,N)-0.5;
y=x+w;
ry=conv(y,fliplr(y));
disp('ACF of Y=')
min(min(corrcoef(y,y)))
subplot(3,1,2);
stem (k,ry(68 : 124));
xlabel(' log index');
ylabel(' Amplitude');
title (' clean signal ACF');
rw=conv(w,fliplr(w));
disp('ACF of W=')
min(min(corrcoef(w,w)))
subplot(3,1,3);
stem(k,rw(68 : 124));
xlabel(' log index');
ylabel(' Amplitude');
title(' clean signal ACF');
rxw=conv(x,fliplr(w));
disp('CCF of X with W=')
min(min(corrcoef(x,w)))
figure
subplot (3,1,1);
stem (k,rxw(68 : 124));
xlabel(' log index');
ylabel(' Amplitude');
title (' X with W');
rxy=conv(x,fliplr(y));
disp('CCF of X with Y=')
min(min(corrcoef(x,y)))
subplot (3,1,2);
stem (k,rxy(68 : 124));
xlabel(' log index');
ylabel(' Amplitude');
title (' X with Y');
ryw=conv(y,fliplr(w));
disp('ACF of Y with W=')
min(min(corrcoef(y,w)))
subplot (3,1,3);
stem (k,rxy(68 : 124));
xlabel(' log index');
ylabel(' Amplitude');
title (' Y with W');
LTI SYSTEM PLOT USING ZERO-POLE-GAIN TRANSFER FUNCTION
clear all; clc; close all
% for IIR butterworth LPF of order 3 and .5 cut off
[z,p,k] = butter(3,.5);
h=zpk(z,p,k); tf(h)
[num,den] = tfdata(h,'v')
% [b,a] = butter(3,.5)
[h,w]=freqz(num,den,2^8);% considering 8 bits
plot(w/(2*pi),20*log10(h))
title('LTI response plot')
figure
subplot(2,1,1), plot(abs(h))
title('magnitude')
axis tight
subplot(2,1,2), plot(w*360/(2*pi))
title('Phase converted to degree')
axis tight
DISCRETE FOURIER TRANSFORM
clear all; clc; close all
%Simple DFT without using the FFT algo of MATLAB
N = 256;
n = 1: N;
xn = cos(0.2 *pi *n);
figure(1);
plot(n,xn);
wn = exp(-j* pi/N);
g= 1;
for k = 1: N,
n= 1:N;
xk(g,1) =xn * (wn * ones(N,1)).^(n' * k);
g = g +1;
end
X1 = abs(xk);
figure(2);
plot(n/(2*N),X1/max(X1));
grid;
axis([0,0.5,0,1]);
title('DFT');
xlabel('Frequency in pi unit');
ylabel('Mag');
COMPARISON OF THE dft USING THE EQUATION AND USING MATLAB’S IN BUILT FFT BASED DFT
clear all; clc; close all
%comparing DFT with the in built FFT of MATLAB
N = 256;
n = 1 : N;
xn = cos(0.2 *pi *n);
figure(1);
plot(n,xn);
M=N;
m=0:(M-1);
y = fft(xn,M);
magy=abs(y);
wn = exp(-j* pi/N);
g= 1;
for k = 1: N,
n= 1:N;
xk(g,1) =xn*(wn*ones(N,1)).^(n'*k);
g = g +1;
end
X1 = abs(xk);
figure(2);
subplot(2,1,1);
plot(n/(2*N),X1/max(X1));
grid;
axis([0,0.5,0,1]);
title('DFT');
xlabel('Frequency in pi unit');
ylabel('Mag');
subplot(2,1,2);
plot(m/M,magy/max(magy));
grid;
axis([0,0.5,0,1]);
title('DFT with fft function');
xlabel('Frequency in pi unit');
ylabel('Mag');
COMPARISON OF MULTIPLICATION IN FREQUENCY DOMAIN WITH CONVOLUTION IN TIME DOMAIN
clear all; clc; close all
%showing multiplication in frequency is convolution in time
x=[1 2 3 4];%1st sequence
h=[1 2 1 2];%2nd sequence
l=length(x)+length(h)-1;%length of convolution o/p
xe=fft(x,l);%fft of 1st squence using zero padding
he=fft(h,l);%fft of 2nd squence using zero padding
y1=ifft(xe.*he);%ifft of the prodct of two sequences
y2=conv(x,h);% normal covoluton o/p
error=y1-y2;%error between the two convolutions
k=0:l-1;
subplot(3,1,1),stem(k,y1);
subplot(3,1,2),stem(k,y2);
subplot(3,1,3),stem(k,abs(error));
No comments:
Post a Comment