Advertisement
Guest User

Untitled

a guest
Nov 2nd, 2015
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. f = 2000;
  2. fs = 44100;
  3. fs_upsampled = 176400;
  4. s = 1:(fs * 2);
  5. s_upsampled = 1:(fs_upsampled * 2);
  6.  
  7. % naive
  8. naive = 1 - 2 * mod(s*f/fs, 1);
  9.  
  10. % ideal
  11. ideal = naive * 0;
  12. f1 = f;
  13. i = 0;
  14. while f1 < fs / 2
  15. i = i + 1;
  16. f1 = f * i;
  17. ideal = ideal + sin(2 * pi * s * f1 / fs) / i;
  18. end
  19. ideal = ideal / norm(ideal) * norm(naive);
  20.  
  21. % naive + oversampling
  22. naive_upsampled = 1 - 2 * mod(s_upsampled*f/fs_upsampled, 1);
  23. naive_upsampled = resample(naive_upsampled, 1, 4);
  24.  
  25. figure;
  26. hold on;
  27. plot(ideal, 'r')
  28. plot(naive_upsampled, 'g')
  29. plot(naive)
  30.  
  31. figure;
  32. hold on;
  33. plot(abs(fft(naive)))
  34. plot(abs(fft(naive_upsampled)), 'g')
  35. plot(abs(fft(ideal)), 'r')
  36.  
  37.  
  38. sound(ideal, fs)
  39. sound(naive, fs)
  40. sound(naive_upsampled, fs)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement