232 KiB
232 KiB
In [5]:
# Plot DSP Output
import numpy as np
import matplotlib.pyplot as plt
PLOT = False
dsp_desired_signal_r11 = np.genfromtxt("./simulation_data/complex_dsp_desired_signal_r11.txt", dtype=int)/(2**(15)-1)
dsp_noise_signal_r11 = np.genfromtxt("./simulation_data/complex_dsp_noise_signal_r11.txt", dtype=int)/(2**(15)-1)
dsp_noise_signal_vpu = np.genfromtxt("./simulation_data/complex_dsp_noise_signal_vpu.txt", dtype=int)/(2**(15)-1)
dsp_corrupted_signal = np.genfromtxt("./simulation_data/complex_dsp_corrupted_signal.txt", dtype=int)/(2**(15)-1)
t = np.linspace(0, len(dsp_corrupted_signal), len(dsp_corrupted_signal))/20000
output = np.genfromtxt("./filter_output/complex_dsp_output.txt", dtype=int)[:-1]/(2**(15)-1) # letzte Zeile löschen
error_signal = (output - dsp_desired_signal_r11)
t2 = np.linspace(0, len(error_signal), len(error_signal))/20000
# SNR davor/danach in dB berechnen, SNR Ratio berechnen,
snr_before = 10 * np.log10(np.trapz(dsp_desired_signal_r11**2, t) / np.trapz(dsp_noise_signal_r11**2, t))
snr_after = 10 * np.log10(np.trapz(dsp_desired_signal_r11**2, t) / np.trapz(error_signal**2, t2))
delta_snr = round(snr_after - snr_before, 2)
# Plots des Filterprozesses
figure1, (ax0, ax1, ax2, ax3) = plt.subplots(4, 1, figsize=(15, 12), sharex=True, sharey=True)
ax0.set_ylim(-1, 1)
ax0.plot(t, dsp_desired_signal_r11, c='deepskyblue', label='Desired signal')
ax1.plot(t, dsp_corrupted_signal, c='royalblue', label='Corrupted signal')
ax2.plot(t, dsp_noise_signal_r11, c='chocolate', label='Reference noise signal')
ax3.plot(t, output, c='green', label=f'SNR Gain = {delta_snr} dB')
ax0.text(0.5, -0.3, '(a) Desired signal',
transform=ax0.transAxes,
fontsize=25,
fontweight='normal',
ha='center',
va='bottom')
ax1.text(0.5, -0.3, '(b) Corrupted signal',
transform=ax1.transAxes,
fontsize=25,
fontweight='normal',
ha='center',
va='bottom')
ax2.text(0.5, -0.3, '(c) Reference noise signal',
transform=ax2.transAxes,
fontsize=25,
fontweight='normal',
ha='center',
va='bottom')
ax3.text(0.5, -0.5, f'(d) DSP Filter output (SNR Gain = {delta_snr} dB)',
transform=ax3.transAxes,
fontsize=25,
fontweight='normal',
ha='center',
va='bottom')
ax3.set_xlabel('time(s)', x=0.05)
ax0.set_ylabel('Amplitude')
ax1.set_ylabel('Amplitude')
ax2.set_ylabel('Amplitude')
ax3.set_ylabel('Amplitude')
# Plots der Filterperfomanz
figure2, (ax4) = plt.subplots(1, 1, figsize=(15, 4), sharex=True)
ax4.set_ylim(-1, 1)
ax4.plot(t2, error_signal, c='purple', label='Error (Desired signal - Filter output)')
ax4.text(0.5, -0.30, 'Error signal',
transform=ax4.transAxes,
fontsize=25,
fontweight='normal',
ha='center',
va='bottom')
ax4.set_xlabel('time(s)', x=0.05)
ax4.set_ylabel('Amplitude')
#Grids direkt auf Subplots anwenden
ax0.grid(True, linestyle='--', alpha=0.4)
ax1.grid(True, linestyle='--', alpha=0.4)
ax2.grid(True, linestyle='--', alpha=0.4)
ax3.grid(True, linestyle='--', alpha=0.4)
ax4.grid(True, linestyle='--', alpha=0.4)
#Spines direkt auf Subplots anwenden
ax0.spines['top'].set_visible(False)
ax1.spines['top'].set_visible(False)
ax2.spines['top'].set_visible(False)
ax3.spines['top'].set_visible(False)
ax4.spines['top'].set_visible(False)
ax0.spines['right'].set_visible(False)
ax1.spines['right'].set_visible(False)
ax2.spines['right'].set_visible(False)
ax3.spines['right'].set_visible(False)
ax4.spines['right'].set_visible(False)
# Schriftgrößen für LaTeX-Dokument
plt.rcParams.update({
"text.usetex": True,
"font.family": "serif",
'font.size': 16, # Standardtext
'axes.labelsize': 30, # Achsenbeschriftungen
'xtick.labelsize': 25, # Tick-Beschriftungen
'ytick.labelsize': 25,
'legend.fontsize': 15 # Legende
})
figure1.tight_layout()
figure2.tight_layout()
if PLOT == True:
figure1.savefig(f'plots/fig_plot_1_dsp_complex', dpi=600)
figure2.savefig(f'plots/fig_plot_2_dsp_complex', dpi=600)
plt.show()