Use python to plot function

This commit is contained in:
flyingscorpio@arch-desktop 2021-11-27 21:06:43 +01:00
parent 6da1eccab2
commit 3621541ded
2 changed files with 163 additions and 2 deletions

View file

@ -0,0 +1,16 @@
#!/usr/bin/env python3
import math
output = []
for x in range(-70, 71):
f = x/10
T = 2
if f == 0:
sinc = 1
else:
sinc = ((math.sin(math.pi * f * T)) / (math.pi * f * T)) ** 2
s = (T**2) * (sinc**2)
output.append(str((f, s)))
print(" --\n".join(output))

View file

@ -167,9 +167,154 @@ Théorie du signal --- TD1
\begin{center}
\begin{tikzpicture}
%TODO plot this
\draw[help lines, dashed] (-7,-2) grid (7,2);
\draw[help lines, dashed] (-7,-1) grid (7,5);
\draw[-latex] (-7,0) -- (7,0) node[below]{$f$};
\draw[-latex] (0,-2) -- (0,2) node[left]{$S_x(f)$};
\draw[-latex] (0,-1) -- (0,5) node[left]{$S_x(f)$};
% T = 3
\draw[very thick, teal, smooth]
plot[domain=-7:7]
(-7.0, 9.236424985855951e-66) --
(-6.9, 1.351508856906833e-07) --
(-6.8, 9.82042242286396e-07) --
(-6.7, 1.0419973375281967e-06) --
(-6.6, 1.6145054556795375e-07) --
(-6.5, 2.1247489470901966e-65) --
(-6.4, 1.825977253441778e-07) --
(-6.3, 1.3329185814786595e-06) --
(-6.2, 1.4210163081164671e-06) --
(-6.1, 2.2125643933133683e-07) --
(-6.0, 9.236424985855951e-66) --
(-5.9, 2.5281754659351027e-07) --
(-5.8, 1.8554696109297905e-06) --
(-5.7, 1.9891447935831516e-06) --
(-5.6, 3.1150365806319875e-07) --
(-5.5, 1.6166354311481645e-63) --
(-5.4, 3.602800545131002e-07) --
(-5.3, 2.661107026328134e-06) --
(-5.2, 2.8717884569168376e-06) --
(-5.1, 4.528293363652966e-07) --
(-5.0, 9.236424985855958e-66) --
(-4.9, 5.31411488307728e-07) --
(-4.8, 3.95549527961044e-06) --
(-4.7, 4.303030142791807e-06) --
(-4.6, 6.842013588090742e-07) --
(-4.5, 9.236424985855951e-66) --
(-4.4, 8.173433869377619e-07) --
(-4.3, 6.141748066122749e-06) --
(-4.2, 6.747900318735658e-06) --
(-4.1, 1.0841261802423652e-06) --
(-4.0, 9.236424985855951e-66) --
(-3.9, 1.3242099017039712e-06) --
(-3.8, 1.0070045517514694e-05) --
(-3.7, 1.1203634282331384e-05) --
(-3.6, 1.8239177759725472e-06) --
(-3.5, 9.236424985855951e-66) --
(-3.4, 2.2924485153493843e-06) --
(-3.3, 1.7705576029270517e-05) --
(-3.2, 2.0024694853027794e-05) --
(-3.1, 3.3171757645011927e-06) --
(-3.0, 9.236424985855951e-66) --
(-2.9, 4.331349886689919e-06) --
(-2.8, 3.4161245363599325e-05) --
(-2.7, 3.951033968062021e-05) --
(-2.6, 6.70381262737629e-06) --
(-2.5, 9.236424985855958e-66) --
(-2.4, 9.233583740861088e-06) --
(-2.3, 7.503337405958586e-05) --
(-2.2, 8.963447864818203e-05) --
(-2.1, 1.5752086215146527e-05) --
(-2.0, 9.236424985855951e-66) --
(-1.9, 2.3507197452505176e-05) --
(-1.8, 0.0002000210946331401) --
(-1.7, 0.00025140281402531684) --
(-1.6, 4.6745017688109035e-05) --
(-1.5, 9.236424985855951e-66) --
(-1.4, 7.974493646417963e-05) --
(-1.3, 0.0007351778449707119) --
(-1.2, 0.0010126067915802706) --
(-1.1, 0.00020923990705607045) --
(-1.0, 9.236424985855951e-66) --
(-0.9, 0.0004669229506489748) --
(-0.8, 0.005126321882375121) --
(-0.7, 0.00874527881308142) --
(-0.6, 0.002363797437660431) --
(-0.5, 9.236424985855951e-66) --
(-0.4, 0.011966724528155946) --
(-0.3, 0.2592273386445493) --
(-0.2, 1.312338401888031) --
(-0.1, 3.06348147920792) --
(0.0, 4) --
(0.1, 3.06348147920792) --
(0.2, 1.312338401888031) --
(0.3, 0.2592273386445493) --
(0.4, 0.011966724528155946) --
(0.5, 9.236424985855951e-66) --
(0.6, 0.002363797437660431) --
(0.7, 0.00874527881308142) --
(0.8, 0.005126321882375121) --
(0.9, 0.0004669229506489748) --
(1.0, 9.236424985855951e-66) --
(1.1, 0.00020923990705607045) --
(1.2, 0.0010126067915802706) --
(1.3, 0.0007351778449707119) --
(1.4, 7.974493646417963e-05) --
(1.5, 9.236424985855951e-66) --
(1.6, 4.6745017688109035e-05) --
(1.7, 0.00025140281402531684) --
(1.8, 0.0002000210946331401) --
(1.9, 2.3507197452505176e-05) --
(2.0, 9.236424985855951e-66) --
(2.1, 1.5752086215146527e-05) --
(2.2, 8.963447864818203e-05) --
(2.3, 7.503337405958586e-05) --
(2.4, 9.233583740861088e-06) --
(2.5, 9.236424985855958e-66) --
(2.6, 6.70381262737629e-06) --
(2.7, 3.951033968062021e-05) --
(2.8, 3.4161245363599325e-05) --
(2.9, 4.331349886689919e-06) --
(3.0, 9.236424985855951e-66) --
(3.1, 3.3171757645011927e-06) --
(3.2, 2.0024694853027794e-05) --
(3.3, 1.7705576029270517e-05) --
(3.4, 2.2924485153493843e-06) --
(3.5, 9.236424985855951e-66) --
(3.6, 1.8239177759725472e-06) --
(3.7, 1.1203634282331384e-05) --
(3.8, 1.0070045517514694e-05) --
(3.9, 1.3242099017039712e-06) --
(4.0, 9.236424985855951e-66) --
(4.1, 1.0841261802423652e-06) --
(4.2, 6.747900318735658e-06) --
(4.3, 6.141748066122749e-06) --
(4.4, 8.173433869377619e-07) --
(4.5, 9.236424985855951e-66) --
(4.6, 6.842013588090742e-07) --
(4.7, 4.303030142791807e-06) --
(4.8, 3.95549527961044e-06) --
(4.9, 5.31411488307728e-07) --
(5.0, 9.236424985855958e-66) --
(5.1, 4.528293363652966e-07) --
(5.2, 2.8717884569168376e-06) --
(5.3, 2.661107026328134e-06) --
(5.4, 3.602800545131002e-07) --
(5.5, 1.6166354311481645e-63) --
(5.6, 3.1150365806319875e-07) --
(5.7, 1.9891447935831516e-06) --
(5.8, 1.8554696109297905e-06) --
(5.9, 2.5281754659351027e-07) --
(6.0, 9.236424985855951e-66) --
(6.1, 2.2125643933133683e-07) --
(6.2, 1.4210163081164671e-06) --
(6.3, 1.3329185814786595e-06) --
(6.4, 1.825977253441778e-07) --
(6.5, 2.1247489470901966e-65) --
(6.6, 1.6145054556795375e-07) --
(6.7, 1.0419973375281967e-06) --
(6.8, 9.82042242286396e-07) --
(6.9, 1.351508856906833e-07) --
(7.0, 9.236424985855951e-66)
;
\end{tikzpicture}
\end{center}