Advertisement
Guest User

Matlab Hann window task

a guest
Jul 17th, 2017
319
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.06 KB | None | 0 0
  1. clear all; close all; clc;  %Cleaning up
  2.  
  3.  
  4. %Task:
  5. %In Matlab, plot the Hann- and Hamming window in the frequency domain with
  6. %window length N=41 by numerically calculating the Fourier transform.
  7.  
  8. %Notes:
  9. %This code only features the Hann window for simplicity
  10. %Demonstration function for comparison:
  11. L = 41;    
  12. wvtool(hann(L))    
  13.  
  14. %Task Properties
  15. N=41;           %Data points
  16. SEGMENTS=1000;   %Segments for the transform. Minimum of 200. Around 4101 yields no -Inf through testing.
  17.  
  18.  
  19. %The Hann function, time domain
  20. a=0.5;  %Hann window specifics
  21. b=0.5;
  22. t=0:N-1;    %Time axis
  23. w=a-b*cos(2*pi*t/(N-1));    %The function
  24.  
  25. % plotting
  26. subplot(2,1,1)
  27. stem(t,w)
  28. xlabel('N')
  29. grid on
  30.  
  31. %The Fourier Transformation, frequency domain
  32. v=0:1/(SEGMENTS-1):1;   % Time axis with 1000 points
  33. W=fft(w,SEGMENTS);      % Fourier transform with 1000 points
  34. Wabs=abs(W);            % Take absolute value
  35. Wabs=mag2db(Wabs);      % and convert to dB
  36.  
  37. % plotting
  38. subplot(2,1,2)
  39. plot(v,Wabs);
  40. ylabel('dB')
  41. xlabel('Normalized frequency')
  42. grid on
  43. axis([0 1/2 -100 50])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement