I have tried solving DFT but i am getting an error

3 visualizzazioni (ultimi 30 giorni)
Sam17
Sam17 il 20 Set 2017
Commentato: Walter Roberson il 20 Set 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 Commento
Walter Roberson
Walter Roberson il 20 Set 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;

Accedi per commentare.

Risposte (0)

Categorie

Scopri di più su Fourier Analysis and Filtering in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by