From 18bd197a42113aebb76bd79b0cee0a9ff2042648 Mon Sep 17 00:00:00 2001
From: Oscar Gustafsson <oscar.gustafsson@gmail.com>
Date: Sun, 26 Feb 2023 16:43:56 +0100
Subject: [PATCH] Replace SciPy with mplsignal

---
 README.md                       |  2 +-
 docs_sphinx/conf.py             |  1 +
 examples/firstorderiirfilter.py | 12 +++++-------
 examples/thirdorderblwdf.py     |  8 ++------
 requirements_doc.txt            |  2 +-
 5 files changed, 10 insertions(+), 15 deletions(-)

diff --git a/README.md b/README.md
index f2df4a12..8e24e07b 100644
--- a/README.md
+++ b/README.md
@@ -55,7 +55,7 @@ To generate the documentation, the following additional packages are required:
     -   [Furo](https://pradyunsg.me/furo/)
     -   [numpydoc](https://numpydoc.readthedocs.io/)
     -   [Sphinx-Gallery](https://sphinx-gallery.github.io/)
-    -   [SciPy](https://scipy.org/)
+    -   [mplsignal](https://mplsignal.readthedocs.io/)
 
 ### Using CMake directly
 
diff --git a/docs_sphinx/conf.py b/docs_sphinx/conf.py
index 90b049c7..670495e0 100644
--- a/docs_sphinx/conf.py
+++ b/docs_sphinx/conf.py
@@ -40,6 +40,7 @@ intersphinx_mapping = {
     'numpy': ('https://numpy.org/doc/stable/', None),
     'PyQt5': ("https://www.riverbankcomputing.com/static/Docs/PyQt5", None),
     'networkx': ('https://networkx.org/documentation/stable', None),
+    'mplsignal': ('https://mplsignal.readthedocs.io/en/stable/', None),
 }
 
 numpydoc_show_class_members = False
diff --git a/examples/firstorderiirfilter.py b/examples/firstorderiirfilter.py
index 51de36b9..16baebeb 100644
--- a/examples/firstorderiirfilter.py
+++ b/examples/firstorderiirfilter.py
@@ -191,15 +191,14 @@ plt.show()
 
 
 # %%
-# To compute and plot the frequency response, it is possible to use SciPy and NumPy as
+# To compute and plot the frequency response, it is possible to use mplsignal
 
-import numpy as np
-import scipy.signal
+from mplsignal.freq_plots import freqz_fir
 
-w, h = scipy.signal.freqz(sim.results['0'])
-plt.plot(w, 20 * np.log10(np.abs(h)))
+freqz_fir(sim.results["0"])
 plt.show()
 
+
 # %%
 # As seen, the output has not converged to zero, leading to that the frequency-response may not be correct, so we want
 # to simulate for a longer time.
@@ -225,6 +224,5 @@ plt.show()
 # %%
 # And the frequency-response:
 
-w, h = scipy.signal.freqz(sim.results['0'])
-plt.plot(w, 20 * np.log10(np.abs(h)))
+freqz_fir(sim.results["0"])
 plt.show()
diff --git a/examples/thirdorderblwdf.py b/examples/thirdorderblwdf.py
index 663d1314..117041fc 100644
--- a/examples/thirdorderblwdf.py
+++ b/examples/thirdorderblwdf.py
@@ -31,13 +31,9 @@ sfg.set_execution_time_of_type(Addition.type_name(), 1)
 sim = Simulation(sfg, [lambda n: 0 if n else 1])
 sim.run_for(1000)
 
-import scipy.signal
-
-w, h = scipy.signal.freqz(sim.results['0'])
-
-import matplotlib.pyplot as plt
 import numpy as np
+from mplsignal.freq_plots import freqz_fir
 
-plt.plot(w, 20 * np.log10(np.abs(h) / 2))
+freqz_fir(np.array(sim.results['0']) / 2)
 
 schedule = Schedule(sfg, cyclic=True)
diff --git a/requirements_doc.txt b/requirements_doc.txt
index 6aacbb63..cc10b763 100644
--- a/requirements_doc.txt
+++ b/requirements_doc.txt
@@ -2,4 +2,4 @@ sphinx
 furo
 numpydoc
 sphinx-gallery
-scipy
+mplsignal
-- 
GitLab