필터 지우기
필터 지우기

Matrix Dimensions Must Agree Error for Cross Correlation

조회 수: 1 (최근 30일)
William Braxton
William Braxton 2019년 10월 21일
답변: Ankit Kumar 2019년 10월 24일

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,

카테고리

Help CenterFile Exchange에서 Subplots에 대해 자세히 알아보기

태그

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by