Need help in creating a script without using for loops.

1 Ansicht (letzte 30 Tage)
matthew choo
matthew choo am 25 Sep. 2020
Kommentiert: matthew choo am 25 Sep. 2020
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 Kommentare
KSSV
KSSV am 25 Sep. 2020
Don't show your image as a image snippet....copy your code here.
matthew choo
matthew choo am 25 Sep. 2020
%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';

Melden Sie sich an, um zu kommentieren.

Antworten (1)

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

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by