From 7740868444967584d2b98fcb21c92587fb55f0a9 Mon Sep 17 00:00:00 2001 From: jaseg Date: Wed, 5 Feb 2020 09:11:05 +0100 Subject: Add some pictures --- gm_platform/fw/grid_scope.ipynb | 78 +++++++++++++++++++++++++++++++++-------- 1 file changed, 64 insertions(+), 14 deletions(-) (limited to 'gm_platform') diff --git a/gm_platform/fw/grid_scope.ipynb b/gm_platform/fw/grid_scope.ipynb index ea641f0..a04b2db 100644 --- a/gm_platform/fw/grid_scope.ipynb +++ b/gm_platform/fw/grid_scope.ipynb @@ -196,7 +196,7 @@ }, { "cell_type": "code", - "execution_count": 45, + "execution_count": 124, "metadata": { "scrolled": false }, @@ -984,7 +984,7 @@ { "data": { "text/html": [ - "" + "" ], "text/plain": [ "" @@ -995,15 +995,16 @@ } ], "source": [ - "fig, (top, bottom) = plt.subplots(2, figsize=(9,6), sharex=True)\n", - "fig.tight_layout()\n", + "fig, (top, bottom) = plt.subplots(2, figsize=(9,6))\n", + "fig.tight_layout(pad=3, h_pad=0.1)\n", "\n", "range_start, range_len = -300, 60 # [s]\n", "\n", "data_slice = data[ int(range_start * sampling_rate) : int((range_start + range_len) * sampling_rate) ]\n", "\n", "top.grid()\n", - "top.plot(np.linspace(0, range_len, int(range_len*sampling_rate)), data_slice, lw=0.5)\n", + "top.plot(np.linspace(0, range_len, int(range_len*sampling_rate)), data_slice, lw=1.0)\n", + "top.set_xlim([range_len/2-0.25, range_len/2+0.25])\n", "mean = np.mean(data_not_nan)\n", "rms = np.sqrt(np.mean(np.square(data_not_nan - mean)))\n", "peak = np.max(np.abs(data_not_nan - mean))\n", @@ -1015,8 +1016,9 @@ "\n", "bottom.grid()\n", "bottom.specgram(data_slice, Fs=sampling_rate)\n", - "bottom.yaxis.set_label('F [Hz]')\n", - "bottom.xaxis.set_label('t [s]')\n", + "top.set_ylabel('U [V]')\n", + "bottom.set_ylabel('F [Hz]')\n", + "bottom.set_xlabel('t [s]')\n", "None" ] }, @@ -1935,7 +1937,7 @@ }, { "cell_type": "code", - "execution_count": 106, + "execution_count": 119, "metadata": { "scrolled": false }, @@ -2723,7 +2725,7 @@ { "data": { "text/html": [ - "" + "" ], "text/plain": [ "" @@ -2753,8 +2755,9 @@ "if not label in ['off_frequency', 'sweep_phase_steps']:\n", " ax.set_ylim([49.90, 50.10])\n", " var = np.var(f_mean[~np.isnan(f_mean)][1:-1])\n", - " ax.text(0.5, 0.1, f'σ²={var * 1e3:.3g} mHz²', transform=ax.transAxes, ha='center')\n", - " ax.text(0.5, 0.15, f'σ={np.sqrt(var) * 1e3:.3g} mHz', transform=ax.transAxes, ha='center')\n", + " ax.text(0.5, 0.08, f'σ²={var * 1e3:.3g} mHz²', transform=ax.transAxes, ha='center', color='white', bbox=bbox)\n", + " ax.text(0.5, 0.15, f'σ={np.sqrt(var) * 1e3:.3g} mHz', transform=ax.transAxes, ha='center', color='white', bbox=bbox)\n", + "\n", "# ax.text(0.5, 0.2, f'filt. σ²={np.var(filtered) * 1e3:.3g} mHz', transform=ax.transAxes, ha='center')\n", "else:\n", " f_min, f_max = min(f_mean[1:-1]), max(f_mean[1:-1])\n", @@ -2770,7 +2773,7 @@ }, { "cell_type": "code", - "execution_count": 102, + "execution_count": 115, "metadata": { "scrolled": false }, @@ -3558,7 +3561,7 @@ { "data": { "text/html": [ - "" + "" ], "text/plain": [ "" @@ -3612,6 +3615,14 @@ " patches.Patch(color='orange', label='low-pass filtered'),\n", " patches.Patch(color='red', label='band-pass filtered')])\n", "\n", + "#ax2r.spines['right'].set_color('red')\n", + "ax2r.yaxis.label.set_color('red')\n", + "#ax2r.tick_params(axis='y', colors='red')\n", + "\n", + "#ax1r.spines['right'].set_color('red')\n", + "ax1r.yaxis.label.set_color('red')\n", + "#ax1r.tick_params(axis='y', colors='red')\n", + "\n", "ax1.set_ylabel('f [Hz]')\n", "ax1r.set_ylabel('band-pass Δf [Hz]')\n", "ax2.set_ylabel('f [Hz]')\n", @@ -3620,9 +3631,48 @@ "# Cut out first 10min of filtered data to give filters time to settle\n", "rms_slice = filtered2[np.where(f_t[1:] > 10*60)[0][0]:]\n", "rms = np.sqrt(np.mean(np.square(rms_slice)))\n", - "ax1.text(0.5, 0.1, f'RMS (filtered): {rms*1e3:.3f}mHz', transform=ax1.transAxes, color='white', bbox=bbox, ha='center')\n", + "ax1.text(0.5, 0.1, f'RMS (band-pass): {rms*1e3:.3f}mHz', transform=ax1.transAxes, color='white', bbox=bbox, ha='center')\n", "None" ] + }, + { + "cell_type": "code", + "execution_count": 127, + "metadata": {}, + "outputs": [], + "source": [ + "chunk_size = 256\n", + "\n", + "with open('filtered_freq.bin', 'wb') as f:\n", + " for chunk in range(0, len(rms_slice), chunk_size):\n", + " out_data = rms_slice[chunk:chunk+chunk_size]\n", + " f.write(struct.pack(f'{len(out_data)}f', *out_data))\n", + " \n", + "with open('raw_freq.bin', 'wb') as f:\n", + " for chunk in range(0, len(f_copy), chunk_size):\n", + " out_data = f_copy[chunk:chunk+chunk_size]\n", + " f.write(struct.pack(f'{len(out_data)}f', *out_data))" + ] + }, + { + "cell_type": "code", + "execution_count": 128, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "54.0" + ] + }, + "execution_count": 128, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "27000 * 2e-3" + ] } ], "metadata": { -- cgit