I have tried solving DFT but i am getting an error

3 次查看(过去 30 天)
Here is my code: i tried solving using matrix multiplication
f1=7;f2=21;
fs=220; %Sampling frequency f2*10
ts=1/fs; %sampling time
t=0:10-ts;
y=sin(2*pi*t*f1)+sin(2*pi*t*f2); %given data set
N=length(y);
n = 0:1:N-1; % row vector for n
k = 0:1:N-1; % row vecor for k
WN = exp(-1j*2*pi/N); % the w elements
n1= transpose(n);
nk = n1*k; % creates a N by N matrix of nk values
WNnk = WN .^ nk; % DFT matrix
Xk = WNnk.*y;
plot(n,xk)
Here is my error message:
Error using .* Matrix dimensions must agree.
Error in a21 (line 13) Xk = WNnk.*y;
Please help me plot:
  1 个评论
Walter Roberson
Walter Roberson 2017-9-20
At the time of your line WNnk.*y then WNnk is 10 x 10 and y is 1 x 10. What size of output were you expecting from that?
Note: your line
t=0:10-ts;
should be
t=0:ts:10-ts;

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Fourier Analysis and Filtering 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by