📄 ccfdemo.m
字号:
% CCFdemo.m
% Dr Y Yan, 07/03/99, 08/03/01
% School of Engineering, University of Greenwich
clear;clf;
close all;
% create two random signals a(n) and b(n)
N=400; N1=N/2; delay=50;
%for i=1:N+delay, b(i)=2*randn-1; end
%for i=1:N, a(i)=b(i+delay); end
sig=2*rand(1,450)-1;
a=sig(51:450);b=sig(1:400);
%num=0.5;den=[1 -0.7];
%x=filter(num,den,a); y=filter(num,den,b);
%Calculate Rxx0 and Ryy0, Ruu0 and Rdd0
Raa0=sum(a(1:N1).^2); Rbb0=sum(b(1:N1).^2);
%Rxx0=sum(x(1:N1).^2); Ryy0=sum(y(1:N1).^2);
% calculate cross-correlation function 1
for m=1:N1,
r1(m)=0;
for n=1:N1,
r1(m)=r1(m)+a(n)*b(n+m-1);
end;
end
r1=r1/sqrt(Raa0*Rbb0); cc1=max(r1)
%r1=xcorr(b,a,50,'coeff');
%cc1=max(r1);
% calculate cross-correlation function 2
%for m=1:N1,
% r2(m)=0;
% for n=1:N1,
% r2(m)=r2(m)+x(n)*y(n+m-1);
% end;
%end
%r2=r2/sqrt(Rxx0*Ryy0); cc2=max(r2)
% output results
subplot(3,2,1),plot(a(1:N1)),title('x(n)');axis([0,N1,-1,1]);
subplot(3,2,3),plot(b(1:N1)),title('y(n)');axis([0,N1,-1,1]);pause;
subplot(3,2,5),plot(r1),title('Rxy(m)'),
% axis([0,N1,-0.3,1]);
grid on;pause;
%subplot(3,2,2),plot(x(1:N1)),title('x(n)');axis([0,N1,-1,1]);
%subplot(3,2,4),plot(y(1:N1)),title('y(n)');axis([0,N1,-1,1]);pause;
%subplot(3,2,6),plot(r2(1:N1)),title('Rxy(m)'),axis([0,N1,-0.3,1]);pause
% %add some noise in b(i)
% for i=1:N, a(i)=0.6*a(i)+0.4*(2*rand-1); end
% for i=1:N, b(i)=0.6*b(i)+0.4*(2*rand-1); end
%
% % determine the outputs of the low-pass filters
% num=0.5;den=[1 -0.7];
% %x=filter(num,den,a);y=filter(num,den,b);
%
% %Calculate Rxx0 and Ryy0, Ruu0 and Rdd0
% Raa0=sum(a(1:N1).^2); Rbb0=sum(b(1:N1).^2);
% %Rxx0=sum(x(1:N1).^2); Ryy0=sum(y(1:N1).^2);
%
% % calculate cross-correlation function 1
%for m=1:N1,
% r1(m)=0;
% for n=1:N1,
% r1(m)=r1(m)+a(n)*b(n+m-1);
% end;
% end
%r1=r1/sqrt(Raa0*Rbb0);cc3=max(r1)
% r1=xcorr(a,b);
% cc3=max(r1)
% calculate cross-correlation function 2
%for m=1:N1,
% r2(m)=0;
% for n=1:N1,
% r2(m)=r2(m)+x(n)*y(n+m-1);
% end;
%end
%r2=r2/sqrt(Rxx0*Ryy0); cc4=max(r2)
%
% % output results
% subplot(3,2,1),plot(a(1:N1)),title('x(n)');axis([0,N1,-1,1]);grid on;
% subplot(3,2,3),plot(b(1:N1)),title('y(n)');axis([0,N1,-1,1]);grid on;pause;
% subplot(3,2,5),plot(r1(1:N1)),title('Rxy(m)'),
% axis([0,length(r1),-0.3,cc3]);
% grid on;pause;
% subplot(3,2,5),plot(r1(1:N1)),title('Rxy(m)'),axis([0,N1,-0.3,1]);grid on;pause;
%subplot(3,2,2),plot(x(1:N1)),title('x(n)');axis([0,N1,-1,1]);
%subplot(3,2,4),plot(y(1:N1)),title('y(n)');axis([0,N1,-1,1]);pause;
%subplot(3,2,6),plot(r2(1:N1)),title('Rxy(m)'),axis([0,N1,-0.3,1]);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -