.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/amplitude_retrieval.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_gallery_amplitude_retrieval.py: Non-Maximum Suppression for Gaussian Pulse Detection ==================================================== This example demonstrates the use of the NonMaximumSuppression class to detect Gaussian pulses in a one-dimensional signal. It generates a synthetic dataset of Gaussian pulses, applies the non-maximum suppression algorithm, and plots the results. .. GENERATED FROM PYTHON SOURCE LINES 10-34 .. code-block:: Python from DeepPeak.algorithms import NonMaximumSuppression from DeepPeak.algorithms.amplitude import ClosedFormSolver from DeepPeak.signals import Kernel, SignalDatasetGenerator NUM_PEAKS = 3 SEQUENCE_LENGTH = 400 gaussian_width = 0.03 generator = SignalDatasetGenerator(n_samples=1, sequence_length=SEQUENCE_LENGTH) dataset = generator.generate( signal_type=Kernel.GAUSSIAN, n_peaks=2, amplitude=(50, 100), # Amplitude range position=(0.3, 0.6), # Peak position range width=gaussian_width, # Width range noise_std=0.3, # Add some noise categorical_peak_count=False, ) dataset.plot() .. image-sg:: /gallery/images/sphx_glr_amplitude_retrieval_001.png :alt: amplitude retrieval :srcset: /gallery/images/sphx_glr_amplitude_retrieval_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 35-36 Configure and run the detector .. GENERATED FROM PYTHON SOURCE LINES 36-69 .. code-block:: Python peak_locator = NonMaximumSuppression( gaussian_sigma=0.003, threshold="auto", maximum_number_of_pulses=3, kernel_truncation_radius_in_sigmas=3, ) peak_locator.run(time_samples=dataset.x_values, signal=dataset.signals.squeeze()) peak_amplitudes = peak_locator.results["peak_amplitude"] peak_centers = peak_locator.results["peak_times"] solver = ClosedFormSolver(sigma=dataset.widths.mean().squeeze() / 1.5) result = solver.run(centers=peak_centers, matched_responses=peak_locator.results["peak_amplitude"]) print( f""" True Centers: {dataset.positions} Measured Centers: {peak_locator.results['peak_times']} True Amplitudes: {dataset.amplitudes} Solved Amplitudes: {result}\n """ ) solver.plot(true_amplitudes=dataset.amplitudes.squeeze()) .. image-sg:: /gallery/images/sphx_glr_amplitude_retrieval_002.png :alt: Gram matrix (cond ≈ 1.00e+00), Amplitudes :srcset: /gallery/images/sphx_glr_amplitude_retrieval_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none True Centers: [[0.44057223 0.58000502]] Measured Centers: [0.44110276 0.57894737] True Amplitudes: [[78.18199069 91.58236372]] Solved Amplitudes: [160.49469496 187.53111687] /opt/hostedtoolcache/Python/3.11.13/x64/lib/python3.11/site-packages/DeepPeak/algorithms/amplitude/closed_form.py:160: UserWarning: Glyph 8776 (\N{ALMOST EQUAL TO}) missing from font(s) cmr10. plt.tight_layout() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.486 seconds) .. _sphx_glr_download_gallery_amplitude_retrieval.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: amplitude_retrieval.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: amplitude_retrieval.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: amplitude_retrieval.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_