Skip to content

Commit

Permalink
refactor: stage before 0.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Sped0n committed May 15, 2024
1 parent c63cc58 commit 19f369d
Show file tree
Hide file tree
Showing 65 changed files with 389,121 additions and 203,169 deletions.
4,096 changes: 4,096 additions & 0 deletions assets/txt/sinwave_n2.txt

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions matlab/main.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
clearvars
clc

t = readtable("../assets/csv/sna.csv");
t = readtable("../assets/csv/voice2.csv");
numRows = height(t);
outputs = [];
filterOutputs = [];

for i = 1:numRows
if t{i, "p_0_out"} == 1
o = t{i, "axis_upstream_tdata_1_31_16_"};
fo = filter_simu_lpx(o);
fo = filter_simu(o);
filterOutputs = [filterOutputs; fo]; %#ok<AGROW>
outputs = [outputs; o]; %#ok<AGROW>
end
Expand All @@ -22,14 +22,14 @@
plot(filterOutputs, 'b', 'DisplayName', 'Filtered'); % Creates a line chart with circle markers at data points
xlabel('Sample Number'); % Assuming each output corresponds to a sample
ylabel('Filter Output');
title('Line Chart of filter\_simu Outputs');
title('滤波后');
grid on; % Adds a grid to the plot for better readability
legend show;

subplot(2, 1, 2);
plot(outputs, 'r', 'DisplayName', 'Original');
xlabel('Sample Number'); % Assuming each output corresponds to a sample
ylabel('Filter Output');
title('Line Chart of original');
title('滤波前');
grid on; % Adds a grid to the plot for better readability
legend show;
1 change: 1 addition & 0 deletions python/gcc_phat_debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from scipy.fftpack import fft, ifft
import matplotlib.pyplot as plt

plt.rcParams["font.family"] = "SimSun"

def csv_to_list(csv_file_name: str) -> tuple[list, list]:
csv_path: str = f"./assets/csv/{csv_file_name}.csv"
Expand Down
35 changes: 16 additions & 19 deletions python/sin_gen.py
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()
Loading

0 comments on commit 19f369d

Please sign in to comment.