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

📄 autocorr.m

📁 calculate the correlation and convolution
💻 M
字号:
%genertate the autocorrelation with two approaches..
%Programmed by Benjamin.Frank, 19-Feb-2009

function y = autocorr(x)

x = randn(1,20);
%the first method
N = length(x);
M = 10;
Rx = zeros(1,M+1);
for m=1:M+1,
    for n=1:N-M+1
        Rx(m) = Rx(m)+x(n)*x(n+m-1);
        Rx(m) = Rx(m)/(N-m+1);
    end
end

%the second method..
N=length(x);
L=M+1;
x1=zeros(N+L-1,1);
x2=x1;
x=x-mean(x);
x1(1:N,1)=x;
for k=1:L
	x2=zeros(N+L-1,1);
	x2(k:N+k-1,1)=x;
	r(k)=x1'*x2;
end
r=r/N;

if 1,
    stem(Rx);
    hold on
    stem(r);
end


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -