I have tried solving DFT but i am getting an error

3 Ansichten (letzte 30 Tage)
Sam17
Sam17 am 20 Sep. 2017
Kommentiert: Walter Roberson am 20 Sep. 2017
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 Kommentar
Walter Roberson
Walter Roberson am 20 Sep. 2017
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;

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Fourier Analysis and Filtering finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by