• API
• FAQ
• Tools
• Archive
SHARE
TWEET  # Untitled a guest Dec 31st, 2016 167 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. close all;
2. f = 100;
3. fs = 1000;
4. T = 1;
5. x = transpose(linspace(0,T,fs*T));
6. y = sin(2*pi*f*x) + 0.01*sin(2*pi*2*f*x) + 0.25*sin(2*pi*4*f*x);
7. %Make sure we have an even number of points;
8. if (mod(length(y), 2) == 1)
9.     y = y(1:end-1,1:end);
10. end
11.
12. n=length(y);
13.
14. %Build windows
15. windows = ones(n,1);
16. windows = [windows, hanning(n)];
17. windows = [windows, hamming(n)];
18. windows = [windows, blackman(n)];
19. windows = [windows, blackmanharris(n)];
20. windows = [windows, gausswin(n)];
21. labels = {'Square'; 'Hanning'; 'Hamming'; 'Blackman'; 'Blackman-Harris'; 'Gaussian'};
22.
24. [n, winnum] = size(windows);
25. data = repmat(y,1,winnum) .* windows;
29.
30. p = fs/n;   %precision
31. %Assign memory
35.
36. figure;
37.
38. for i=1:winnum
39.     %Computes FFTs
42.     conv_spectrum(1:end,i) = conv(window_spectrum(1:end,i),data_spectrum(1:end,i));
43.
44.     %Draw plots
45.     subplot(2,3,i);
46.     hold on;