Skip to content

Commit

Permalink
Update scipy simpson method
Browse files Browse the repository at this point in the history
  • Loading branch information
moble committed Mar 27, 2024
1 parent 610c256 commit 2b3c45c
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions content/MatchedFiltering.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1776,7 +1776,7 @@
},
{
"cell_type": "code",
"source": "# Filter and rescale arbitrarily to match amplitude of data\nnr_filtered_h = 0.55 * filter_signal(nr, sampling_rate, noisy_signal=h)\nnr_filtered_h_tilde = dt * np.fft.rfft(nr_filtered_h)\nnr_filtered_l = 0.55 * filter_signal(nr, sampling_rate, noisy_signal=l)\nnr_filtered_l_tilde = dt * np.fft.rfft(nr_filtered_l)\n\n# Now, plot and play the *filtered* NR data on top of the filtered detector data\nplt.close()\nplt.plot(t+0.0072, -l_filtered, label='Livingston')\nplt.plot(t, h_filtered, label='Hanford')\nplt.plot(t-0.002, nr_filtered_h, label='Simulated and filtered')\nplt.xlim(16.1, 16.5)\nplt.xlabel('Time (seconds)')\nplt.ylabel('Detector strain $h$ (dimensionless)')\nplt.title('Filtered detector data and simulated signal')\nplt.grid()\nplt.legend(loc='upper left');\ndisplay(Audio(data=np.vstack((np.roll(-l_filtered, int(0.0072*sampling_rate)),\n h_filtered,\n np.roll(nr_filtered_h, int(-0.002*sampling_rate)))),\n rate=sampling_rate))",
"source": "# Filter and rescale arbitrarily to match amplitude of data\nnr_filtered_h = 0.55 * filter_signal(nr, sampling_rate, noisy_signal=h)\nnr_filtered_h_tilde = dt * np.fft.rfft(nr_filtered_h)\nnr_filtered_l = 0.55 * filter_signal(nr, sampling_rate, noisy_signal=l)\nnr_filtered_l_tilde = dt * np.fft.rfft(nr_filtered_l)\n\n# Now, plot and play the *filtered* NR data on top of the filtered detector data\nplt.close()\nplt.plot(t+0.0072, -l_filtered, label='Livingston')\nplt.plot(t, h_filtered, label='Hanford')\nplt.plot(t-0.002, nr_filtered_h, label='Simulated and filtered')\nplt.xlim(16.0, 16.5)\nplt.xlabel('Time (seconds)')\nplt.ylabel('Detector strain $h$ (dimensionless)')\nplt.title('Filtered detector data and filtered simulated signal')\nplt.grid()\nplt.legend(loc='upper left');\ndisplay(Audio(data=np.vstack((np.roll(-l_filtered, int(0.0072*sampling_rate)),\n h_filtered,\n np.roll(nr_filtered_h, int(-0.002*sampling_rate)))),\n rate=sampling_rate))",
"metadata": {
"ExecuteTime": {
"end_time": "2020-07-02T16:02:07.390183Z",
Expand Down Expand Up @@ -1833,7 +1833,7 @@
},
{
"cell_type": "code",
"source": "# Add small time offsets to the filtered detector data, to align the measured data to the model,\n# and evaluate the correlation. (The precise time offsets will be derived below.)\nl_correlation = np.roll(-l_filtered, 37) * nr_filtered_h\nh_correlation = np.roll(+h_filtered, 7) * nr_filtered_l\n\n# Integrate the correlation functions over time\nc_l = scipy.integrate.simps(l_correlation, t)\nc_h = scipy.integrate.simps(h_correlation, t)\ndisplay(Latex(r'$c_{{\\mathrm{{Livingston}}}} = {0:.4f}$'.format(c_l)))\ndisplay(Latex(r'$c_{{\\mathrm{{Hanford}}}} = {0:.4f}$'.format(c_h)))\n\n# Plot the correlation functions as functions of time\nplt.close()\nplt.plot(t, l_correlation, label='Livingston')\nplt.plot(t, h_correlation, label='Hanford')\nplt.grid()\nplt.xlim(16.25, 16.5)\nplt.xlabel('Time (seconds)')\nplt.ylabel('Correlation between data and simulated signal')\nplt.legend();",
"source": "# Add small time offsets to the filtered detector data, to align the measured data to the model,\n# and evaluate the correlation. (The precise time offsets will be derived below.)\nl_correlation = np.roll(-l_filtered, 37) * nr_filtered_h\nh_correlation = np.roll(+h_filtered, 7) * nr_filtered_l\n\n# Integrate the correlation functions over time\nc_l = scipy.integrate.simpson(y=l_correlation, x=t)\nc_h = scipy.integrate.simpson(y=h_correlation, x=t)\ndisplay(Latex(r'$c_{{\\mathrm{{Livingston}}}} = {0:.4f}$'.format(c_l)))\ndisplay(Latex(r'$c_{{\\mathrm{{Hanford}}}} = {0:.4f}$'.format(c_h)))\n\n# Plot the correlation functions as functions of time\nplt.close()\nplt.plot(t, l_correlation, label='Livingston')\nplt.plot(t, h_correlation, label='Hanford')\nplt.grid()\nplt.xlim(16.25, 16.5)\nplt.xlabel('Time (seconds)')\nplt.ylabel('Correlation between data and simulated signal')\nplt.legend();",
"metadata": {
"ExecuteTime": {
"end_time": "2020-07-02T16:02:08.020992Z",
Expand Down

0 comments on commit 2b3c45c

Please sign in to comment.