Matrix dimensions must agree when doing an elementwise operation

Hello, I would like to compute the product of two Fourier transform with the following code :
Fe=8000;
Te=1/Fe;
N=Fe;
t=0:Te:(N-1)*Te;
T=0.02;
x=1+square(2*pi*t/T);
K=10;
h=ones(1,K)/K;
y=conv(x,h);
Npts=Fe*T;
X=fft(x);
H=fft(h);
Y=fft(y);
prod=X.*H;
conv=fft(conv(x,h,'same'));
The objective here is to show that fft(h)*fft(x)= fft(conv(x,h)).
The problem is that even if I use the elementwise operator I get this error :
This is surely because of the size of the vector h, could anyone explain me what's wrong ?

1 件のコメント

Torsten
Torsten 2022 年 4 月 11 日
X has 8000, H has 10 elements. There is no way to multiply the arrays.

サインインしてコメントする。

回答 (1 件)

Esha Chakraborty
Esha Chakraborty 2022 年 4 月 14 日

0 投票

Hi Adrien,
I understand that you are encountering the error - 'Matrix dimensions must agree', while performing element-wise matrix multiplcation of X and H variables in your code.
Please note that for matrix multiplcation, the sizes of X and H must be the same or be compatible. You can find more details on array size compatibility in the documentation here.

1 件のコメント

Adrien Sallé
Adrien Sallé 2022 年 4 月 18 日
Its way clearer now,
Thank you very much !

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeFourier Analysis and Filtering についてさらに検索

製品

リリース

R2020a

質問済み:

2022 年 4 月 11 日

コメント済み:

2022 年 4 月 18 日

Community Treasure Hunt

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

Start Hunting!

Translated by