Created
January 27, 2026 09:23
-
-
Save kumanna/4befb80a1d0da0f159758359cedeae54 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 | |
| # Ts = 0.01 | |
| # N = 400 | |
| t = np.arange(0, 4, 0.01) | |
| x = np.cos(2 * np.pi * t) | |
| # plt.plot(t, x) | |
| # plt.show() | |
| # If we take FFT, the frequency of the sinusoid is 1 Hz | |
| # f_s / N = 100 / 400 = 0.25 Hz | |
| # So we will get two peaks, one at k = 4 and another at k = 396 | |
| X = np.fft.fft(x) | |
| # plt.stem(np.abs(X)) | |
| # plt.show() | |
| # For this one: | |
| y = np.cos(2 * 1.125 * np.pi * t) | |
| Y = np.fft.fft(y) | |
| # plt.stem(np.abs(Y)) | |
| # plt.show() | |
| # Reason is this: if omega_0 is a multiple of 2pi / N, you get nice peak | |
| print(np.abs(np.sum(x * np.exp(-1j * 2 * np.pi * t)))) | |
| print(np.abs(np.sum(y * np.exp(-1j * 2 * np.pi * t)))) | |
| print(np.abs(np.sum(y * np.exp(-1j * 2 * 2 * np.pi * t)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment