1. Sound - Two tones

Mar 8th, 2022
995
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. clc
2. clear all
3.
4. % Data standard
5. Fs = 4410;
6. T = 1 / Fs;
7. LEN = 1000;
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. S1 = fft(s1);
18. S2 = fft(s2);
19. S = fft(s);
20.
21. % 1. Figure 1 - Time and frequency plots along with sound
22. figure(1);
23. title("Time and frequency domain");
24.
25. sound(s1, Fs);
26. delay(1);
27. title1 = num2str(f1) + " Hz";
28. subplot(3, 2, 1);
29. plot(s1);
30. title(title1 + " in time");
31. subplot(3, 2, 2);
32. plot(real(S1));
33. title(title1 + " in frequency");
34.
35. sound(s2, Fs);
36. delay(1);
37. title2 = num2str(f2) + " Hz";
38. subplot(3, 2, 3);
39. plot(s2);
40. title(title2 + " in time");
41. subplot(3, 2, 4);
42. plot(real(S2));
43. title(title2 + " in frequency");
44.
45. sound(s, Fs);
46. delay(1);
47. title3 = "Two tones together";
48. subplot(3, 2, 5);
49. plot(s);
50. title(title3 + " in time");
51. subplot(3, 2, 6);
52. plot(real(S));
53. title(title3 + " in frequency");
54.
55.
56.
57.
58.
59. % AUXILIARY FUNCTIONS
60. function y = delay(seconds)
61.     c = 0;
62.     for i = 1 : seconds * 10^9;
63.         c = c + 1;
64.     end
65.     y = c;
66. end
67.
68.