⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 f_corr.asv

📁 DSP程序 Matlab是一套用于科学工程计算的可视化高性能语言与软件环境。它集数值分析、矩阵运算、信号处理和图形显示于一体
💻 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 + -