Plots weiter

This commit is contained in:
Patrick Hangl
2026-05-08 12:27:44 +02:00
parent 53fbf70ed1
commit c44a2bf6bc
6 changed files with 154 additions and 74 deletions
+105 -46
View File
@@ -48,7 +48,7 @@
" modified_signal = np.fft.irfft(modified_freq_signal, n=N)\n",
" return modified_signal\n",
"\n",
"# High-Level ANR Algorithmmus\n",
"# High-Level ANR Algorithmmus - nicht deterministisch, daher nicht gleiche Ergebnisse wie in C\n",
"def anr_function(input, ref_noise, coefficients, mu, adaption_step = 1):\n",
" coefficient_matrix = np.zeros((len(input), coefficients), dtype=np.float32)\n",
" output=np.zeros(input.shape[0], dtype=np.float32)\n",
@@ -88,8 +88,8 @@
" error = input[n] - accumulator\n",
" output[n] = error\n",
" # update_filter_coeffcients: Filterkoeffizienten adaptieren\n",
" if (n % adaption_step) == 0: # bei Rate x/adatpion_step: if (n % adaption_step) < x:\n",
" #if abs(error) > 0.00: # nur adaptieren wenn Fehler über Schwellwert\n",
" #if (n % adaption_step) == 0: # bei Rate x/adatpion_step: if (n % adaption_step) < x:\n",
" if (abs(error)*ref_noise[n]) > 0.000001: # nur adaptieren wenn Fehler über Schwellwert\n",
" counter += 1\n",
" filter_line += mu * error * sample_line\n",
" # Filterkoeffizienten expoertieren\n",
@@ -966,6 +966,8 @@
"update_gain_breathing = update_rate_breathing[:, 2]\n",
"update_cycles_breathing = update_rate_breathing[:, 4]\n",
"update_load_breathing = update_rate_breathing[:, 5]\n",
"update_cycles_breathing_new = update_rate_breathing[:, 7]\n",
"update_load_breathing_new = update_rate_breathing[:, 8]\n",
"\n",
"# Sortieren\n",
"idx = np.argsort(x)\n",
@@ -973,6 +975,8 @@
"update_gain_breathing = update_gain_breathing[idx]\n",
"update_cycles_breathing = update_cycles_breathing[idx]\n",
"update_load_breathing = update_load_breathing[idx]\n",
"update_cycles_breathing_new = update_cycles_breathing_new[idx]\n",
"update_load_breathing_new = update_load_breathing_new[idx]\n",
"\n",
"# Smoothing\n",
"x_smooth = np.linspace(x.min(), x.max(), 300)\n",
@@ -980,6 +984,8 @@
"update_gain_smooth = make_interp_spline(x, update_gain_breathing)(x_smooth)\n",
"update_cycles_smooth = make_interp_spline(x, update_cycles_breathing)(x_smooth)\n",
"update_load_smooth = make_interp_spline(x, update_load_breathing)(x_smooth)\n",
"update_cycles_smooth_new = make_interp_spline(x, update_cycles_breathing_new)(x_smooth)\n",
"update_load_smooth_new = make_interp_spline(x, update_load_breathing_new)(x_smooth)\n",
"\n",
"diff_smooth = np.abs(update_gain_smooth - update_cycles_smooth)\n",
"idx_max = np.argmax(diff_smooth)\n",
@@ -988,17 +994,31 @@
"y2_max = update_cycles_smooth[idx_max]\n",
"\n",
"# Plot\n",
"plt.figure(figsize=(15, 7))\n",
"plt.plot(x_smooth, update_gain_smooth, linestyle='--', color='indianred', linewidth=2, alpha=0.9, label='SNR-Gain')\n",
"plt.plot(x_smooth, update_cycles_smooth, linestyle='-.', color='skyblue', linewidth=2, alpha=0.9, label='Cycles/Sample')\n",
"plt.plot(x_smooth, update_load_smooth, linestyle=':', color='forestgreen', linewidth=2, alpha=0.9, label='DSP Load')\n",
"plt.plot([x_max, x_max], [y1_max, y2_max], color='black', linestyle=':', linewidth=2)\n",
"figure1, ax1 = plt.subplots(figsize=(15, 7))\n",
"ax1.plot(x_smooth, update_gain_smooth, linestyle='--', color='indianred', linewidth=2, alpha=0.9, label='SNR-Gain')\n",
"ax1.plot(x_smooth, update_cycles_smooth, linestyle='-.', color='skyblue', linewidth=2, alpha=0.9, label='Cycles/Sample')\n",
"ax1.plot(x_smooth, update_load_smooth, linestyle=':', color='forestgreen', linewidth=2, alpha=0.9, label='DSP Load')\n",
"ax1.plot([x_max, x_max], [y1_max, y2_max], color='black', linestyle=':', linewidth=2)\n",
"\n",
"plt.scatter(x, update_gain_breathing, color='indianred', s=40)\n",
"plt.scatter(x, update_cycles_breathing, color='skyblue', s=40)\n",
"plt.scatter(x, update_load_breathing, color='forestgreen', s=40)\n",
"ax1.scatter(x, update_gain_breathing, color='indianred', s=40)\n",
"ax1.scatter(x, update_cycles_breathing, color='skyblue', s=40)\n",
"ax1.scatter(x, update_load_breathing, color='forestgreen', s=40)\n",
"\n",
"plt.text(x_max, (y1_max + y2_max)/2+0.1,\n",
"# Plot\n",
"figure2, ax2 = plt.subplots(figsize=(15, 7))\n",
"ax2.plot(x_smooth, update_gain_smooth, linestyle='--', color='indianred', linewidth=2, alpha=0.9, label='SNR-Gain')\n",
"ax2.plot(x_smooth, update_cycles_smooth, linestyle='-.', color='skyblue', linewidth=2, alpha=0.3)\n",
"ax2.plot(x_smooth, update_load_smooth, linestyle=':', color='forestgreen', linewidth=2, alpha=0.3)\n",
"ax2.plot(x_smooth, update_cycles_smooth_new, linestyle='-', color='skyblue', linewidth=2, alpha=0.9, label='Cycles/Sample (New)')\n",
"ax2.plot(x_smooth, update_load_smooth_new, linestyle='-', color='forestgreen', linewidth=2, alpha=0.9, label='DSP Load (New)')\n",
"\n",
"ax2.scatter(x, update_gain_breathing, color='indianred', s=40)\n",
"ax2.scatter(x, update_cycles_breathing, color='skyblue', s=40, alpha=0.3)\n",
"ax2.scatter(x, update_load_breathing, color='forestgreen', s=40, alpha=0.3)\n",
"ax2.scatter(x, update_cycles_breathing_new, color='skyblue', s=40)\n",
"ax2.scatter(x, update_load_breathing_new, color='forestgreen', s=40)\n",
"\n",
"ax1.text(x_max, (y1_max + y2_max)/2+0.1,\n",
" f'Max. offset at update rate {x_max:.2f}',\n",
" fontsize=20,\n",
" ha='left')\n",
@@ -1014,19 +1034,30 @@
"})\n",
"\n",
"\n",
"plt.xlabel(\"Update Rate\")\n",
"plt.ylabel(\"Relative Performance\")\n",
"plt.grid(True, linestyle='-.', alpha=0.4)\n",
"ax1.set_xlabel(\"Update Rate\")\n",
"ax1.set_ylabel(\"Relative Performance\")\n",
"ax2.set_xlabel(\"Update Rate\")\n",
"ax2.set_ylabel(\"Relative Performance\")\n",
"ax1.grid(True, linestyle='-.', alpha=0.4)\n",
"ax2.grid(True, linestyle='-.', alpha=0.4)\n",
"#Spines auf ganzen Plot anwenden\n",
"plt.gca().yaxis.set_major_formatter(mtick.PercentFormatter(1.0))\n",
"plt.gca().spines['top'].set_visible(False)\n",
"plt.gca().spines['right'].set_visible(False)\n",
"plt.gca().invert_xaxis()\n",
"plt.legend(frameon=False, loc='upper right')\n",
"plt.tight_layout()\n",
"ax1.yaxis.set_major_formatter(mtick.PercentFormatter(1.0))\n",
"ax2.yaxis.set_major_formatter(mtick.PercentFormatter(1.0))\n",
"ax1.spines['top'].set_visible(False)\n",
"ax1.spines['right'].set_visible(False)\n",
"ax2.spines['top'].set_visible(False)\n",
"ax2.spines['right'].set_visible(False)\n",
"ax1.invert_xaxis()\n",
"ax2.invert_xaxis()\n",
"ax1.legend(frameon=False, loc='upper right')\n",
"ax2.legend(frameon=False, loc='upper right')\n",
"figure1.tight_layout()\n",
"figure2.tight_layout()\n",
"if PLOT == True:\n",
" plt.savefig(f'plots/fig_snr_update_rate', dpi=600)\n",
"plt.show()\n"
" figure1.savefig(f'plots/fig_snr_update_rate', dpi=600)\n",
" figure2.savefig(f'plots/fig_snr_update_rate_new', dpi=600)\n",
"figure1.show()\n",
"figure2.show()\n"
]
},
{
@@ -1232,6 +1263,8 @@
"error_gain = data_error_threshold[:, 2]\n",
"error_cycles = data_error_threshold[:, 6]\n",
"error_load = data_error_threshold[:, 7]\n",
"error_cycles_new = data_error_threshold[:, 9]\n",
"error_load_new = data_error_threshold[:, 10]\n",
"\n",
"# Sortieren\n",
"idx = np.argsort(x)\n",
@@ -1239,13 +1272,16 @@
"error_gain = error_gain[idx]\n",
"error_cycles = error_cycles[idx]\n",
"error_load = error_load[idx]\n",
"\n",
"error_cycles_new = error_cycles_new[idx]\n",
"error_load_new = error_load_new[idx]\n",
"# Smoothing\n",
"x_smooth = np.linspace(x.min(), x.max(), 300)\n",
"\n",
"gain_smooth = make_interp_spline(x, error_gain)(x_smooth)\n",
"cycles_smooth = make_interp_spline(x, error_cycles)(x_smooth)\n",
"comp_smooth = make_interp_spline(x, error_load)(x_smooth)\n",
"load_smooth = make_interp_spline(x, error_load)(x_smooth)\n",
"cycles_smooth_new = make_interp_spline(x, error_cycles_new)(x_smooth)\n",
"load_smooth_new = make_interp_spline(x, error_load_new)(x_smooth)\n",
"\n",
"diff_smooth = np.abs(gain_smooth - cycles_smooth)\n",
"idx_max = np.argmax(diff_smooth)\n",
@@ -1254,17 +1290,31 @@
"y2_max = cycles_smooth[idx_max]\n",
"\n",
"# Plot\n",
"plt.figure(figsize=(15, 7))\n",
"plt.plot(x_smooth, gain_smooth, linestyle='--', color='indianred', linewidth=2, alpha=0.9, label='SNR-Gain')\n",
"plt.plot(x_smooth, cycles_smooth, linestyle='-.', color='skyblue', linewidth=2, alpha=0.9, label='Cycles/Sample')\n",
"plt.plot(x_smooth, comp_smooth, linestyle=':', color='forestgreen', linewidth=2, alpha=0.9, label='DSP Load')\n",
"plt.plot([x_max, x_max], [y1_max, y2_max], color='black', linestyle=':', linewidth=2)\n",
"figure1, ax1 = plt.subplots(figsize=(15, 7))\n",
"ax1.plot(x_smooth, gain_smooth, linestyle='--', color='indianred', linewidth=2, alpha=0.9, label='SNR-Gain')\n",
"ax1.plot(x_smooth, cycles_smooth, linestyle='-.', color='skyblue', linewidth=2, alpha=0.9, label='Cycles/Sample')\n",
"ax1.plot(x_smooth, load_smooth, linestyle=':', color='forestgreen', linewidth=2, alpha=0.9, label='DSP Load')\n",
"ax1.plot([x_max, x_max], [y1_max, y2_max], color='black', linestyle=':', linewidth=2)\n",
"\n",
"plt.scatter(x, error_gain, color='indianred', s=40)\n",
"plt.scatter(x, error_cycles, color='skyblue', s=40)\n",
"plt.scatter(x, error_load, color='forestgreen', s=40)\n",
"ax1.scatter(x, error_gain, color='indianred', s=40)\n",
"ax1.scatter(x, error_cycles, color='skyblue', s=40)\n",
"ax1.scatter(x, error_load, color='forestgreen', s=40)\n",
"\n",
"plt.text(x_max, (y1_max + y2_max)/2+0.21,\n",
"figure2, ax2 = plt.subplots(figsize=(15, 7))\n",
"ax2.plot(x_smooth, gain_smooth, linestyle='--', color='indianred', linewidth=2, alpha=0.9, label='SNR-Gain')\n",
"ax2.plot(x_smooth, cycles_smooth, linestyle='-.', color='skyblue', linewidth=2, alpha=0.3)\n",
"ax2.plot(x_smooth, load_smooth, linestyle=':', color='forestgreen', linewidth=2, alpha=0.3)\n",
"ax2.plot(x_smooth, cycles_smooth_new, linestyle='-', color='skyblue', linewidth=2, alpha=0.9, label='Cycles/Sample (New)')\n",
"ax2.plot(x_smooth, load_smooth_new, linestyle='-', color='forestgreen', linewidth=2, alpha=0.9, label='DSP Load (New)')\n",
"\n",
"\n",
"ax2.scatter(x, error_gain, color='indianred', s=40)\n",
"ax2.scatter(x, error_cycles, color='skyblue', s=40, alpha=0.3)\n",
"ax2.scatter(x, error_load, color='forestgreen', s=40, alpha=0.3)\n",
"ax2.scatter(x, error_cycles_new, color='skyblue', s=40,)\n",
"ax2.scatter(x, error_load_new, color='forestgreen', s=40)\n",
"\n",
"ax1.text(x_max, (y1_max + y2_max)/2+0.21,\n",
" f'Max. offset at threshold {x_max:.2f}',\n",
" fontsize=20,\n",
" ha='left')\n",
@@ -1279,19 +1329,28 @@
" 'legend.fontsize': 25 # Legende\n",
"})\n",
"\n",
"plt.xlabel(\"Error Threshold\")\n",
"plt.ylabel(\"Relative Performance\")\n",
"plt.grid(True, linestyle='-.', alpha=0.4)\n",
"ax1.set_xlabel(\"Error Threshold\")\n",
"ax1.set_ylabel(\"Relative Performance\")\n",
"ax2.set_xlabel(\"Error Threshold\")\n",
"ax2.set_ylabel(\"Relative Performance\")\n",
"ax1.grid(True, linestyle='-.', alpha=0.4)\n",
"ax2.grid(True, linestyle='-.', alpha=0.4)\n",
"#Spines auf ganzen Plot anwenden\n",
"plt.gca().yaxis.set_major_formatter(mtick.PercentFormatter(1.0))\n",
"plt.gca().spines['top'].set_visible(False)\n",
"plt.gca().spines['right'].set_visible(False)\n",
"#plt.gca().invert_xaxis()\n",
"plt.legend(frameon=False, loc='upper right')\n",
"plt.tight_layout()\n",
"ax1.yaxis.set_major_formatter(mtick.PercentFormatter(1.0))\n",
"ax2.yaxis.set_major_formatter(mtick.PercentFormatter(1.0))\n",
"ax1.spines['top'].set_visible(False)\n",
"ax1.spines['right'].set_visible(False)\n",
"ax2.spines['top'].set_visible(False)\n",
"ax2.spines['right'].set_visible(False)\n",
"ax1.legend(frameon=False, loc='upper right')\n",
"ax2.legend(frameon=False, loc='upper right')\n",
"figure1.tight_layout()\n",
"figure2.tight_layout()\n",
"if PLOT == True:\n",
" plt.savefig(f'plots/fig_snr_error_threshold', dpi=600)\n",
"plt.show()\n"
" figure1.savefig(f'plots/fig_snr_error_threshold', dpi=600)\n",
" figure2.savefig(f'plots/fig_snr_error_threshold_new', dpi=600)\n",
"figure1.show()\n",
"figure2.show()\n"
]
},
{
@@ -1473,7 +1532,7 @@
],
"metadata": {
"kernelspec": {
"display_name": ".venv",
"display_name": ".venv (3.9.13)",
"language": "python",
"name": "python3"
},
+23 -2
View File
File diff suppressed because one or more lines are too long
Binary file not shown.
@@ -1,18 +1,18 @@
Threshold;SNR_Gain;%SNR_Gain;Adjustments;%Adjustments;Cycles;%Cycles;DSP_Load
0;9.47;1.000;200000;1.000;357;1.000;0.446
0.001;9.47;1.000;174704;0.874;322;0.902;0.402
0.005;9.43;0.996;133980;0.670;265;0.743;0.332
0.01;9.27;0.979;108728;0.544;230;0.645;0.288
0.02;8.63;0.911;81434;0.407;192;0.538;0.240
0.03;7.84;0.828;66027;0.330;171;0.478;0.213
0.04;7.12;0.752;55964;0.280;157;0.439;0.196
0.05;6.56;0.693;48488;0.242;146;0.410;0.183
0.06;6.12;0.646;42814;0.214;139;0.388;0.173
0.07;5.75;0.607;37829;0.189;132;0.369;0.164
0.08;5.46;0.577;33634;0.168;126;0.352;0.157
0.09;5.28;0.558;29944;0.150;121;0.338;0.151
0.1;5.15;0.544;26675;0.133;116;0.325;0.145
0.2;4.19;0.442;7867;0.039;90;0.252;0.112
0.3;2.87;0.303;1852;0.009;82;0.228;0.102
0.4;1.24;0.131;268;0.001;79;0.222;0.099
0.5;0.47;0.050;55;0.000;79;0.222;0.099
Threshold;SNR_Gain;%SNR_Gain;Adjustments;%Adjustments;Cycles;%Cycles;DSP_Load;Cycles_new;%Cycles_new;DSP_Load_new
0;9.47;1.000;200000;1.000;357;1.000;0.446;367;1.000;0.459
0.001;9.47;1.000;174704;0.874;322;0.902;0.402;332;0.904;0.415
0.005;9.43;0.996;133980;0.670;265;0.743;0.332;275;0.750;0.344
0.01;9.27;0.979;108728;0.544;230;0.645;0.288;240;0.654;0.300
0.02;8.63;0.911;81434;0.407;192;0.538;0.240;202;0.551;0.253
0.03;7.84;0.828;66027;0.330;171;0.478;0.213;181;0.493;0.226
0.04;7.12;0.752;55964;0.280;157;0.439;0.196;167;0.454;0.208
0.05;6.56;0.693;48488;0.242;146;0.410;0.183;156;0.426;0.195
0.06;6.12;0.646;42814;0.214;139;0.388;0.173;149;0.405;0.186
0.07;5.75;0.607;37829;0.189;132;0.369;0.164;142;0.386;0.177
0.08;5.46;0.577;33634;0.168;126;0.352;0.157;136;0.370;0.170
0.09;5.28;0.558;29944;0.150;121;0.338;0.151;131;0.356;0.163
0.1;5.15;0.544;26675;0.133;116;0.325;0.145;126;0.344;0.158
0.2;4.19;0.442;7867;0.039;90;0.252;0.112;100;0.272;0.125
0.3;2.87;0.303;1852;0.009;82;0.228;0.102;92;0.250;0.114
0.4;1.24;0.131;268;0.001;79;0.222;0.099;89;0.244;0.112
0.5;0.47;0.050;55;0.000;79;0.222;0.099;89;0.243;0.111
1 Threshold SNR_Gain %SNR_Gain Adjustments %Adjustments Cycles %Cycles DSP_Load Cycles_new %Cycles_new DSP_Load_new
2 0 9.47 1.000 200000 1.000 357 1.000 0.446 367 1.000 0.459
3 0.001 9.47 1.000 174704 0.874 322 0.902 0.402 332 0.904 0.415
4 0.005 9.43 0.996 133980 0.670 265 0.743 0.332 275 0.750 0.344
5 0.01 9.27 0.979 108728 0.544 230 0.645 0.288 240 0.654 0.300
6 0.02 8.63 0.911 81434 0.407 192 0.538 0.240 202 0.551 0.253
7 0.03 7.84 0.828 66027 0.330 171 0.478 0.213 181 0.493 0.226
8 0.04 7.12 0.752 55964 0.280 157 0.439 0.196 167 0.454 0.208
9 0.05 6.56 0.693 48488 0.242 146 0.410 0.183 156 0.426 0.195
10 0.06 6.12 0.646 42814 0.214 139 0.388 0.173 149 0.405 0.186
11 0.07 5.75 0.607 37829 0.189 132 0.369 0.164 142 0.386 0.177
12 0.08 5.46 0.577 33634 0.168 126 0.352 0.157 136 0.370 0.170
13 0.09 5.28 0.558 29944 0.150 121 0.338 0.151 131 0.356 0.163
14 0.1 5.15 0.544 26675 0.133 116 0.325 0.145 126 0.344 0.158
15 0.2 4.19 0.442 7867 0.039 90 0.252 0.112 100 0.272 0.125
16 0.3 2.87 0.303 1852 0.009 82 0.228 0.102 92 0.250 0.114
17 0.4 1.24 0.131 268 0.001 79 0.222 0.099 89 0.244 0.112
18 0.5 0.47 0.050 55 0.000 79 0.222 0.099 89 0.243 0.111
Binary file not shown.
@@ -1,8 +1,8 @@
Update_Rate;SNR_Gain;%SNR_Gain;Cycles;%Cycles;%DSP_Load
1;9.47;1;357;1;0.446
0.75;8.54;0.902;288;0.805;0.359
0.66;8.16;0.862;262;0.735;0.328
0.5;7.27;0.768;218;0.611;0.273
0.33;6.05;0.639;171;0.478;0.213
0.25;5.21;0.550;149;0.416;0.186
0.2;4.59;0.485;135;0.377;0.168
Update_Rate;SNR_Gain;%SNR_Gain;Cycles;%Cycles;%DSP_Load;Cycles_new;%Cycles_new;%DSP_Load_new
1;9.47;1;357;1;0.446;386;1.000;0.483
0.75;8.54;0.902;288;0.805;0.359;317;0.820;0.396
0.66;8.16;0.862;262;0.735;0.328;291;0.755;0.364
0.5;7.27;0.768;218;0.611;0.273;247;0.640;0.309
0.33;6.05;0.639;171;0.478;0.213;200;0.517;0.250
0.25;5.21;0.550;149;0.416;0.186;178;0.460;0.222
0.2;4.59;0.485;135;0.377;0.168;164;0.424;0.205
1 Update_Rate SNR_Gain %SNR_Gain Cycles %Cycles %DSP_Load Cycles_new %Cycles_new %DSP_Load_new
2 1 9.47 1 357 1 0.446 386 1.000 0.483
3 0.75 8.54 0.902 288 0.805 0.359 317 0.820 0.396
4 0.66 8.16 0.862 262 0.735 0.328 291 0.755 0.364
5 0.5 7.27 0.768 218 0.611 0.273 247 0.640 0.309
6 0.33 6.05 0.639 171 0.478 0.213 200 0.517 0.250
7 0.25 5.21 0.550 149 0.416 0.186 178 0.460 0.222
8 0.2 4.59 0.485 135 0.377 0.168 164 0.424 0.205