-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
65 changed files
with
389,121 additions
and
203,169 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,38 @@ | ||
import matplotlib.pyplot as plt | ||
import numpy as np | ||
|
||
Fs = 1024 | ||
plt.rcParams["font.family"] = "SimSun" | ||
|
||
Fs = 4096 | ||
t = np.arange(0, 1, 1 / Fs) | ||
y = np.sin(30 * t) | ||
y = np.sin(70 * t) + np.sin(700 * t) + np.sin(7000 * t) | ||
noise = np.random.randn(len(t)) | ||
noise_intensity = 0.2 | ||
noise_intensity = 0.05 | ||
y_noisy = y + noise_intensity * noise | ||
y_16bit = np.floor(y_noisy * np.power(2, 14)) | ||
y_16bit = np.floor(y_noisy * np.power(2, 10)) | ||
|
||
plt.figure() | ||
|
||
plt.subplot(221) | ||
plt.subplot(311) | ||
plt.plot(y_16bit) | ||
plt.xlabel("Original signed sine wave") | ||
plt.title("输入信号", fontsize=12) | ||
|
||
y1 = np.fft.fft(y_16bit, 1024) | ||
y1 = np.fft.fft(y_16bit, 4096) | ||
|
||
plt.subplot(222) | ||
plt.subplot(312) | ||
plt.plot(y1.real) | ||
plt.xlabel("FFT of original signed number (Real part)") | ||
plt.title("FFT 结果 (实部)", fontsize=12) | ||
|
||
y_16bit_a = y_16bit.copy() | ||
|
||
y_16bit_a[y_16bit_a < 0] += 2**16 | ||
|
||
plt.subplot(223) | ||
plt.plot(y_16bit_a) | ||
plt.xlabel("Sine wave after converting signed number to unsigned number") | ||
|
||
y2 = np.fft.fft(y_16bit_a, 1024) | ||
|
||
plt.subplot(224) | ||
plt.plot(y2.real) | ||
print(y2.real) | ||
plt.xlabel("FFT after converting to unsigned number (Real part)") | ||
|
||
np.savetxt("../assets/txt/sinwave_n2.txt", y_16bit_a, fmt="%d") | ||
plt.subplot(313) | ||
plt.plot(y1.imag) | ||
plt.title("FFT 结果 (虚部)", fontsize=12) | ||
|
||
np.savetxt("./assets/txt/sinwave_n2.txt", y_16bit_a, fmt="%d") | ||
plt.tight_layout() | ||
plt.show() |
Oops, something went wrong.