filtering stuff
All checks were successful
Publish Python 🐍 distribution 📦 to PyPI and TestPyPI / Build distribution 📦 (push) Successful in -15s
Publish Python 🐍 distribution 📦 to PyPI and TestPyPI / Publish Python 🐍 distribution 📦 to PyPI (push) Has been skipped

This commit is contained in:
Brendan Haines 2024-12-02 22:55:39 -07:00
parent 48d559f084
commit 958d1f96d1

View File

@ -170,8 +170,8 @@ n, wn = signal.buttord(
analog=False, analog=False,
fs=sdr.sdr.sample_rate, fs=sdr.sdr.sample_rate,
) )
b, a = signal.butter(n, wn, "lowpass", analog=False, output="ba", fs=sdr.sdr.sample_rate) sos = signal.butter(n, wn, "lowpass", analog=False, output="sos", fs=sdr.sdr.sample_rate)
filt_data = signal.lfilter(b, a, ddc_data, axis=-1) filt_data = signal.sosfiltfilt(sos, ddc_data, axis=-1)
axs[0][0].plot(np.real(filt_data).T, label="FILT") axs[0][0].plot(np.real(filt_data).T, label="FILT")
axs[1][0].plot(np.imag(filt_data).T, label="FILT") axs[1][0].plot(np.imag(filt_data).T, label="FILT")
filt_rel = filt_data[1] / filt_data[0] filt_rel = filt_data[1] / filt_data[0]
@ -220,21 +220,19 @@ ax.set_ylim(ax.get_xlim())
fig.show() fig.show()
# %% Plot in frequency # %% Plot in frequency
f, Pxx_den = signal.periodogram(data, sdr.sdr.sample_rate, axis=-1, return_onesided=False)
f_ddc, Pxx_den_ddc = signal.periodogram(ddc_data, sdr.sdr.sample_rate, axis=-1, return_onesided=False)
f_filt, Pxx_den_filt = signal.periodogram(filt_data, sdr.sdr.sample_rate, axis=-1, return_onesided=False)
f = np.fft.fftfreq(data.shape[-1], 1 / sdr.sdr.sample_rate) f = np.fft.fftfreq(data.shape[-1], 1 / sdr.sdr.sample_rate)
Pxx_den = np.fft.fft(data, axis=-1) RX_BITS = 10
Pxx_den_ddc = np.fft.fft(ddc_data, axis=-1) Pxx_den = np.fft.fft(data, axis=-1) / (len(data) * 2 ** (2 * RX_BITS))
Pxx_den_filt = np.fft.fft(filt_data, axis=-1) Pxx_den_ddc = np.fft.fft(ddc_data, axis=-1) / (len(ddc_data) * 2 ** (2 * RX_BITS))
fft_ddc_tone = np.fft.fft(ddc_tone, axis=-1) Pxx_den_filt = np.fft.fft(filt_data, axis=-1) / (len(filt_data) * 2 ** (2 * RX_BITS))
fft_ddc_tone = np.fft.fft(ddc_tone, axis=-1) / (len(ddc_tone))
plt.figure() plt.figure()
for cc, chan in enumerate(sdr.sdr.rx_enabled_channels): for cc, chan in enumerate(sdr.sdr.rx_enabled_channels):
plt.plot( # plt.plot(
np.fft.fftshift(f), # np.fft.fftshift(f),
db20(np.fft.fftshift(Pxx_den[cc])), # db20(np.fft.fftshift(Pxx_den[cc])),
label=f"Channel {chan}", # label=f"Channel {chan}",
) # )
plt.plot( plt.plot(
np.fft.fftshift(f), np.fft.fftshift(f),
db20(np.fft.fftshift(Pxx_den_ddc[cc])), db20(np.fft.fftshift(Pxx_den_ddc[cc])),
@ -245,16 +243,16 @@ for cc, chan in enumerate(sdr.sdr.rx_enabled_channels):
db20(np.fft.fftshift(Pxx_den_filt[cc])), db20(np.fft.fftshift(Pxx_den_filt[cc])),
label=f"Channel {chan}", label=f"Channel {chan}",
) )
plt.plot( # plt.plot(
np.fft.fftshift(f), # np.fft.fftshift(f),
db20(np.fft.fftshift(fft_ddc_tone)), # db20(np.fft.fftshift(fft_ddc_tone)),
label="DDC Tone", # label="DDC Tone",
) # )
plt.legend() plt.legend()
# plt.ylim(1e-7, 1e2) # plt.ylim(1e-7, 1e2)
plt.ylim(0) plt.ylim(-100, 0)
plt.xlabel("Frequency [Hz]") plt.xlabel("Frequency [Hz]")
plt.ylabel("PSD [$V^2/Hz$]") plt.ylabel("Power [dBfs]")
plt.title(f"Fc = {sdr.sdr.rx_lo / 1e9} GHz") plt.title(f"Fc = {sdr.sdr.rx_lo / 1e9} GHz")
plt.gca().xaxis.set_major_formatter(EngFormatter()) plt.gca().xaxis.set_major_formatter(EngFormatter())
plt.grid(True) plt.grid(True)