From 84144488551a58f8b1a34b1de541a7be4d7364a6 Mon Sep 17 00:00:00 2001 From: "Edgar P. Burkhart" Date: Sun, 9 Feb 2025 22:29:56 +0100 Subject: [PATCH 01/19] Enhance serve workflow by modifying build command to execute during HTML generation --- .forgejo/workflows/serve.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.forgejo/workflows/serve.yaml b/.forgejo/workflows/serve.yaml index d6094bf..6e3215b 100644 --- a/.forgejo/workflows/serve.yaml +++ b/.forgejo/workflows/serve.yaml @@ -13,7 +13,7 @@ jobs: - name: Install dependencies run: ./.env/bin/pip install mystmd jupyterlab_myst ipykernel altair pandas - name: Build static HTML - run: ./.env/bin/myst build --html + run: ./.env/bin/myst build --execute --html - name: Copy files run: | rm -rf /data/srv/forgejo-runner/cours4.0 From ec450c6092e749f3a4434a70ae3f171fc169bae0 Mon Sep 17 00:00:00 2001 From: "Edgar P. Burkhart" Date: Sun, 9 Feb 2025 22:33:16 +0100 Subject: [PATCH 02/19] Update serve workflow to include 'jupyter' dependency in installation --- .forgejo/workflows/serve.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.forgejo/workflows/serve.yaml b/.forgejo/workflows/serve.yaml index 6e3215b..85e4709 100644 --- a/.forgejo/workflows/serve.yaml +++ b/.forgejo/workflows/serve.yaml @@ -11,7 +11,7 @@ jobs: - name: Initialize virtual environment run: /usr/bin/python -m venv .env - name: Install dependencies - run: ./.env/bin/pip install mystmd jupyterlab_myst ipykernel altair pandas + run: ./.env/bin/pip install mystmd jupyter jupyterlab_myst ipykernel altair pandas - name: Build static HTML run: ./.env/bin/myst build --execute --html - name: Copy files From cb665904ee4e7913d9474f8a8e74fb3934840e74 Mon Sep 17 00:00:00 2001 From: "Edgar P. Burkhart" Date: Sun, 9 Feb 2025 22:36:53 +0100 Subject: [PATCH 03/19] Fix serve workflow to correct 'jupyterlab' dependency in installation --- .forgejo/workflows/serve.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.forgejo/workflows/serve.yaml b/.forgejo/workflows/serve.yaml index 85e4709..a5d7fe9 100644 --- a/.forgejo/workflows/serve.yaml +++ b/.forgejo/workflows/serve.yaml @@ -11,7 +11,7 @@ jobs: - name: Initialize virtual environment run: /usr/bin/python -m venv .env - name: Install dependencies - run: ./.env/bin/pip install mystmd jupyter jupyterlab_myst ipykernel altair pandas + run: ./.env/bin/pip install mystmd jupyterlab jupyterlab_myst ipykernel altair pandas - name: Build static HTML run: ./.env/bin/myst build --execute --html - name: Copy files From a31ab300c216d23e737a363b6ee350cbfd0b1b5c Mon Sep 17 00:00:00 2001 From: "Edgar P. Burkhart" Date: Sun, 9 Feb 2025 22:40:57 +0100 Subject: [PATCH 04/19] Fix serve workflow to correctly install 'jupyter' dependency and update build command for HTML generation --- .forgejo/workflows/serve.yaml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.forgejo/workflows/serve.yaml b/.forgejo/workflows/serve.yaml index a5d7fe9..6bd8ab9 100644 --- a/.forgejo/workflows/serve.yaml +++ b/.forgejo/workflows/serve.yaml @@ -11,9 +11,11 @@ jobs: - name: Initialize virtual environment run: /usr/bin/python -m venv .env - name: Install dependencies - run: ./.env/bin/pip install mystmd jupyterlab jupyterlab_myst ipykernel altair pandas + run: ./.env/bin/pip install mystmd jupyter jupyterlab_myst ipykernel altair pandas - name: Build static HTML - run: ./.env/bin/myst build --execute --html + run: | + . ./env/bin/activate + myst build --execute --html - name: Copy files run: | rm -rf /data/srv/forgejo-runner/cours4.0 From 1a992a81748cd5a1189e55e84e5d0d3011be1f6c Mon Sep 17 00:00:00 2001 From: "Edgar P. Burkhart" Date: Sun, 9 Feb 2025 22:40:57 +0100 Subject: [PATCH 05/19] Fix serve workflow to correctly install 'jupyter' dependency and update build command for HTML generation --- .forgejo/workflows/serve.yaml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.forgejo/workflows/serve.yaml b/.forgejo/workflows/serve.yaml index a5d7fe9..8f8b4ba 100644 --- a/.forgejo/workflows/serve.yaml +++ b/.forgejo/workflows/serve.yaml @@ -11,9 +11,11 @@ jobs: - name: Initialize virtual environment run: /usr/bin/python -m venv .env - name: Install dependencies - run: ./.env/bin/pip install mystmd jupyterlab jupyterlab_myst ipykernel altair pandas + run: ./.env/bin/pip install mystmd jupyter jupyterlab_myst ipykernel altair pandas - name: Build static HTML - run: ./.env/bin/myst build --execute --html + run: | + . .env/bin/activate + myst build --execute --html - name: Copy files run: | rm -rf /data/srv/forgejo-runner/cours4.0 From 1e808ae6b843fb7c12d36d3ca41adccc2b327fd3 Mon Sep 17 00:00:00 2001 From: "Edgar P. Burkhart" Date: Sun, 9 Feb 2025 22:43:18 +0100 Subject: [PATCH 06/19] Remove unused imports from 02-signaux.md --- cours/SIN/02-signaux.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/cours/SIN/02-signaux.md b/cours/SIN/02-signaux.md index 1a4929f..899f7cd 100644 --- a/cours/SIN/02-signaux.md +++ b/cours/SIN/02-signaux.md @@ -34,10 +34,7 @@ et un niveau **bas** ("Low"). :tags: [remove-input] import altair as alt import pandas as pd -import matplotlib.pyplot as plt -import numpy as np import random -from scipy.interpolate import CubicSpline random.seed(25) From 5691023d0c081e23cfff185156441b9b65557840 Mon Sep 17 00:00:00 2001 From: "Edgar P. Burkhart" Date: Mon, 10 Feb 2025 18:34:49 +0100 Subject: [PATCH 07/19] Refactor signal examples in 02-signaux.md to improve clarity and consistency --- cours/SIN/02-signaux.md | 102 +++++++++++++++++++++++++++++++++++----- 1 file changed, 90 insertions(+), 12 deletions(-) diff --git a/cours/SIN/02-signaux.md b/cours/SIN/02-signaux.md index 899f7cd..919c48e 100644 --- a/cours/SIN/02-signaux.md +++ b/cours/SIN/02-signaux.md @@ -33,15 +33,15 @@ et un niveau **bas** ("Low"). ```{code-cell} python :tags: [remove-input] import altair as alt +import numpy as np import pandas as pd -import random -random.seed(25) +rng = np.random.default_rng(25) n = 16 -t = range(n+1) -s = random.choices([0, 1], k=n) -s += s[-1:] +t = np.arange(n+1) +s = rng.choice([0, 1], n+1) +s[-1] = s[-2] data = pd.DataFrame({ "t": t, "s": s, @@ -49,24 +49,102 @@ data = pd.DataFrame({ alt.Chart( data ).mark_line( - interpolate="step-after" + interpolate="step-after", + strokeWidth=3, ).encode( alt.X("t:Q").axis(title="Temps (s)").scale(domain=(0,n)), - alt.Y("s:Q", axis=alt.Axis(title="Signal logique", tickMinStep=1.0)).scale(domain=(0,1)), + alt.Y("s:Q", axis=alt.Axis(title="Signal logique", values=[0, 1], format=".0f")).scale(domain=(0,1)), ).properties( width="container", + height=100, ) - ``` Exemple de signal logique ```` -Le signal logique en @logique est par exemple à l'état haut entre 1 s et 3 s, -et à l'état bas entre 8 s et 11 s. -Lorsque le signal passe de l'état bas à l'état haut (comme à 1 s), +Le signal logique en @logique est par exemple à l'état haut entre 2 s et 3 s, +et à l'état bas entre 3 s et 6 s. +Lorsque le signal passe de l'état bas à l'état haut (comme à 2 s), on parle de **front montant**. Dans le cas contraire (comme à 3 s), on parle de **front descendant**. ## Les signaux analogiques -Un signal analogique est un signal qui peut prendre un ensemble continu de valeurs. \ No newline at end of file +Un signal analogique est un signal qui peut prendre un ensemble continu de valeurs. +Un exemple de signal analogique est donné en @analogique. + +````{figure} +:label: analogique +```{code-cell} python +:tags: [remove-input] +import altair as alt +import numpy as np +import pandas as pd + +rng = np.random.default_rng(25) + +n = 20 +t_max = 16 + +t = np.linspace(0, t_max, n) + +s = 5 * rng.random(n) +s[-1] = s[-2] +data = pd.DataFrame({ + "t": t, + "s": s, +}) +alt.Chart( + data +).mark_line( + interpolate="basis", + strokeWidth=3, +).encode( + alt.X("t:Q").axis(title="Temps (s)").scale(domain=(0,t_max)), + alt.Y("s:Q", axis=alt.Axis(title="Signal analogique")).scale(domain=(0,5)), +).properties( + width="container", + height=200, +) +``` +Exemple de signal analogique +```` + +## Les signaux numériques +Un signal numérique est un signal qui peut prendre un ensemble discret de valeur, +c'est-à-dire un ensemble précis de valeurs distinctes (généralement des nombres entiers). +Un exemple de signal analogique est donné en @numerique. + +````{figure} +:label: numerique +```{code-cell} python +:tags: [remove-input] +import altair as alt +import numpy as np +import pandas as pd + +rng = np.random.default_rng(25) + +n = 16 +t = np.arange(n+1) +s = rng.integers(0, 16, n+1) +s[-1] = s[-2] +data = pd.DataFrame({ + "t": t, + "s": s, +}) +alt.Chart( + data +).mark_line( + interpolate="step-after", + strokeWidth=3, +).encode( + alt.X("t:Q").axis(title="Temps (s)").scale(domain=(0,n)), + alt.Y("s:Q", axis=alt.Axis(title="Signal numérique", values=np.arange(0, 16))).scale(domain=(0,15)), +).properties( + width="container", + height=200, +) +``` +Exemple de signal numérique +```` \ No newline at end of file From 8acd77664bc5930f16ea03a016c08c7adbbe3eed Mon Sep 17 00:00:00 2001 From: "Edgar P. Burkhart" Date: Mon, 10 Feb 2025 21:40:48 +0100 Subject: [PATCH 08/19] Update figure labels in 01-capteurs.md and 02-signaux.md for consistency --- cours/SIN/01-capteurs.md | 6 +++--- cours/SIN/02-signaux.md | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/cours/SIN/01-capteurs.md b/cours/SIN/01-capteurs.md index 0c3deb9..fbffa9b 100644 --- a/cours/SIN/01-capteurs.md +++ b/cours/SIN/01-capteurs.md @@ -29,7 +29,7 @@ Un interrupteur (@inter) ou un détecteur de mouvement PIR (@pir) sont des capte tout ou rien. ::::{figure} -:label: tor +:label: fig:capteur-tor :::{figure} https://upload.wikimedia.org/wikipedia/commons/3/3a/Switches-electrical.agr.jpg :label: inter @@ -60,7 +60,7 @@ Une thermistance (@thermistance) ou une jauge de déformation (@jauge) sont des capteurs analogiques. ::::{figure} -:label: analogique +:label: fig:capteur-analogique :::{figure} https://upload.wikimedia.org/wikipedia/commons/3/3b/NTC_bead.jpg :label: thermistance @@ -88,7 +88,7 @@ Un capteur numérique génère un signal de sortie ne pouvant prendre qu'un cert Une caméra (@camera) ou un codeur absolu (@codeur) sont des capteurs numériques. ::::{figure} -:label: numeriques +:label: fig:capteur-numerique :::{figure} https://upload.wikimedia.org/wikipedia/commons/0/02/S4000_Image_Sensor_%28Colorful%29.jpg :label: camera diff --git a/cours/SIN/02-signaux.md b/cours/SIN/02-signaux.md index 919c48e..651ccee 100644 --- a/cours/SIN/02-signaux.md +++ b/cours/SIN/02-signaux.md @@ -29,7 +29,7 @@ Un signal logique ne peut prendre que deux valeurs : un niveau **haut** ("High") et un niveau **bas** ("Low"). ````{figure} -:label: logique +:label: fig:sig-logique ```{code-cell} python :tags: [remove-input] import altair as alt @@ -62,7 +62,7 @@ alt.Chart( Exemple de signal logique ```` -Le signal logique en @logique est par exemple à l'état haut entre 2 s et 3 s, +Le signal logique en @fig:sig-logique est par exemple à l'état haut entre 2 s et 3 s, et à l'état bas entre 3 s et 6 s. Lorsque le signal passe de l'état bas à l'état haut (comme à 2 s), on parle de **front montant**. @@ -71,10 +71,10 @@ Dans le cas contraire (comme à 3 s), on parle de **front descendant**. ## Les signaux analogiques Un signal analogique est un signal qui peut prendre un ensemble continu de valeurs. -Un exemple de signal analogique est donné en @analogique. +Un exemple de signal analogique est donné en @fig:sig-analogique. ````{figure} -:label: analogique +:label: fig:sig-analogique ```{code-cell} python :tags: [remove-input] import altair as alt @@ -113,10 +113,10 @@ Exemple de signal analogique ## Les signaux numériques Un signal numérique est un signal qui peut prendre un ensemble discret de valeur, c'est-à-dire un ensemble précis de valeurs distinctes (généralement des nombres entiers). -Un exemple de signal analogique est donné en @numerique. +Un exemple de signal analogique est donné en @fig:sig-numerique. ````{figure} -:label: numerique +:label: fig:sig-numerique ```{code-cell} python :tags: [remove-input] import altair as alt From 5d9d2e0ea0d7f6186528316b0d279c812045785e Mon Sep 17 00:00:00 2001 From: "Edgar P. Burkhart" Date: Mon, 10 Feb 2025 21:41:06 +0100 Subject: [PATCH 09/19] =?UTF-8?q?WIP:=20Add=20new=20course=20material=20on?= =?UTF-8?q?=20CAN=20(Convertisseur=20Analogique=20Num=C3=A9rique)=20with?= =?UTF-8?q?=20definitions,=20sampling,=20and=20conversion=20examples?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cours/SIN/03-can.md | 141 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 141 insertions(+) create mode 100644 cours/SIN/03-can.md diff --git a/cours/SIN/03-can.md b/cours/SIN/03-can.md new file mode 100644 index 0000000..9b40196 --- /dev/null +++ b/cours/SIN/03-can.md @@ -0,0 +1,141 @@ +--- +title: Le CAN +subject: Cours +kernelspec: + name: python3 + display_name: Python 3 +abbreviations: + CAN: Convertisseur Analogique Numérique +--- + +# Définition + +:::{prf:definition} CAN +:nonumber: true +Un convertisseur analogique-numérique est un dispositif électronique dont la fonction est de traduire une grandeur analogique en une valeur numérique codée sur plusieurs bits. Le signal converti est généralement une tension électrique. + +Source : Article _[Convertisseur analogique-numérique](http://fr.wikipedia.org/wiki/Convertisseur_analogique-num%C3%A9rique)_ de [Wikipédia en français](https://fr.wikipedia.org/) ([auteurs](http://fr.wikipedia.org/w/index.php?title=Convertisseur_analogique-num%C3%A9rique&action=history)) +::: + +# L'échantillonage du signal +L'échantillonage du signal est la prise d'une valeur à un intervalle régulier de temps. L'intervalle entre deux valeurs s'appelle **période d'échantillonage**. On la note $T_e$ (en secondes). On parle aussi de **fréquence d'échantillonage** $f_e=\frac{1}{T_e}$ (en Hertz), qui correspond au nombre de valeurs prises chaque seconde. + +Le **quantum** correspond au plus petit écart quantifiable (la "hauteur d'une marche"). On le note $q$ et son unité est celle du signal d'entrée (généralement le Volt). + +La **tension de pleine échelle** ou **tension de référence** est la tension maximale quantifiable par le CAN. On la note $V_\text{pe}$ ou $V_\text{ref}$. + +Le nombre de valeurs que peut générer le convertisseur se note $N$ et dépend du nombre de bits $n$ du convertisseur. Ainsi : $N=2^n$. + +On obtient la relation suivante : $q=\frac{V_\text{pe}}{N}=\frac{V_\text{pe}}{2^n}$. + +# Exemple de conversion +On donne en @fig:exemple-can l'exemple d'un CAN de tension de référence 5 V fonctionnant sur 3 bits avec une fréquence d'échantillonage de 2 Hz. + +La **caractéristique** du CAN est la courbe représentant la valeur numérique en sortie en fonction de la valeur analogique en entrée (@fig:carac-can). + +````{figure} +:label: fig:exemple-can +```{code-cell} python +:tags: [remove-input] +import altair as alt +import numpy as np +import pandas as pd +from scipy import interpolate + +rng = np.random.default_rng(25) + +n = 20 +t_max = 16 + +T = np.linspace(0, t_max, 1601) +y = np.clip( + interpolate.BSpline(np.linspace(0, t_max, n), 5 * rng.random(n), 2)(T), + 0, + 5, +) +y_n = np.full([1601], np.nan) +y_n[::50] = np.floor(y[::50] * 8 / 5) +y_n[y_n == 8] = 7 + + +data = pd.DataFrame({ + "t": T, + "s": y, + "s_n": y_n, +}) + +base = alt.Chart( + data +).encode( + alt.X("t:Q").axis(title="Temps (s)").scale(domain=(0,t_max)), +) + +ch = base.mark_line( + interpolate="basis", + strokeWidth=3, + color="#6666cc", +).encode( + alt.Y("s:Q", axis=alt.Axis(title="Signal analogique", titleColor="#6666cc")).scale(domain=(0,5)), +) + +ch_n = base.mark_point( + filled=True, + color="#ff6600", +).encode( + alt.Y( + "s_n:Q", + axis=alt.Axis( + title="Signal numérisé", + titleColor="#ff6600", + values=np.arange(8), + ) + ).scale(domain=(0,8)), +) + +alt.layer(ch_n, ch).resolve_scale( + y="independent", +).properties( + width="container", + height=200, +) + + +``` +Signal analogique et signal numérisé. +```` + +````{figure} +:label: fig:carac-can +```{code-cell} python +:tags: [remove-input] +import altair as alt +import numpy as np +import pandas as pd +from scipy import interpolate + +N = 8 +s_n = np.arange(N+1) +s_n[-1] = s_n[-2] +data = pd.DataFrame({ + "s_n": s_n, + "s_a": np.linspace(0, 5, N+1), +}) + +alt.Chart( + data +).mark_line( + interpolate="step-after", + strokeWidth=3, + color="#ff6600", +).encode( + alt.X("s_a:Q").axis(title="Signal Analogique").scale(domain=(0,5)), + alt.Y("s_n:Q", axis=alt.Axis(title="Signal numérique", values=np.arange(N))).scale(domain=(0,N)), +).properties( + width=200, + height=200, +) + + +``` +Caractéristique du CAN. +```` \ No newline at end of file From 0503034e4087735eb9e308c02e71159d937120c9 Mon Sep 17 00:00:00 2001 From: "Edgar P. Burkhart" Date: Thu, 27 Feb 2025 17:32:53 +0100 Subject: [PATCH 10/19] Update workflow configuration and replace Altair with Matplotlib for signal visualizations --- .forgejo/workflows/serve.yaml | 6 +- cours/SIN/01-capteurs.md | 2 +- cours/SIN/02-signaux.md | 117 +++++++++++++++++----------------- cours/SIN/matplotlibrc | 1 + matplotlibrc | 43 +++++++++++++ requirements.txt | 7 ++ 6 files changed, 115 insertions(+), 61 deletions(-) create mode 120000 cours/SIN/matplotlibrc create mode 100644 matplotlibrc create mode 100644 requirements.txt diff --git a/.forgejo/workflows/serve.yaml b/.forgejo/workflows/serve.yaml index 247f473..5c43a11 100644 --- a/.forgejo/workflows/serve.yaml +++ b/.forgejo/workflows/serve.yaml @@ -9,12 +9,12 @@ jobs: - name: Checkout repository uses: actions/checkout@v4 - name: Initialize virtual environment - run: /usr/bin/python -m venv .env + run: /usr/bin/python -m venv .venv - name: Install dependencies - run: ./.env/bin/pip install mystmd jupyter jupyterlab_myst ipykernel altair pandas + run: ./.venv/bin/pip install -r requirements.txt - name: Build static HTML run: | - . .env/bin/activate + . .venv/bin/activate myst build --execute --html - name: Copy files run: | diff --git a/cours/SIN/01-capteurs.md b/cours/SIN/01-capteurs.md index 0c3deb9..77bd675 100644 --- a/cours/SIN/01-capteurs.md +++ b/cours/SIN/01-capteurs.md @@ -60,7 +60,7 @@ Une thermistance (@thermistance) ou une jauge de déformation (@jauge) sont des capteurs analogiques. ::::{figure} -:label: analogique +:label: cap_analogique :::{figure} https://upload.wikimedia.org/wikipedia/commons/3/3b/NTC_bead.jpg :label: thermistance diff --git a/cours/SIN/02-signaux.md b/cours/SIN/02-signaux.md index 919c48e..039f085 100644 --- a/cours/SIN/02-signaux.md +++ b/cours/SIN/02-signaux.md @@ -32,32 +32,26 @@ et un niveau **bas** ("Low"). :label: logique ```{code-cell} python :tags: [remove-input] -import altair as alt +import matplotlib.pyplot as plt +from matplotlib import ticker import numpy as np -import pandas as pd rng = np.random.default_rng(25) n = 16 t = np.arange(n+1) -s = rng.choice([0, 1], n+1) -s[-1] = s[-2] -data = pd.DataFrame({ - "t": t, - "s": s, -}) -alt.Chart( - data -).mark_line( - interpolate="step-after", - strokeWidth=3, -).encode( - alt.X("t:Q").axis(title="Temps (s)").scale(domain=(0,n)), - alt.Y("s:Q", axis=alt.Axis(title="Signal logique", values=[0, 1], format=".0f")).scale(domain=(0,1)), -).properties( - width="container", - height=100, +s = rng.choice([0, 1], n) + +fig, ax = plt.subplots() +ax.stairs(s, t, lw=3) +ax.set( + xlim=(0, n), + ylim=(-.5, 1.5), + xlabel="Temps (s)", + ylabel="Signal logique", ) +ax.yaxis.set_major_locator(ticker.MultipleLocator(1)) +ax.xaxis.set_major_locator(ticker.MultipleLocator(1)) ``` Exemple de signal logique ```` @@ -77,35 +71,38 @@ Un exemple de signal analogique est donné en @analogique. :label: analogique ```{code-cell} python :tags: [remove-input] -import altair as alt +import matplotlib.pyplot as plt +from matplotlib import ticker import numpy as np -import pandas as pd +from scipy.interpolate import CubicSpline +from scipy.stats import qmc + rng = np.random.default_rng(25) n = 20 t_max = 16 -t = np.linspace(0, t_max, n) - +t_base = np.linspace(0, t_max, n) +lhs = (qmc.LatinHypercube(d=n-2, rng=rng).random(1)[0] - .5) * t_max/n +t = t_base + np.concatenate(([0], lhs, [0])) +t = t_base s = 5 * rng.random(n) s[-1] = s[-2] -data = pd.DataFrame({ - "t": t, - "s": s, -}) -alt.Chart( - data -).mark_line( - interpolate="basis", - strokeWidth=3, -).encode( - alt.X("t:Q").axis(title="Temps (s)").scale(domain=(0,t_max)), - alt.Y("s:Q", axis=alt.Axis(title="Signal analogique")).scale(domain=(0,5)), -).properties( - width="container", - height=200, + +t_interp = np.linspace(0, t_max, 1024) +s_interp = np.clip(CubicSpline(t, s)(t_interp), 0, 5) + +fig, ax = plt.subplots() +ax.plot(t_interp, s_interp, lw=3) +ax.set( + xlim=(0, t_max), + ylim=(-.5, 5.5), + xlabel="Temps (s)", + ylabel="Signal analogique", ) +ax.yaxis.set_major_locator(ticker.MultipleLocator(1)) +ax.xaxis.set_major_locator(ticker.MultipleLocator(1)) ``` Exemple de signal analogique ```` @@ -119,32 +116,38 @@ Un exemple de signal analogique est donné en @numerique. :label: numerique ```{code-cell} python :tags: [remove-input] -import altair as alt +import matplotlib.pyplot as plt +from matplotlib import ticker import numpy as np -import pandas as pd rng = np.random.default_rng(25) n = 16 t = np.arange(n+1) -s = rng.integers(0, 16, n+1) -s[-1] = s[-2] -data = pd.DataFrame({ - "t": t, - "s": s, -}) -alt.Chart( - data -).mark_line( - interpolate="step-after", - strokeWidth=3, -).encode( - alt.X("t:Q").axis(title="Temps (s)").scale(domain=(0,n)), - alt.Y("s:Q", axis=alt.Axis(title="Signal numérique", values=np.arange(0, 16))).scale(domain=(0,15)), -).properties( - width="container", - height=200, +s = rng.integers(0, 16, n) + +fig, ax = plt.subplots() +ax.stairs(s, t, lw=3) +ax.set( + xlim=(0, n), + ylim=(-.5, 16.5), + xlabel="Temps (s)", + ylabel="Signal numérique", ) +ax.yaxis.set_major_locator(ticker.MultipleLocator(1)) +ax.xaxis.set_major_locator(ticker.MultipleLocator(1)) +# alt.Chart( +# data +# ).mark_line( +# interpolate="step-after", +# strokeWidth=3, +# ).encode( +# alt.X("t:Q").axis(title="Temps (s)").scale(domain=(0,n)), +# alt.Y("s:Q", axis=alt.Axis(title="Signal numérique", values=np.arange(0, 16))).# scale(domain=(0,15)), +# ).properties( +# width="container", +# height=200, +# ) ``` Exemple de signal numérique ```` \ No newline at end of file diff --git a/cours/SIN/matplotlibrc b/cours/SIN/matplotlibrc new file mode 120000 index 0000000..b48e529 --- /dev/null +++ b/cours/SIN/matplotlibrc @@ -0,0 +1 @@ +../../matplotlibrc \ No newline at end of file diff --git a/matplotlibrc b/matplotlibrc new file mode 100644 index 0000000..6075cf1 --- /dev/null +++ b/matplotlibrc @@ -0,0 +1,43 @@ +lines.linewidth: 3 + +font.family: Fira Code + +image.cmap: inferno + +axes.linewidth: 1 +axes.grid: True +axes.grid.which: major +axes.titlelocation: right +axes.titleweight: 700 +axes.axisbelow: True + +axes.prop_cycle: cycler(color=["#4269d0","#efb118","#ff725c","#6cc5b0","#3ca951","#ff8ab7","#a463f2","#97bbf5","#9c6b4e","#9498a0"]) + +axes.formatter.use_locale: True + +grid.color: "#bebebe" +grid.linewidth: 1 +grid.alpha: 1 + +hatch.linewidth: 8 +hatch.color: "#00000013" + +boxplot.showmeans: true +boxplot.meanprops.markeredgecolor: "k" +boxplot.meanprops.marker: "+" +boxplot.flierprops.markerfacecolor: C0 +boxplot.medianprops.color: C0 + +figure.figsize: 8, 4.5 +figure.dpi: 96 +figure.constrained_layout.use: True + +xtick.direction: in +xtick.major.size: 4 +xtick.minor.size: 2 + +ytick.direction: in +ytick.major.size: 4 +ytick.minor.size: 2 + +savefig.format: pdf \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..0bbb937 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,7 @@ +mystmd +jupyter-server +ipykernel +matplotlib +numpy +pandas +scipy \ No newline at end of file From bc9d8904e2e505c4e63be5da5d78f0cbb01d2a26 Mon Sep 17 00:00:00 2001 From: "Edgar P. Burkhart" Date: Thu, 27 Feb 2025 18:33:19 +0100 Subject: [PATCH 11/19] Refactor signal visualizations to use Matplotlib, removing Altair dependencies and updating figure configurations for clarity --- cours/SIN/02-signaux.md | 17 +---- cours/SIN/03-can.md | 144 ++++++++++++++++++++-------------------- 2 files changed, 73 insertions(+), 88 deletions(-) diff --git a/cours/SIN/02-signaux.md b/cours/SIN/02-signaux.md index b9cbeb5..49288b0 100644 --- a/cours/SIN/02-signaux.md +++ b/cours/SIN/02-signaux.md @@ -43,7 +43,7 @@ t = np.arange(n+1) s = rng.choice([0, 1], n) fig, ax = plt.subplots() -ax.stairs(s, t, lw=3) +ax.stairs(s, t, lw=3, baseline=None) ax.set( xlim=(0, n), ylim=(-.5, 1.5), @@ -88,7 +88,6 @@ lhs = (qmc.LatinHypercube(d=n-2, rng=rng).random(1)[0] - .5) * t_max/n t = t_base + np.concatenate(([0], lhs, [0])) t = t_base s = 5 * rng.random(n) -s[-1] = s[-2] t_interp = np.linspace(0, t_max, 1024) s_interp = np.clip(CubicSpline(t, s)(t_interp), 0, 5) @@ -127,7 +126,7 @@ t = np.arange(n+1) s = rng.integers(0, 16, n) fig, ax = plt.subplots() -ax.stairs(s, t, lw=3) +ax.stairs(s, t, lw=3, baseline=None) ax.set( xlim=(0, n), ylim=(-.5, 16.5), @@ -136,18 +135,6 @@ ax.set( ) ax.yaxis.set_major_locator(ticker.MultipleLocator(1)) ax.xaxis.set_major_locator(ticker.MultipleLocator(1)) -# alt.Chart( -# data -# ).mark_line( -# interpolate="step-after", -# strokeWidth=3, -# ).encode( -# alt.X("t:Q").axis(title="Temps (s)").scale(domain=(0,n)), -# alt.Y("s:Q", axis=alt.Axis(title="Signal numérique", values=np.arange(0, 16))).# scale(domain=(0,15)), -# ).properties( -# width="container", -# height=200, -# ) ``` Exemple de signal numérique ```` \ No newline at end of file diff --git a/cours/SIN/03-can.md b/cours/SIN/03-can.md index 9b40196..ff412e3 100644 --- a/cours/SIN/03-can.md +++ b/cours/SIN/03-can.md @@ -37,69 +37,64 @@ La **caractéristique** du CAN est la courbe représentant la valeur numérique :label: fig:exemple-can ```{code-cell} python :tags: [remove-input] -import altair as alt +import matplotlib.pyplot as plt +from matplotlib import ticker import numpy as np -import pandas as pd -from scipy import interpolate +from scipy.interpolate import CubicSpline +from scipy.stats import qmc -rng = np.random.default_rng(25) +rng = np.random.default_rng(50) n = 20 -t_max = 16 +t_max = 8 +n_interp = t_max * 100 + 1 -T = np.linspace(0, t_max, 1601) -y = np.clip( - interpolate.BSpline(np.linspace(0, t_max, n), 5 * rng.random(n), 2)(T), - 0, - 5, +t_base = np.linspace(0, t_max, n) +lhs = (qmc.LatinHypercube(d=n-2, rng=rng).random(1)[0] - .5) * t_max/n +t = t_base + np.concatenate(([0], lhs, [0])) +t = t_base +s = 5 * rng.random(n) + +t_interp = np.linspace(0, t_max, n_interp) +s_interp = np.clip(CubicSpline(t, s)(t_interp), 0, 5) +s_n = np.full_like(t_interp[::50], np.nan) +s_n = np.floor(s_interp[::50] * 8 / 5) +s_n[s_n == 8] = 7 + +fig, ax = plt.subplots() +ax2 = ax.twinx() + +ax.plot(t_interp, s_interp, lw=3) +ax2.scatter(t_interp[::50], s_n, color="C1") + +ax.grid(False, axis="y") +ax.grid(True, axis="x", which="both") +ax2.grid(True) + +ax.set( + xlim=(0, t_max), + ylim=(-.5, 5.5), + xlabel="Temps (s)", ) -y_n = np.full([1601], np.nan) -y_n[::50] = np.floor(y[::50] * 8 / 5) -y_n[y_n == 8] = 7 - - -data = pd.DataFrame({ - "t": T, - "s": y, - "s_n": y_n, -}) - -base = alt.Chart( - data -).encode( - alt.X("t:Q").axis(title="Temps (s)").scale(domain=(0,t_max)), +ax.set_ylabel("Signal analogique (V)", color="C0") +ax2.set( + ylim=(-8/5*.5, 8/5*5.5), ) +ax2.set_ylabel("Signal numérique", color="C1") -ch = base.mark_line( - interpolate="basis", - strokeWidth=3, - color="#6666cc", -).encode( - alt.Y("s:Q", axis=alt.Axis(title="Signal analogique", titleColor="#6666cc")).scale(domain=(0,5)), -) +ax.yaxis.set_major_locator(ticker.MultipleLocator(1)) +ax.xaxis.set_major_locator(ticker.MultipleLocator(1)) +ax.xaxis.set_minor_locator(ticker.MultipleLocator(.5)) +ax2.set_yticks(np.arange(9), np.concatenate((np.arange(8), [""]))) -ch_n = base.mark_point( - filled=True, - color="#ff6600", -).encode( - alt.Y( - "s_n:Q", - axis=alt.Axis( - title="Signal numérisé", - titleColor="#ff6600", - values=np.arange(8), - ) - ).scale(domain=(0,8)), -) - -alt.layer(ch_n, ch).resolve_scale( - y="independent", -).properties( - width="container", - height=200, -) +arr = ax2.annotate("", xy=(0, 0), xytext=(0.5, 0), arrowprops=dict(arrowstyle="<->")) +ax2.annotate("$T_e$", (0.5, 1), xycoords=arr, ha="center", va="bottom") +arr2 = ax2.annotate("", xy=(0.5, 0), xytext=(0.5, 1), arrowprops=dict(arrowstyle="<->")) +ax2.annotate("$q$", (1, 0.5), xycoords=arr2, ha="left", va="center") +arr3 = ax2.annotate("", xy=(1, 0), xytext=(1, 8), arrowprops=dict(arrowstyle="<->")) +ax2.annotate("$V_{pe}$", (1, 0.5), xycoords=arr3, ha="left", va="center") ``` Signal analogique et signal numérisé. ```` @@ -108,34 +103,37 @@ Signal analogique et signal numérisé. :label: fig:carac-can ```{code-cell} python :tags: [remove-input] -import altair as alt +import matplotlib.pyplot as plt +from matplotlib import ticker import numpy as np -import pandas as pd -from scipy import interpolate N = 8 -s_n = np.arange(N+1) -s_n[-1] = s_n[-2] -data = pd.DataFrame({ - "s_n": s_n, - "s_a": np.linspace(0, 5, N+1), -}) +s_n = np.arange(N) +s_a = np.linspace(0, 5, N+1) -alt.Chart( - data -).mark_line( - interpolate="step-after", - strokeWidth=3, - color="#ff6600", -).encode( - alt.X("s_a:Q").axis(title="Signal Analogique").scale(domain=(0,5)), - alt.Y("s_n:Q", axis=alt.Axis(title="Signal numérique", values=np.arange(N))).scale(domain=(0,N)), -).properties( - width=200, - height=200, +fig, ax = plt.subplots() + +ax.stairs(s_n, s_a, color="C1", lw=3, baseline=None) + +ax.set( + xlim=(0, 5), + ylim=(-1, N), + yticks=s_n, + xlabel="Signal analogique (V)", + ylabel="Signal numérique", ) +ax.set_xticks(s_a, [f"{v:.3f}" for v in s_a], rotation=45, ha="right", rotation_mode="anchor") +ax.set_aspect(5/8, 'box') +arr4 = ax.annotate( + "", xy=(s_a[0], 0), xytext=(s_a[1], 0), arrowprops=dict(arrowstyle="<->") +) +ax.annotate("$q$", (0.5, 1), xycoords=arr4, ha="center", va="bottom") +arr5 = ax.annotate( + "", xy=(s_a[0], 1.5), xytext=(s_a[-1], 1.5), arrowprops=dict(arrowstyle="<->") +) +ax.annotate("$V_{pe}$", (0.5, 1), xycoords=arr5, ha="center", va="bottom") ``` Caractéristique du CAN. ```` \ No newline at end of file From f4cabbf11a4e6588f2de296422a82d3eded177a3 Mon Sep 17 00:00:00 2001 From: "Edgar P. Burkhart" Date: Thu, 27 Feb 2025 18:38:15 +0100 Subject: [PATCH 12/19] Update myst.yml to modify output settings for error handling and Matplotlib string removal --- myst.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/myst.yml b/myst.yml index dbca803..0a2d0db 100644 --- a/myst.yml +++ b/myst.yml @@ -19,6 +19,10 @@ project: exclude: README.md numbering: headings: true + settings: + output_stderr: remove-error + output_stdout: remove + output_matplotlib_strings: remove site: template: book-theme options: From 0240949bc6cf8467cc2ae8b5b31b85c7a05c99fa Mon Sep 17 00:00:00 2001 From: "Edgar P. Burkhart" Date: Fri, 28 Feb 2025 11:34:46 +0100 Subject: [PATCH 13/19] Update README.md to fix Forgejo Actions badge link --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index cda87c9..68aaebf 100644 --- a/README.md +++ b/README.md @@ -3,4 +3,4 @@ [![Made with MyST](https://img.shields.io/badge/made%20with-myst-orange)](https://myst.tools) -[![Forgejo Actions](https://img.shields.io/badge/serve.yaml-success-brightgreen)](https://git.edgarpierre.fr/edpibu/cours4.0/actions?workflow=serve.yaml) \ No newline at end of file +[![Forgejo Actions](https://git.edgarpierre.fr/edpibu/cours4.0/badges/workflows/serve.yaml/badge.svg)](https://git.edgarpierre.fr/edpibu/cours4.0/actions?workflow=serve.yaml) \ No newline at end of file From 4b03461d1f30f127a22cd1963e7f8c77560abc2b Mon Sep 17 00:00:00 2001 From: "Edgar P. Burkhart" Date: Fri, 28 Feb 2025 12:57:28 +0100 Subject: [PATCH 14/19] Add PDF export functionality and integrate courstex submodule --- .forgejo/workflows/serve.yaml | 4 ++++ .gitmodules | 3 +++ cours/SIN/01-capteurs.md | 3 +++ cours/SIN/02-signaux.md | 3 +++ cours/SIN/03-can.md | 3 +++ courstex | 1 + myst.yml | 4 +++- procédures/01-vr.md | 3 +++ procédures/02-laser.md | 3 +++ 9 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 .gitmodules create mode 160000 courstex diff --git a/.forgejo/workflows/serve.yaml b/.forgejo/workflows/serve.yaml index 5c43a11..d374f5b 100644 --- a/.forgejo/workflows/serve.yaml +++ b/.forgejo/workflows/serve.yaml @@ -12,6 +12,10 @@ jobs: run: /usr/bin/python -m venv .venv - name: Install dependencies run: ./.venv/bin/pip install -r requirements.txt + - name: Build PDF exports + run: | + . .venv/bin/activate + myst build --execute --pdf - name: Build static HTML run: | . .venv/bin/activate diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..95ac1a6 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "courstex"] + path = courstex + url = https://git.edgarpierre.fr/edpibu/courstex.git diff --git a/cours/SIN/01-capteurs.md b/cours/SIN/01-capteurs.md index fbffa9b..30ee8e0 100644 --- a/cours/SIN/01-capteurs.md +++ b/cours/SIN/01-capteurs.md @@ -1,6 +1,9 @@ --- title: Les capteurs subject: Cours +export: + - format: pdf + template: courstex --- # Définition diff --git a/cours/SIN/02-signaux.md b/cours/SIN/02-signaux.md index 49288b0..05095b8 100644 --- a/cours/SIN/02-signaux.md +++ b/cours/SIN/02-signaux.md @@ -1,6 +1,9 @@ --- title: Les signaux subject: Cours +export: + - format: pdf + template: courstex kernelspec: name: python3 display_name: Python 3 diff --git a/cours/SIN/03-can.md b/cours/SIN/03-can.md index ff412e3..e5226a2 100644 --- a/cours/SIN/03-can.md +++ b/cours/SIN/03-can.md @@ -1,6 +1,9 @@ --- title: Le CAN subject: Cours +export: + - format: pdf + template: courstex kernelspec: name: python3 display_name: Python 3 diff --git a/courstex b/courstex new file mode 160000 index 0000000..d040c12 --- /dev/null +++ b/courstex @@ -0,0 +1 @@ +Subproject commit d040c12b630182d5b127a9123a0cfa617d9a0016 diff --git a/myst.yml b/myst.yml index 0a2d0db..c1554bb 100644 --- a/myst.yml +++ b/myst.yml @@ -16,7 +16,9 @@ project: country: France url: https://lyceedupaysdesoule.fr license: CC-BY-NC-SA-4.0 - exclude: README.md + exclude: + - README.md + - courstex numbering: headings: true settings: diff --git a/procédures/01-vr.md b/procédures/01-vr.md index 1902ac3..9f135f3 100644 --- a/procédures/01-vr.md +++ b/procédures/01-vr.md @@ -6,6 +6,9 @@ abstract: | L'objectif de cette procédure est de visualiser un modèle 3D réalisé avec Solidworks en réalité augmentée avec l'application [Caddy](https://www.heycaddy.net/) sur Meta Quest 3. +export: + - format: pdf + template: courstex --- # Export au format IGES diff --git a/procédures/02-laser.md b/procédures/02-laser.md index 59a87c1..274acc5 100644 --- a/procédures/02-laser.md +++ b/procédures/02-laser.md @@ -5,6 +5,9 @@ subtitle: Découper ou graver une pièce abstract: | L'objectif de cette procédure est de découper et graver une pièce dans une plaque à l'aide de la découpe laser JAMP78 JA50. +export: + - format: pdf + template: courstex --- # Import dans RdCAM From df56660eb0858d4d5a8a792cbc08a968fb93a340 Mon Sep 17 00:00:00 2001 From: "Edgar P. Burkhart" Date: Fri, 28 Feb 2025 13:18:21 +0100 Subject: [PATCH 15/19] Refactor figures in documentation to use consistent syntax and improve layout; update myst.yml to remove obsolete output settings. --- cours/SIN/01-capteurs.md | 23 +++++++---------------- cours/SIN/03-can.md | 25 +++++++++++-------------- myst.yml | 4 ---- 3 files changed, 18 insertions(+), 34 deletions(-) diff --git a/cours/SIN/01-capteurs.md b/cours/SIN/01-capteurs.md index 30ee8e0..3e64d40 100644 --- a/cours/SIN/01-capteurs.md +++ b/cours/SIN/01-capteurs.md @@ -31,10 +31,9 @@ Ils génèrent donc un signal dit **binaire**. Un interrupteur (@inter) ou un détecteur de mouvement PIR (@pir) sont des capteurs tout ou rien. -::::{figure} -:label: fig:capteur-tor :::{figure} https://upload.wikimedia.org/wikipedia/commons/3/3a/Switches-electrical.agr.jpg :label: inter +:width: 50% Interrupteur[^inter]. @@ -44,6 +43,7 @@ Interrupteur[^inter]. :::{figure} https://upload.wikimedia.org/wikipedia/commons/2/2e/Motion_detector.jpg :label: pir +:width: 50% Détecteur de mouvement PIR[^pir]. @@ -51,9 +51,6 @@ Détecteur de mouvement PIR[^pir]. Public domain, via Wikimedia Commons. ::: -Exemples de capteurs tout ou rien -:::: - ## Les capteurs analogiques Le signal de sortie est en relation directe avec la grandeur d'entrée (généralement proportionnelle) @@ -62,10 +59,9 @@ c'est un signal dit **analogique**. Une thermistance (@thermistance) ou une jauge de déformation (@jauge) sont des capteurs analogiques. -::::{figure} -:label: fig:capteur-analogique :::{figure} https://upload.wikimedia.org/wikipedia/commons/3/3b/NTC_bead.jpg :label: thermistance +:width: 50% Thermistance : résistance variant selon la température[^thermistance]. @@ -76,6 +72,7 @@ via Wikimedia Commons. :::{figure} https://upload.wikimedia.org/wikipedia/commons/0/0a/Unmounted_strain_gauge.jpg :label: jauge +:width: 50% Jauge de déformation : résistance variant selon son élongation[^jauge]. @@ -83,17 +80,13 @@ Jauge de déformation : résistance variant selon son élongation[^jauge]. [CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0), via Wikimedia Commons. ::: -Exemples de capteurs analogiques. -:::: - ## Les capteurs numériques Un capteur numérique génère un signal de sortie ne pouvant prendre qu'un certain nombre de valeur distincte, c'est à dire un signal **numérique**. Une caméra (@camera) ou un codeur absolu (@codeur) sont des capteurs numériques. -::::{figure} -:label: fig:capteur-numerique :::{figure} https://upload.wikimedia.org/wikipedia/commons/0/02/S4000_Image_Sensor_%28Colorful%29.jpg :label: camera +:width: 50% Caméra : pour chaque pixel, le signal peut prendre une valeur entière allant de 0 à 255[^camera]. @@ -101,12 +94,10 @@ Caméra : pour chaque pixel, le signal peut prendre une valeur entière allant d ::: :::{figure} https://upload.wikimedia.org/wikipedia/commons/a/a8/Gray_code_rotary_encoder_13-track_opened.jpg :label: codeur +:width: 50% Codeur absolu : le signal prend une valeur entière différente selon l'angle du disque[^codeur]. [^codeur]: [Mike1024](https://commons.wikimedia.org/wiki/File:Gray_code_rotary_encoder_13-track_opened.jpg), Public domain, via Wikimedia Commons -::: - -Exemples de capteurs numériques -:::: \ No newline at end of file +::: \ No newline at end of file diff --git a/cours/SIN/03-can.md b/cours/SIN/03-can.md index e5226a2..0f13680 100644 --- a/cours/SIN/03-can.md +++ b/cours/SIN/03-can.md @@ -36,9 +36,9 @@ On donne en @fig:exemple-can l'exemple d'un CAN de tension de référence 5 V fo La **caractéristique** du CAN est la courbe représentant la valeur numérique en sortie en fonction de la valeur analogique en entrée (@fig:carac-can). -````{figure} +::::{figure} :label: fig:exemple-can -```{code-cell} python +:::{code-cell} python :tags: [remove-input] import matplotlib.pyplot as plt from matplotlib import ticker @@ -97,14 +97,14 @@ arr2 = ax2.annotate("", xy=(0.5, 0), xytext=(0.5, 1), arrowprops=dict(arrowstyle ax2.annotate("$q$", (1, 0.5), xycoords=arr2, ha="left", va="center") arr3 = ax2.annotate("", xy=(1, 0), xytext=(1, 8), arrowprops=dict(arrowstyle="<->")) -ax2.annotate("$V_{pe}$", (1, 0.5), xycoords=arr3, ha="left", va="center") -``` +ax2.annotate("$V_{pe}$", (1, 0.5), xycoords=arr3, ha="left", va="center"); +::: Signal analogique et signal numérisé. -```` +:::: -````{figure} +::::{figure} :label: fig:carac-can -```{code-cell} python +:::{code-cell} python :tags: [remove-input] import matplotlib.pyplot as plt from matplotlib import ticker @@ -119,15 +119,12 @@ fig, ax = plt.subplots() ax.stairs(s_n, s_a, color="C1", lw=3, baseline=None) ax.set( - xlim=(0, 5), - ylim=(-1, N), yticks=s_n, xlabel="Signal analogique (V)", ylabel="Signal numérique", ) ax.set_xticks(s_a, [f"{v:.3f}" for v in s_a], rotation=45, ha="right", rotation_mode="anchor") -ax.set_aspect(5/8, 'box') - +ax.set_aspect(5/8, "datalim") arr4 = ax.annotate( "", xy=(s_a[0], 0), xytext=(s_a[1], 0), arrowprops=dict(arrowstyle="<->") ) @@ -136,7 +133,7 @@ ax.annotate("$q$", (0.5, 1), xycoords=arr4, ha="center", va="bottom") arr5 = ax.annotate( "", xy=(s_a[0], 1.5), xytext=(s_a[-1], 1.5), arrowprops=dict(arrowstyle="<->") ) -ax.annotate("$V_{pe}$", (0.5, 1), xycoords=arr5, ha="center", va="bottom") -``` +ax.annotate("$V_{pe}$", (0.5, 1), xycoords=arr5, ha="center", va="bottom"); +::: Caractéristique du CAN. -```` \ No newline at end of file +:::: \ No newline at end of file diff --git a/myst.yml b/myst.yml index c1554bb..fb39f1d 100644 --- a/myst.yml +++ b/myst.yml @@ -21,10 +21,6 @@ project: - courstex numbering: headings: true - settings: - output_stderr: remove-error - output_stdout: remove - output_matplotlib_strings: remove site: template: book-theme options: From 976e5db7ed2e90ffbbd8917270e653de1e4c0b76 Mon Sep 17 00:00:00 2001 From: "Edgar P. Burkhart" Date: Fri, 28 Feb 2025 13:21:14 +0100 Subject: [PATCH 16/19] Enable submodule checkout in Forgejo workflow configuration --- .forgejo/workflows/serve.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.forgejo/workflows/serve.yaml b/.forgejo/workflows/serve.yaml index d374f5b..288d8c8 100644 --- a/.forgejo/workflows/serve.yaml +++ b/.forgejo/workflows/serve.yaml @@ -8,6 +8,8 @@ jobs: steps: - name: Checkout repository uses: actions/checkout@v4 + with: + submodules: "true" - name: Initialize virtual environment run: /usr/bin/python -m venv .venv - name: Install dependencies From 9e02248a5a4e0ae844a14873eb4d3ec70e1a0160 Mon Sep 17 00:00:00 2001 From: "Edgar P. Burkhart" Date: Fri, 28 Feb 2025 13:29:43 +0100 Subject: [PATCH 17/19] Add execution step to Forgejo workflow for MyST build --- .forgejo/workflows/serve.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.forgejo/workflows/serve.yaml b/.forgejo/workflows/serve.yaml index 288d8c8..0f39f6f 100644 --- a/.forgejo/workflows/serve.yaml +++ b/.forgejo/workflows/serve.yaml @@ -14,6 +14,10 @@ jobs: run: /usr/bin/python -m venv .venv - name: Install dependencies run: ./.venv/bin/pip install -r requirements.txt + - name: Execute code + run: | + . .venv/bin/activate + myst build --execute - name: Build PDF exports run: | . .venv/bin/activate From ce388b112663484d5a84678caed92d73935f01e2 Mon Sep 17 00:00:00 2001 From: "Edgar P. Burkhart" Date: Thu, 6 Mar 2025 09:45:18 +0100 Subject: [PATCH 18/19] Add course material on numeral systems with definitions and conversion methods --- cours/SIN/04-numeration.md | 111 +++++++++++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 cours/SIN/04-numeration.md diff --git a/cours/SIN/04-numeration.md b/cours/SIN/04-numeration.md new file mode 100644 index 0000000..45672de --- /dev/null +++ b/cours/SIN/04-numeration.md @@ -0,0 +1,111 @@ +--- +title: Systèmes de numération +subject: Cours +export: + - format: pdf + template: courstex +--- + +# Définition + +:::{prf:definition} Système de numération +:nonumber: true +Un système de numération est un ensemble de règles qui régissent une, voire plusieurs numérations données. De façon plus explicite, c'est un ensemble de règles d'utilisation des signes, des mots ou des gestes permettant d'écrire, d'énoncer ou de mimer les nombres. + +Source : Article _[Système de numération](https://fr.wikipedia.org/wiki/Syst%C3%A8me_de_num%C3%A9ration)_ de [Wikipédia en français](https://fr.wikipedia.org/) ([auteurs](https://fr.wikipedia.org/w/index.php?title=Syst%C3%A8me_de_num%C3%A9ration&action=history)) +::: + +# Systèmes de numération usuels + +## Le système décimal (base 10) + +Le système décimal est celui que l'on utilise au quotidien, qui utilise 10 symboles (0 à 9). La valeur des nombres s'obtient ainsi (@tab:num-10) : + +:::{math} +1789=1 \times 10^3 + 7 \times 10^2 + 8 \times 10^1 + 9 \times 10^0 +::: + +:::{csv-table} Système décimal +:label: tab:num-10 +10³,10²,10¹,10⁰ +1000, 100, 10, 1 +1,7,8,9 +::: + +## Le système binaire (base 2) + +Le système binaire est celui utilisé par systèmes électroniques. Il utilise 2 symboles (0 et 1). Chaque chiffre est appelé un bit. Un nombre à 8 bits est appelé octet (ou byte en anglais). La valeur des nombres s'obtient ainsi (@tab:num-2) : + +:::{math} +1011_2=1 \times 2^3 + 0 \times 2^2 + 1 \times 2^1 + 1 \times 2^0 +::: + +:::{csv-table} Système binaire +:label: tab:num-2 +2³,2²,2¹,2⁰ +8, 4, 2,1 +1,0,1,1 +::: + +### Conversion binaire vers décimal + +Pour convertir un nombre binaire en nombre décimal, utiliser la méthode ci-dessus : chaque bit, lui associer sa valeur, puis faire la somme des bits à 1. + +::::{hint} Exemple : Convertir $1101_2$ en décimal. + +- On associe à chaque bit sa valeur : +:::{math} +\begin{matrix} +2³ & 2² & 2¹ & 2⁰ \\ +1 & 1 & 0 & 1 +\end{matrix} +::: +- On additione la valeur des bits à 1 : +:::{math} +N = 8+4+1 = 13_{10} +::: +:::: + +### Conversion décimal vers binaire + +La méthode infaillible pour convertir un nombre décimal en nombre binaire est de poser la division par 2, puis réitérer avec le quotient obtenu jusqu'à obtenir 0, puis lire le reste des divisions en sens inverse. + +::::{hint} Exemple : Convertir $25_{10}$ en binaire. + +- On pose la division : + - $25\div 2=12\text{, reste }1$ + - $12\div 2=6\text{, reste }0$ + - $6\div 2=3\text{, reste }0$ + - $3\div 2=1\text{, reste }1$ + - $1\div 2=0\text{, reste }1$ +- On lit le reste des divisions dans l'ordre inverse : $25_{10}=11001_{2}$. +:::: + +## Le système hexadécimal (base 16) + +Le système hexadécimal est souvent utiliser pour retranscrire des nombres binaires car la conversion entre les deux systèmes est simple. Il utilise 16 symboles (0 à 9 puis A à F ; A=10, B=11, C=12, D=13, E=14 et F=15). La valeur des chiffres s'obtient ainsi (@tab:num-16) : + +:::{math} +6FD_{16}=6\times 16²+15\times 16¹+13\times 16⁰ +::: + +:::{csv-table} Système hexadécimal +:label: tab:num-16 +16²,16¹,16⁰ +256,16,1 +6,F,D +::: + +### Conversion entre binaire et hexadécimal + +Pour convertir un nombre binaire en hexadécimal, on peut regrouper les bits en paquets de 4, puis convertir chaque groupe de 4 bits en un chiffre hexadécimal. + +:::{hint} Exemple : Convertir $0110\,1111\,1101_2$ en hexadécimal. + +- On groupe en paquets de 4 bits : $0110_2$, $1111_2$, $1101_2$. +- On convertit chaque paquet en un chiffre hexadécimal : + - $0110_2=6_{10}=6_{16}$ + - $1111_2=15_{10}=F_{16}$ + - $1101_2=13_{10}=D_{16}$ +- On obtient donc : $0110\,1111\,1101_2=6FD_{16}$. +::: \ No newline at end of file From 7ea0ad923cc58616cfd9446e18ecd432c52298f6 Mon Sep 17 00:00:00 2001 From: "Edgar P. Burkhart" Date: Thu, 6 Mar 2025 10:16:45 +0100 Subject: [PATCH 19/19] Add course material on combinatorial logic with definitions, truth tables, and logical functions --- cours/SIN/05-logique.md | 70 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 cours/SIN/05-logique.md diff --git a/cours/SIN/05-logique.md b/cours/SIN/05-logique.md new file mode 100644 index 0000000..163eb65 --- /dev/null +++ b/cours/SIN/05-logique.md @@ -0,0 +1,70 @@ +--- +title: Logique combinatoire +subject: Cours +export: + - format: pdf + template: courstex +kernelspec: + name: python3 + display_name: Python 3 +--- + +# Vocabulaire +:::{prf:definition} Variable logique +:nonumber: true +Une **variable logique** est une variable qui ne peut prendre que deux valeurs, dites **états logiques** : 0 et 1. +::: + +:::{prf:definition} Table de vérité +:nonumber: true +Une **table de vérité** permet de renseigner les états logiques des sorties du système en fonction de ses entrées (exemple : @tab:verite). +::: + +:::{csv-table} Table de vérité +:label: tab:verite +:header-rows: 1 +a,b,S +0,0,1 +0,1,0 +1,0,0 +1,1,1 +::: + +:::{prf:definition} Chronogramme +:nonumber: true +Un **chronogramme** permet de représenter l'évolution des états logiques d'un système en fonction du temps (exemple : @fig:chronogramme). +::: + +::::{figure} +:label: fig:chronogramme +:::{code-cell} python +:tag: [remove-input] +import matplotlib.pyplot as plt +import numpy as np + +rng = np.random.default_rng(25) + +fig, [ax_a, ax_b, ax] = plt.subplots(3, figsize=(10, 4), sharex=True, sharey=True) +ax.set(xlim=(0, 16), xticks=np.arange(0, 16), ylim=(-0.5, 1.5), yticks=(0, 1)) +ax.set(xlabel="Temps (s)", ylabel="Signal logique") + +a = rng.integers(2, size=16) +b = rng.integers(2, size=16) +S = np.equal(a, b) + +ax_a.stairs(a, lw=3, baseline=None) +ax_a.set_ylabel("a") + +ax_b.stairs(b, lw=3, baseline=None) +ax_b.set_ylabel("b") + +ax.stairs(S, lw=3, baseline=None) +ax.set_ylabel("S"); +::: + +Chronogramme +:::: + +# Fonctions logiques +Une fonction logique donne un résultat en fonction des valeurs d'entrée. +Les fonctions logiques usuelles sont ET ($a\cdot{}b$), OU ($a+b$), NON ($\bar a$) et OU exclusif (XOR, $a\oplus{}b$). Les symboles et tables de vérité sont donnés sur la [page Wikipédia des fonctions logiques](https://fr.wikipedia.org/wiki/Fonction_logique#Repr%C3%A9sentation_graphique). \ No newline at end of file