Matrix Dimensions Must Agree Error for Cross Correlation

1 次查看(过去 30 天)

clear;
clc;
close all;
%x
n = 1:200;
phi = 0;
x_n = (cos(pi*n/15) + phi);
%e
N = 200;
e_n = 30*(rand(N,1)-0.5);
%x+e
x_ne = x_n + e_n;
%h depending upon which K value is used
n1 = 0:10;
h_n1 = cos(pi*n1/15);
n2 = 0:20;
h_n2 = cos(pi*n2/15);
n3 = 0:40;
h_n3 = cos(pi*n3/15);
n4 = 0:80;
h_n4 = cos(pi*n4/15);
%correlation length
corr1 = length(x_ne)+length(h_n1)-1;
corr2 = length(x_ne)+length(h_n2)-1;
corr3 = length(x_ne)+length(h_n3)-1;
corr4 = length(x_ne)+length(h_n4)-1;
%cross correlation
y1 = fftshift(ifft(fft(x_ne,n).*conj(fft(h_n1,corr1))))
y2 = fftshift(ifft(fft(x_ne,n).*conj(fft(h_n2,corr2))));
y3 = fftshift(ifft(fft(x_ne,n).*conj(fft(h_n3,corr3))));
y4 = fftshift(ifft(fft(x_ne,n).*conj(fft(h_n4,corr4))));
%plotting each y
subplot(4,1,1)
stem(n1, y1)

subplot(4,1,2)
stem(n2, y2)

subplot(4,1,3)
stem(n3, y3)

subplot(4,1,4)
stem(n4, y4)

回答(1 个)

Ankit Kumar
Ankit Kumar 2019-10-24
Hi William,
In your code
y1 = fftshift(ifft(fft(x_ne,n).*conj(fft(h_n1,corr1))))
Here the two arrays are not compatible for multiplication. See this for compatible array sizes,
Also in fft(x_ne,n) you are not giving n as a scalar whereas n should be specified as [] or a nonnegative integer scalar. Refer to this,

标签

产品


版本

R2019a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by