how to repeat cycles in a DFT equation

3 次查看(过去 30 天)
Hello, I have to write a code for a DFT equation. I have the code for 1 cycle below and it comes out fine. Now I have to repeat the cycle 100 times with the same x(n). I am trying to repeat with a for loop but can't get the summation right.
n=0:1:1/f; %sequence of time samples
X=cos(2*pi*f*n); %first part of equation
Xz= [(X) zeros(1,10)]; %padding zeros
Xs=0;
so I end up saying I want to repeat Xz 100 cycles
for t=0:100 Xs(t+1)=Xs(t+1)+Xz end
but matlab says the sides are not equal? Any help would be great.

回答(1 个)

Azzi Abdelmalek
Azzi Abdelmalek 2013-7-28
编辑:Azzi Abdelmalek 2013-7-28
Use repmat function
repmat(Xz,100,1)
  1 个评论
steven
steven 2013-7-28
Thanks, ok I see the matlab has made 100 copies, but it won't graph correctly now.
Xs=repmat(Xz,100,1);
Xw=zeros(1,N);%put zeros in Xw
for k=0:N-1 %loop for k
for n=0:N-1 % loop for n
Xw(k+1)=Xw(k+1)+Xs(n+1)*exp((-j*2*pi*n*k)/N); %DFT equation
end
end
When I do my for loops with the one cylce the graph comes out correctly, but when I replace it with the Xs that holds my 100 cycles the graph comes out wrong? Shouldn't the DFT algorithm do it through all the cycles now?

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by