function [p m] = correlation_f(x, y)
if nargin == 0
t = 0.01:0.01:2*pi;
x = sin(t);
y = sin(t+pi/2);
end
if nargin == 1
y = x;
end
nlength = length(x);
m = fix(nlength/4);
% initialized data
p(2*m+1) = 0;
for i = -m:m;
if i <= 0
n_x = -i+1:nlength;
n_y = 1:nlength+i;
else
n_x = 1:nlength-i;
n_y = i+1:nlength;
end
pdenominator = sqrt(sum(x(n_x).^2)*sum(y(n_y).^2));
p(i+m+1) = sum(x(n_x).*y(n_y))/pdenominator;
end
% plot(-m:m,p)
恰好有自相关函数的求取代码,另一个问题就不知道了。