how to repeat cycles in a DFT equation

3 views (last 30 days)
steven
steven on 28 Jul 2013
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.

Answers (1)

Azzi Abdelmalek
Azzi Abdelmalek on 28 Jul 2013
Edited: Azzi Abdelmalek on 28 Jul 2013
Use repmat function
repmat(Xz,100,1)
  1 Comment
steven
steven on 28 Jul 2013
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?

Sign in to comment.

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!