Advertisement
makispaiktis

2. Sound - Corrupted signal

Mar 8th, 2022 (edited)
1,357
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.14 KB | None | 0 0
  1. clc
  2. clear all
  3.  
  4. % Data standard
  5. Fs = 5000;
  6. T = 1 / Fs;
  7. LEN = 10000;
  8. t = (0 : LEN-1) * T;
  9. % Selecting data
  10. A1 = 0.7;
  11. A2 = 0.9;
  12. f1 = 294;
  13. f2 = 440;
  14. s1 = A1 * cos(2*pi*f1*t);
  15. s2 = A2 * cos(2*pi*f2*t);
  16. s = s1 + s2;
  17. % Corrupt my signal s ---> create x
  18. x = s + 0.35 * randn(size(t));
  19.  
  20. % Display the first time samples
  21. S = fft(s);
  22. X = fft(x);
  23. stop = LEN / 50;         % Show only 2% of all the samples
  24. figure();
  25.  
  26. subplot(2, 2, 1);
  27. plot(1000*t(1:stop), s(1:stop));
  28. title("Original in time (first samples)");
  29. xlabel('t (milliseconds)')
  30. ylabel('s(t)')
  31. subplot(2, 2, 2);
  32. plot(real(S));
  33. title("Original in frequencies (all samples)");
  34.  
  35. subplot(2, 2, 3);
  36. plot(1000*t(1:stop), x(1:stop));
  37. title("Corrupted in time (first samples)");
  38. xlabel('t (milliseconds)')
  39. ylabel('x(t)')
  40. subplot(2, 2, 4);
  41. plot(real(X));
  42. title("Corrupted in frequencies (all samples)");
  43.  
  44. % Sound
  45. sound(s, Fs);
  46. display("Playing the ORIGINAL sound");
  47. delay(2);
  48. sound(x, Fs)
  49. display("Playing the CORRUPTED sound");
  50.  
  51.  
  52.  
  53. % AUXILIARY FUNCTIONS
  54. function y = delay(seconds)
  55.     c = 0;
  56.     for i = 1 : seconds * 10^9;
  57.         c = c + 1;
  58.     end
  59.     y = c;
  60. end
  61.  
  62.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement