Commit 2ab0d55d authored by MEULE Samuel's avatar MEULE Samuel
Browse files

Ajout des notebooks TD2 à TD8 + ajout des fichiers

# Historique
* [X] Ajout de requirements.txt pour gestion des dépendances
* [X] Ajout du fichier .py et du notebook jupyter .ipynb pour TD1
* [X] Création d'un git pour Stat
parent b7fd7f88
This diff is collapsed.
Ajout de requirement.txt pour gestion des dépendances
Ajout des notebooks TD2 à TD8 + ajout des fichiers
# Historique
* [X] Ajout de requirements.txt pour gestion des dépendances
* [X] Ajout du fichier .py et du notebook jupyter .ipynb pour TD1
* [X] Création d'un git pour Stat
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#!/usr/bin/python\n",
"# coding: utf-8\n",
"\n",
"#################################################\" \n",
"## MODULES #####\"\n",
"#################################################\"\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"#################################################\"\n",
"\n",
"# Parameters\n",
"\n",
"N = 500 # Number of sampling\n",
"Tmax = 2.0 # Max time\n",
"Te = Tmax/N # Delta time between each measurements\n",
"f1=1 # Acquisition frequency\n",
"t = np.arange(0, Tmax, Te) # Time vector\n",
"\n",
"# Functions\n",
"u1=0.5*1.0*np.cos(2*np.pi*f1*t)\n",
"u2=0.3*np.cos(2*2*np.pi*f1*t-np.pi/3)\n",
"u=u1+u2\n",
"\n",
"# fft analysis\n",
"Puu=np.abs(np.fft.fft(u,N)/N)**2 # Density spectrum\n",
"freqs=np.linspace(0,1/Te,len(Puu)) # frequencies\n",
"\n",
"# Figure\n",
"fig1=plt.figure(figsize=(10,5))\n",
"plt.plot(freqs,Puu, 'ko-', label='u')\n",
"plt.axis([0,11,0,0.1])\n",
"plt.xlabel(\"Frequency (Hz)\")\n",
"plt.ylabel(\"Power spectrum\")\n",
"plt.grid()\n",
"plt.show()\n",
"\n",
"# Save the figure\n",
"fig1.savefig('Figure_TD2',dpi=200)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
%% Cell type:code id: tags:
``` python
#!/usr/bin/python
# coding: utf-8
#################################################"
## MODULES #####"
#################################################"
import matplotlib.pyplot as plt
import numpy as np
#################################################"
# Parameters
N = 500 # Number of sampling
Tmax = 2.0 # Max time
Te = Tmax/N # Delta time between each measurements
f1=1 # Acquisition frequency
t = np.arange(0, Tmax, Te) # Time vector
# Functions
u1=0.5*1.0*np.cos(2*np.pi*f1*t)
u2=0.3*np.cos(2*2*np.pi*f1*t-np.pi/3)
u=u1+u2
# fft analysis
Puu=np.abs(np.fft.fft(u,N)/N)**2 # Density spectrum
freqs=np.linspace(0,1/Te,len(Puu)) # frequencies
# Figure
fig1=plt.figure(figsize=(10,5))
plt.plot(freqs,Puu, 'ko-', label='u')
plt.axis([0,11,0,0.1])
plt.xlabel("Frequency (Hz)")
plt.ylabel("Power spectrum")
plt.grid()
plt.show()
# Save the figure
fig1.savefig('Figure_TD2',dpi=200)
```
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#!/usr/bin/python\n",
"# coding: utf-8\n",
"\n",
"#################################################\" \n",
"## MODULES #####\"\n",
"#################################################\"\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"#################################################\"\n",
"\n",
"# Parameters\n",
"N = 500 # Number of sampling\n",
"Tmax = 2.0 # Max time\n",
"Te = Tmax/N # Delta time between each measurements\n",
"f1=1 # Acquisition frequency\n",
"t = np.arange(0, Tmax, Te) # Time vector\n",
"\n",
"\n",
"# Functions\n",
"u1=2*1.0*np.cos(2*np.pi*f1*t)\n",
"u2=2*np.cos(2*2*np.pi*f1*t-np.pi/3)\n",
"u=u1+u2\n",
"\n",
"# Analyse statistique\n",
"nbrv=(np.diff(np.sign(u)) < 0).sum()# Nbr d'oscillations\n",
"hist, bin_edges = np.histogram(u, bins=20) #Fonction de repartition des hauteurs de vagues. \n",
"X = np.sort(u)\n",
"F = np.array(range(N))*100/float(N)\n",
"H13=np.mean(X[np.where(F>66)]) # Calcul de la moyenne du tiers superieur des oscillations\n",
"fu=np.where((np.diff(np.sign(u)) < 0))\n",
"Tm=np.mean(np.diff(fu))*Te # Calcul de la periode moyenne\n",
"\n",
"\n",
"# Figure\n",
"fig1=plt.figure(figsize=(10,5))\n",
"plt.bar(bin_edges[:-1], hist, width=bin_edges[1]-bin_edges[0], color='red', alpha=0.5, label='Histogramm')\n",
"plt.plot(X, F, label=u'cumulative frequency')\n",
"plt.xlabel(\"oscillation amplitude\")\n",
"plt.ylabel(u\"Probability\")\n",
"titre='Amplitude histogram: H1/3=' + str(np.around(H13,2))+'; Tm='+str(np.around(Tm,2))\n",
"plt.title(titre)\n",
"plt.legend()\n",
"plt.grid()\n",
"plt.ylim(0,100)\n",
"plt.show()\n",
"\n",
"# Save the figure\n",
"fig1.savefig('Figure_TD3',dpi=200)\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
%% Cell type:code id: tags:
``` python
#!/usr/bin/python
# coding: utf-8
#################################################"
## MODULES #####"
#################################################"
import matplotlib.pyplot as plt
import numpy as np
#################################################"
# Parameters
N = 500 # Number of sampling
Tmax = 2.0 # Max time
Te = Tmax/N # Delta time between each measurements
f1=1 # Acquisition frequency
t = np.arange(0, Tmax, Te) # Time vector
# Functions
u1=2*1.0*np.cos(2*np.pi*f1*t)
u2=2*np.cos(2*2*np.pi*f1*t-np.pi/3)
u=u1+u2
# Analyse statistique
nbrv=(np.diff(np.sign(u)) < 0).sum()# Nbr d'oscillations
hist, bin_edges = np.histogram(u, bins=20) #Fonction de repartition des hauteurs de vagues.
X = np.sort(u)
F = np.array(range(N))*100/float(N)
H13=np.mean(X[np.where(F>66)]) # Calcul de la moyenne du tiers superieur des oscillations
fu=np.where((np.diff(np.sign(u)) < 0))
Tm=np.mean(np.diff(fu))*Te # Calcul de la periode moyenne
# Figure
fig1=plt.figure(figsize=(10,5))
plt.bar(bin_edges[:-1], hist, width=bin_edges[1]-bin_edges[0], color='red', alpha=0.5, label='Histogramm')
plt.plot(X, F, label=u'cumulative frequency')
plt.xlabel("oscillation amplitude")
plt.ylabel(u"Probability")
titre='Amplitude histogram: H1/3=' + str(np.around(H13,2))+'; Tm='+str(np.around(Tm,2))
plt.title(titre)
plt.legend()
plt.grid()
plt.ylim(0,100)
plt.show()
# Save the figure
fig1.savefig('Figure_TD3',dpi=200)
```
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#!/usr/bin/python\n",
"# coding: utf-8\n",
"\n",
"#################################################\" \n",
"## MODULES #####\"\n",
"#################################################\"\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"#################################################\"\n",
"\n",
"# Parameters\n",
"N = 1000 # Number of sampling\n",
"Tmax = 4.0 # Max time\n",
"Te = Tmax/N # Delta time between each measurements\n",
"f1=1 # Acquisition frequency (Hz)\n",
"t = np.arange(0, Tmax, Te) # Time vector\n",
"\n",
"\n",
"\n",
"# Functions\n",
"u1=0.5*np.cos(1*2*np.pi*f1*t)\n",
"u2=0.3*np.cos(2*2*np.pi*f1*t-np.pi/3)\n",
"u=u1+u2\n",
"\n",
"# fft analysis\n",
"y=np.fft.rfft(u,N)/N # Fast Fourier Transform\n",
"a0=2*y[0].real # Fourier coeff a0\n",
"a=2*y.real # Fourier coeff a\n",
"b=-2*y.imag # Fourier coeff b\n",
"\n",
"# Rebuilding the harmonics\n",
"n=1 # Number of harmonics\n",
"m=int(Tmax)*f1*n\n",
"v1=a[m]*np.cos(2*np.pi*f1*t)+b[m]*np.sin(2*np.pi*f1*t)\n",
"#\n",
"n=2 # Number of harmonics\n",
"m=int(Tmax)*f1*n\n",
"v2=a[m]*np.cos(n*2*np.pi*f1*t)+b[m]*np.sin(n*2*np.pi*f1*t)\n",
"#\n",
"v=a0+v1+v2\n",
"\n",
"# Figure\n",
"fig1=plt.figure(figsize=(10,5))\n",
"#plt.hold(True)\n",
"plt.plot(t,u, 'r--', label='u')\n",
"plt.plot(t,u1, 'y--', label='u1')\n",
"plt.plot(t,u2, 'g--', label='u2')\n",
"plt.plot(t,v, 'ro', label='v')\n",
"plt.plot(t,v1, 'yo', label='v1')\n",
"plt.plot(t,v2, 'go', label='v2')\n",
"plt.legend()\n",
"plt.xlabel(\"t\")\n",
"plt.ylabel(\"f(t)\")\n",
"#plt.axis([0,2,-2,2])\n",
"plt.grid()\n",
"plt.show()\n",
"\n",
"# Save the figure\n",
"fig1.savefig('Figure_TD3',dpi=200)\n",
"\n",
"\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
%% Cell type:code id: tags:
``` python
#!/usr/bin/python
# coding: utf-8
#################################################"
## MODULES #####"
#################################################"
import matplotlib.pyplot as plt
import numpy as np
#################################################"
# Parameters
N = 1000 # Number of sampling
Tmax = 4.0 # Max time
Te = Tmax/N # Delta time between each measurements
f1=1 # Acquisition frequency (Hz)
t = np.arange(0, Tmax, Te) # Time vector
# Functions
u1=0.5*np.cos(1*2*np.pi*f1*t)
u2=0.3*np.cos(2*2*np.pi*f1*t-np.pi/3)
u=u1+u2
# fft analysis
y=np.fft.rfft(u,N)/N # Fast Fourier Transform
a0=2*y[0].real # Fourier coeff a0
a=2*y.real # Fourier coeff a
b=-2*y.imag # Fourier coeff b
# Rebuilding the harmonics
n=1 # Number of harmonics
m=int(Tmax)*f1*n
v1=a[m]*np.cos(2*np.pi*f1*t)+b[m]*np.sin(2*np.pi*f1*t)
#
n=2 # Number of harmonics
m=int(Tmax)*f1*n
v2=a[m]*np.cos(n*2*np.pi*f1*t)+b[m]*np.sin(n*2*np.pi*f1*t)
#
v=a0+v1+v2
# Figure
fig1=plt.figure(figsize=(10,5))
#plt.hold(True)
plt.plot(t,u, 'r--', label='u')
plt.plot(t,u1, 'y--', label='u1')
plt.plot(t,u2, 'g--', label='u2')
plt.plot(t,v, 'ro', label='v')
plt.plot(t,v1, 'yo', label='v1')
plt.plot(t,v2, 'go', label='v2')
plt.legend()
plt.xlabel("t")
plt.ylabel("f(t)")
#plt.axis([0,2,-2,2])
plt.grid()
plt.show()
# Save the figure
fig1.savefig('Figure_TD3',dpi=200)
```
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#!/usr/bin/python\n",
"# coding: utf-8\n",
"\n",
"#################################################\" \n",
"## MODULES #####\"\n",
"#################################################\"\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"#################################################\"\n",
"\n",
"\n",
"# Parameters\n",
"\n",
"N = 1000 # Number of sampling\n",
"Tmax = 4.0 # Max time\n",
"Te = Tmax/N # Delta time between each measurements\n",
"f1=1 # Acquisition frequency (Hz)\n",
"t = np.arange(0, Tmax, Te) # Time vector\n",
"n=4 # Number of harmonics\n",
"\n",
"# Functions\n",
"\n",
"u1=0.5*np.cos(1*2*np.pi*f1*t)\n",
"u2=0.3*np.cos(2*2*np.pi*f1*t-np.pi/3)\n",
"u3=0.5*np.cos(3*2*np.pi*f1*t+np.pi/3)\n",
"u4=0.1*np.cos(4*2*np.pi*f1*t)\n",
"u=u1+u2+u3+u4\n",
"\n",
"# fft analysis\n",
"y=np.fft.fft(u) #Fast Fourier Transform\n",
"\n",
"# order of the filtering\n",
"m=int(Tmax)*f1*n+1\n",
"\n",
"y[m:-m]=0\n",
"# Reverse fft and normalize\n",
"Y=np.fft.ifft(y)\n",
"Y=Y.real\n",
"\n",
"# Figure\n",
"fig1=plt.figure(figsize=(10,5))\n",
"plt.plot(t, Y, 'k.', label='filtered dataset')\n",
"plt.plot(t,u, 'r--', label=\"Original dataset\")\n",
"plt.legend()\n",
"plt.xlabel(\"t\")\n",
"plt.ylabel(\"u\")\n",
"plt.show()\n",
"\n",
"# Save the figure\n",
"fig1.savefig('Figure_TD5',dpi=200)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
%% Cell type:code id: tags:
``` python
#!/usr/bin/python
# coding: utf-8
#################################################"
## MODULES #####"
#################################################"
import matplotlib.pyplot as plt
import numpy as np
#################################################"
# Parameters
N = 1000 # Number of sampling
Tmax = 4.0 # Max time
Te = Tmax/N # Delta time between each measurements
f1=1 # Acquisition frequency (Hz)
t = np.arange(0, Tmax, Te) # Time vector
n=4 # Number of harmonics
# Functions
u1=0.5*np.cos(1*2*np.pi*f1*t)
u2=0.3*np.cos(2*2*np.pi*f1*t-np.pi/3)
u3=0.5*np.cos(3*2*np.pi*f1*t+np.pi/3)
u4=0.1*np.cos(4*2*np.pi*f1*t)
u=u1+u2+u3+u4
# fft analysis
y=np.fft.fft(u) #Fast Fourier Transform
# order of the filtering
m=int(Tmax)*f1*n+1
y[m:-m]=0
# Reverse fft and normalize
Y=np.fft.ifft(y)
Y=Y.real
# Figure
fig1=plt.figure(figsize=(10,5))
plt.plot(t, Y, 'k.', label='filtered dataset')
plt.plot(t,u, 'r--', label="Original dataset")
plt.legend()
plt.xlabel("t")
plt.ylabel("u")
plt.show()
# Save the figure
fig1.savefig('Figure_TD5',dpi=200)
```
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#!/usr/bin/python\n",
"# coding: utf-8\n",
"\n",
"#################################################\" \n",
"## MODULES #####\"\n",
"#################################################\"\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"#################################################\"\n",
"n=1 # Number of harmonics\n",
"\n",
"# Read ascii file\n",
"\n",
"filename='fichier2.txt'\n",
"with open(filename, 'r') as f:\n",
" lines=f.readlines()\n",
"t=[]\n",
"u=[]\n",
"for l in lines:\n",
" value=l.strip().split(\"\\t\")\n",
" t.append(float(value[0])) # Read the first column: time t\n",
" u.append(float(value[1])) # Read the second column: function u \n",
"\n",
"t=np.array(t)\n",
"u=np.array(u)\n",
"# Parameters\n",
"f1=1\n",
"N=len(t)\n",
"Tmax=np.round(max(t))\n",
"\n",
"# fft analysis\n",
"y=np.fft.fft(u) #Fast Fourier Transform\n",
"\n",
"# order of the filtering\n",
"m=int(Tmax)*f1*n+1\n",
"y[m:-m]=0\n",
"# Reverse fft and normalize\n",
"Y=np.fft.ifft(y)\n",
"Y=Y.real\n",
"# Figure\n",
"fig1=plt.figure(figsize=(10,5))\n",
"plt.plot(t,u, 'r--', label=\"Original dataset\")\n",
"plt.plot(t, Y, 'k.', label='filtered dataset')\n",
"plt.legend()\n",
"plt.grid()\n",
"plt.show()\n",
"# Save the figure\n",
"fig1.savefig('Figure_TD6',dpi=200)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
%% Cell type:code id: tags:
``` python
#!/usr/bin/python
# coding: utf-8
#################################################"
## MODULES #####"
#################################################"
import matplotlib.pyplot as plt
import numpy as np
#################################################"
n=1 # Number of harmonics
# Read ascii file