Advertisement
makispaiktis

Tutorial Thomas - LPF effect

Jul 25th, 2021 (edited)
1,001
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.20 KB | None | 0 0
  1. clc
  2. clear all
  3.  
  4. % 1. Beep of a sine wave
  5. x = linspace(0, 200*pi, 10001);
  6. Fs_usual = 44100;
  7. y = sin(x);
  8. play(y, Fs_usual);
  9. play(y, Fs_usual / 2);
  10. play(y, Fs_usual/4);
  11. display(' ');
  12.  
  13. % 2. Data is the sound
  14. [data, Fs] = audioread('helloworld.mp3');
  15. play2(data, Fs);
  16.  
  17. % 3. Filter data with a LPF
  18. b = ones(40, 1) / 40;         % Initialize conditions
  19. data_LPF = filter(b, 1, data);
  20. play2(data_LPF, Fs);
  21.  
  22. % 4. Plots
  23. [sizeOfData, dimensions] = size(data);      % pe: 84480 x 2 (stereo sound)
  24. xaxis = 1:sizeOfData;
  25. figure(1);
  26. plot(xaxis, data, 'red', xaxis, data_LPF, 'blue');
  27. title('Red = data, Blue = filtered data');
  28. figure(2);
  29. subplot(2,1,1);
  30. plot(real(fft(data)), 'red');
  31. title('Red = fft(data)');
  32. subplot(2,1,2);
  33. plot(real(fft(data_LPF)), 'blue');
  34. title('Blue = fft(data_LPF)');
  35.  
  36.  
  37.  
  38.  
  39. % Auxiliary Functions
  40. function play(y, Fs)
  41.     display(strcat('Listening to sinx with Fs=', num2str(Fs)));
  42.     sound(y, Fs);
  43.     counter = 0;
  44.     for i = 1:2*10^9
  45.         counter = counter + 1;
  46.     end
  47. end
  48.  
  49. function play2(y, Fs)
  50.     display(strcat('Listening to hello world with Fs=', num2str(Fs)));
  51.     sound(y, Fs);
  52.     counter = 0;
  53.     for i = 1:6*10^9
  54.         counter = counter + 1;
  55.     end
  56. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement