Advertisement
makispaiktis

6. Sound - Time and one sided spectrum of EVERY SOUND

Apr 17th, 2022 (edited)
1,678
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.50 KB | None | 0 0
  1. clc
  2. clear all
  3.  
  4. % Time
  5. [d, Fs] = audioread('kanonikosima.mp3');
  6. subplot(2, 1, 1);
  7. plot(d);
  8. xlabel('Time');
  9. title('Time domain');
  10.  
  11. % Frequency
  12. D = fft(d(:, 1));
  13. % 3. Two sided spectrums, two_sided = P2 and single_sided = P1
  14. LEN = size(d, 1);
  15. P2_S = abs(D / LEN);
  16. P1_S = P2_S(1 : 1+LEN/2);
  17. P1_S(2:end-1) = 2 * P1_S(2:end-1);
  18. P2_X = abs(D / LEN);
  19. P1_X = P2_X(1 : 1+LEN/2);
  20. P1_X(2:end-1) = 2 * P1_X(2:end-1);
  21. subplot(2, 1, 2);
  22. plot(P1_X);
  23. xlabel('Frequency (Hz)');
  24. title('One sided spectrum');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement