computing matrix without using for loop
Mostrar comentarios más antiguos
i wish to compute DFT without using a for loop so i figured to use matrix multiplication with the transformative matrix
function y = dft_mat(x,N)
for k=0:N-1
for l=0:N-1
w(k+1,l+1)=cos((2*pi*k*l)/N)-1i*sin((2*pi*k*l)/N);
end
end
y=w*x';
y=y';
end
but to calculate w i ended up using some for loops anyway
is there a way to calculate w without using a for loop? or any other DFT method without using for loop?
1 comentario
Bob Thompson
el 27 de En. de 2020
You can remove one loop by applying the calculations for entire sets of l at one time.
function y = dft_mat(x,N)
l = [0:N-1];
for k=0:N-1
w(k+1,:)=cos((2*pi*k*l)/N)-1i.*sin((2*pi*k*l)/N);
end
y=w*x';
y=y';
end
Untested, but should be about right.
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!