我试图在matlab中绘制一个标准化的互相关,但我不确定代码是否正确,因为我继续收到错误说“在一个赋值A(:) = B中,A和B中的元素数量必须是相同。”请问我怎么能纠正这个?
%cross correlation
if length(s1_filtered)>length(s2_filtered)
pad = length(s1_filtered)-length(s2_filtered);
s2_filtered = [s1_filtered zeros(1,pad)];
elseif length(s1_filtered)<length(s2_filtered)
pad = length(s2_filtered)-length(s1_filtered);
s1_filtered= [s2_filtered zeros(1,pad)];
end
out_length = length(s1_filtered);
out = zeros(1,out_length);
denom = zeros(1,out_length);
for k = 1:out_length
out(k) = s1_filtered*s2_filtered';
s2_filtered = [0 s2_filtered(1:end-1)];
end
for a = 1:out_length
denom(a) = sqrt(s1_filtered.^2).* sqrt(s2_filtered.^2);
s2_filtered = [0 s2_filtered(1:end-1)];
end
crossc=out(k)/denom(a);
figure(8);
plot(crossc);
title('CROSS CORRELATION OF S1 AND S2');