?? f_corr.asv
字號:
function r = f_corr (x,y,circ,norm)
% F_CORR: Fast cross-correlation of two discrete-time signals
%
% Usage: r = f_corr (x,y,circ,norm)
%
% Entry: x = vector of length L containing first signal
% y = vector of length M <= L containing second signal
% circ = correlation type code:
%
% 0 = linear correlation
% 1 = circular correlation
%
% norm = normalization code:
%
% 0 = no normalization
% 1 = normalized cross-correlation
%
% Exit: r = vector of length L contained selected cross-
% correlation of x with y.
%
% Notes: To compute auto-correlation use y = x.
%
% See also: f_conv
% Initialize
L = length(x);
M = length(y);
if M > L
fprintf ('\nThe length of argument 2 of fcorr exceeds the length')
fprintf ('\nof argument 1.\n')
f_wait
return;
end
if circ
% Compute circular cross-correlation
if M ~= L
fprintf ('\nThe length of argument 2 of fcorr must equal the length')
fprintf ('\nof argument 1 for a circular cross-correlation.\n')
f_wait
return;
else
X = fft(f_tocol(x),L);
Y = fft(f_tocol(y),L);
s = ifft(X .* conj(Y))/L;
r = real(s);
else
% Compute linear cross-correlation
N = 2^ceil(log(L+M-1)/log(2));
X = fft(f_tocol(x),N);
Y = fft(f_tocol(y),N);
s = ifft(X .* conj(Y))/L;
r = real(s(1:L));
% Normalize
if norm
P_x = sum(x .^ 2)/L;
P_y = sum(y .^ 2)/M;
r = r/sqrt((M/L)*P_x*P_y);
end
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -