Created
December 15, 2025 06:11
-
-
Save kumanna/cc388c832dd08de23d090d54583a0f02 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import numpy as np | |
| import matplotlib.pyplot as plt | |
| import scipy.signal | |
| SAMPLE_RATE = 44100 | |
| DURATION_SEC = 2 | |
| FREQ1 = 1000 | |
| FREQ2 = 1050 | |
| T = 1 / SAMPLE_RATE | |
| n_samples = SAMPLE_RATE * DURATION_SEC | |
| t = np.arange(n_samples) / T | |
| x1 = np.cos(2 * np.pi * FREQ1 * T * np.arange(n_samples)) | |
| x2 = np.cos(2 * np.pi * FREQ2 * T * np.arange(n_samples) + 2 * np.pi / 3) | |
| LIMIT = 1000 | |
| #plt.plot(t[:LIMIT], x1[:LIMIT], label=f"{FREQ1} Hz") | |
| #plt.plot(t[:LIMIT], x2[:LIMIT], label=f"{FREQ2} Hz") | |
| s = x1 + 0.01 * x2 | |
| # plt.plot(t[:LIMIT], s[:LIMIT], label=f"{FREQ1} Hz, {FREQ2} Hz") | |
| # plt.legend() | |
| # plt.show() | |
| # We do the FFT and see | |
| N = 1024 | |
| S = np.fft.fft(scipy.signal.windows.hamming(N) * s[:N]) | |
| #S = np.fft.fft(s[:N]) | |
| plt.stem(20*np.log10(np.abs(S))) | |
| plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment