Need help in creating a script without using for loops.

1 次查看(过去 30 天)
I am trying to write a scrpt without using for loops. Attach is the scripts with for loops. They are for Q3a and Q3b.
  4 个评论
KSSV
KSSV 2020-9-25
Don't show your image as a image snippet....copy your code here.
matthew choo
matthew choo 2020-9-25
%Biosensor Project 2 Q3
%Develop a function in MatLab to
%Calculate the Discrete Fourier Transform
%Check the function with the function in Matlab.
%Develop a function. Don't use loop.
%Implement function with matrices.
%To test function using following signals.
%a)Aperiodic signal
%x[n]={0,1,2,3,4,3,2,1,0,0,0,0}
x=[0 1 2 3 4 3 2 1 0 0 ]
l=length(x)
disp('array initialized with zero and length l')
for k=1:10
xk(k)=0;
for n=1:10
xk(k)=xk(k)+x(n)*k;
end
end
disp('displaying final transform')
disp(xk)
%function [Xk] = dft(xn)
%x=[0 1 2 3 4 3 2 1 0 0 ]
%len = length(xn);
%w = 2*pi*linspace(0,1-1/len,len);
%Xk = exp(-1j*w'*(n-1))*xn';

请先登录,再进行评论。

回答(1 个)

David Hill
David Hill 2020-9-25
N=length(x);
Xk=sum(x.*exp((-1i*2*pi/N*(0:N-1)).*(0:N-1)'),2);

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by