Incorrect Dimensions for Matrix Multiplication in DFT script

I'm writing a DFT script and I keep running up agains this problem where my matrix multiplication is erroring out due to their matrix sizes. One is 1x1000 and the other is 500 x 500.
Here is the code below.
clc;
clear all;
close all;
t = 0:1/100:10-1/100; % Time vector
xn = 5 + 2*cos(2*pi*t-pi/2) + 3*cos(2*pi*4*t); %Signal in Time domain
N = 500; % length of data points
for k=0:N-1
for n=0:N-1
Wn=exp(-j*2*pi*k*n/N);
X1(k+1,n+1)=Wn;
end
end
Xk = X1*xn';

 採用された回答

KALYAN ACHARJYA
KALYAN ACHARJYA 2019 年 7 月 16 日
編集済み: KALYAN ACHARJYA 2019 年 7 月 16 日

0 投票

What I did?
For matrix multiplication, the number of columns in first matrix must be equal to the number of rows in second matrix, hence I try to satisfy the issue by changing N=500 to N=1000
t = 0:1/100:10-1/100; % Time vector
xn = 5 + 2*cos(2*pi*t-pi/2) + 3*cos(2*pi*4*t); %Signal in Time domain
N = 1000; % length of data points
X1=zeros(N,N);
for k=0:N-1
for n=0:N-1
Wn=exp(-j*2*pi*k*n/N);
X1(k+1,n+1)=Wn;
end
end
Xk=X1*xn';

2 件のコメント

madhan ravi
madhan ravi 2019 年 7 月 16 日
Preallocate X1.
KALYAN ACHARJYA
KALYAN ACHARJYA 2019 年 7 月 16 日
編集済み: KALYAN ACHARJYA 2019 年 7 月 16 日
#Edited @Madhan I am Sorry, ohh God..I missed it again. Thanks

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

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by