PRACTICAL MATLAB® FOR ENGINEERS PRACTICAL MATLAB

(sharon) #1

DTFT, DFT, ZT, and FFT 535


figure(2)
corr = xcorr(f1n,f2n);
N= length (corr);
m = 0:1:N-1;
subplot (3,1,1)
stem(m,corr);title(‘Convolution and correlation plots’);
ylabel(‘Amplitude’);
subplot(3,1,2)
conv1=conv(f1n,f2n _ rev);
stem(m,conv1)
xlabel(‘time index n’);ylabel(‘Amplitude’);
subplot(3,1,3)
conv2=conv(f1n _ rev,f2n);
stem(m,conv2);
xlabel(‘time index n’);ylabel(‘Amplitude’);

figure(3) % auto-correlations
mm=-31:31;
aut _ corr1=xcorr(f1n,f1n);aut=xcorr(f1n);
aut _ corr2=xcorr(f2n,f2n);
plot(mm,aut _ corr1,mm,aut _ corr2,mm,aut);
title(‘Auto-correlation plots’);
ylabel(‘Amplitude’);
legend(‘R11’,’R22’,’R1’)

figure(4) % frequency analysis
DFT _ corr = fft(corr,256);
DFT _ f1n = fft(f1n,256);
DFT _ f2n = fft(f2n,256);
DFT _ 12 = conj(DFT _ f1n).*DFT _ f2n;
k=1:1:256;
subplot (2,1,1)
plot (k/256,abs(DFT _ 12));title(‘abs[conj[fft(f1n)]*fft(f2n)] vs. W ’)
ylabel(‘Magnitude’)
subplot(2,1,2)
plot(k/256,abs(DFT _ corr));title(‘abs[fft(xcorr(f1(n),f2(n)))] vs. W’)
xlabel(‘W’); ylabel(‘Magnitude’)

figure(5)
subplot (2,1,1)
error1 = corr-conv1;
bar(m,error1);title(‘error1=corr[f1(n),f2(n)]-conv[f1(n),f2(-n)]’)
ylabel(‘Amplitude’);
subplot(2,1,2)
error2 = abs(abs(corr)-abs(conv2));
bar(m,error2)
title (‘error2=abs[abs[corr[f1(n),f2(n)]]-abs[conv[f1(-n),f2(n)]]]’)
xlabel (‘time index n’); ylabel(‘Amplitude’)

The script fi le conv_corr is executed, and the results are as follows:

>> conv _ corr
Free download pdf