defineSN

N point DFT with plot and twiddle factor

May 20th, 2012
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.85 KB | None | 0 0
  1. run_loop=1;
  2. while run_loop==1
  3. x=input('enter the sequence under []:\n');
  4. xstr=int2str(x);
  5. N=input('how many point dft? enter value of N:\n');
  6.  
  7. fprintf('\n')
  8. for p=0:1:(N/2-1)
  9.     e=exp(-i*(2*pi/N)*p);
  10.     a=horzcat('[',int2str(real(e)),' ',int2str(imag(e)),'j',']','<- this is a string only');
  11.     fprintf('W%d = %s\n',p,a)
  12.  
  13. end
  14. y=fft(x,N)
  15. ystr=int2str(y);
  16. yABS=abs(y);
  17. yANG=angle(y);
  18. n=0:1:(N-1);
  19. subplot(2,2,1)
  20. stem(n,x)
  21. xlabel('samples')
  22. ylabel('amplitude')
  23. title(['input sequence:',xstr])
  24. subplot(2,2,2)
  25. stem(n,y)
  26. xlabel('samples')
  27. ylabel('amplitude')
  28. title(['output sequence:',ystr])
  29. subplot(2,2,3)
  30. stem(n,yABS)
  31. xlabel('samples')
  32. ylabel('amplitude')
  33. title('magnitude of DFT')
  34. subplot(2,2,4)
  35. stem(n,yANG)
  36. xlabel('samples')
  37. ylabel('amplitude')
  38. title('angle of DFT')
  39.  
  40. run_loop=input('continue with another fft? 1(YES), 0(NO):')
  41. end
Advertisement
Add Comment
Please, Sign In to add comment