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 件のコメント

Bob Thompson
Bob Thompson 2020 年 1 月 27 日
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.

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

 採用された回答

Steven Lord
Steven Lord 2020 年 1 月 27 日

0 投票

Compute the matrix k*l using implicit expansion with element-wise multiplication. The other operations (cos, sin, scalar multiplication, scalar division, subtraction) involved in creating w can all operate on matrices.
If you're using a release older than release R2016b, when implicit expansion was introduced, use bsxfun or repmat.

1 件のコメント

Panda
Panda 2020 年 1 月 27 日
Yup totally forgot about element wise operations thanks a lot

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange で Loops and Conditional Statements についてさらに検索

質問済み:

2020 年 1 月 27 日

コメント済み:

2020 年 1 月 27 日

Community Treasure Hunt

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

Start Hunting!

Translated by