📄 crosscor.m
字号:
function z = crosscor (x,y)
%-----------------------------------------------------------------------
% Usage: z = crosscor (x,y)
%
% Description: Compute the normalized cross-correlation of two
% discrete-time signals.
%
% Inputs: x = n by 1 vector containing samples of first signal
% y = m by 1 vector containing samples of second signal
% where m <= n.
%
% Outputs: z = n by 1 vector containing normalized cross-correlation
% of x with y.
%
% Note: The auto correlation of a signal x is just the cross
% correlation of x with x.
%-----------------------------------------------------------------------
% Initialize
chkvec (x,1,'crosscor');
chkvec (y,2,'crosscor');
n = length(x);
m = length(y);
if m > n
disp ('Argument 2 of crosscor can not be longer than argument 1');
return
end;
% Compute DFTs of x(k) and y(k), pad y with (n-m) zeros
Y = zeros(n,1);
Y(1:m) = y;
X = dft (x,1);
Y = dft (Y,1);
% Compute inveres DFT of X(m)conj(Y(m)) */
X = X .* conj(Y);
z = real(dft (X,-1));
% Normalize
a = dot(x,x);
b = dot(y,y);
c = sqrt(a)*sqrt(b);
z = z/c;
%-----------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -