Commit 0cc890e0 authored by Pierre MARQUE's avatar Pierre MARQUE

Initial commit

parents
Pipeline #1027 failed with stages
File added
from math import*
import scipy as scipy
from scipy import optimize
import random as rd
import matplotlib.pyplot as plt
c=1500
A=1000
w=10
lambda_=(2*pi*c)/w
thetaMax=pi/2
t0,tf=0,0.01
lois=[[0,1514],[348,1520],[1000,1490],[7000,1550]] #liste de [profondeur,c]
#sol plat pour formationDesVoies(3.7,5.7,thetaMax,N=50,n=31,d=20,f=1000)
L=[[5.494000000000499, -0.7696902001294993], [5.495000000000499, -0.7382742735936013], [5.1990000000004, -0.7068583470577033], [5.1990000000004, -0.6754424205218054], [4.953000000000318, -0.6440264939859074], [4.845000000000282, -0.6126105674500094], [4.845000000000282, -0.5811946409141114], [4.746000000000249, -0.5497787143782135], [4.573000000000191, -0.5183627878423155], [4.574000000000192, -0.48694686130641757], [4.499000000000167, -0.45553093477051965], [4.082000000000027, -0.4241150082346217], [4.052000000000017, -0.3926990816987238], [4.056000000000019, -0.3612831551628259], [4.066000000000022, -0.32986722862692797], [4.069000000000023, -0.29845130209103005], [4.045000000000015, -0.2670353755551321], [4.053000000000018, -0.2356194490192342], [4.055000000000018, -0.20420352248333629], [4.037000000000012, -0.17278759594743837], [4.040000000000013, -0.14137166941154045], [4.027000000000009, -0.10995574287564251], [4.009000000000003, -0.07853981633974458], [4.010000000000003, -0.047123889803846644], [4.009000000000003, -0.01570796326794871], [4.009000000000003, 0.015707963267949224], [4.010000000000003, 0.04712388980384716], [4.009000000000003, 0.07853981633974509], [4.027000000000009, 0.10995574287564303], [4.040000000000013, 0.14137166941154095], [4.037000000000012, 0.17278759594743887], [4.055000000000018, 0.20420352248333679], [4.053000000000018, 0.2356194490192347], [4.045000000000015, 0.2670353755551326], [4.069000000000023, 0.29845130209103055], [4.066000000000022, 0.32986722862692847], [4.056000000000019, 0.3612831551628264], [4.052000000000017, 0.3926990816987243], [4.082000000000027, 0.4241150082346222], [4.499000000000167, 0.45553093477052015], [4.574000000000192, 0.48694686130641807], [4.573000000000191, 0.518362787842316], [4.746000000000249, 0.549778714378214], [4.845000000000282, 0.581194640914112], [4.845000000000282, 0.61261056745001], [4.953000000000318, 0.6440264939859079], [5.1990000000004, 0.6754424205218059], [5.1990000000004, 0.7068583470577039], [5.3400000000004475, 0.7382742735936019], [5.494000000000499, 0.7696902001294998]]
erreur=[-40.960590066511486, 48.204650180872704, -34.987038633850716, 43.09326581421692, -29.371414884888964, -27.048464306647475, 37.114999372129205, 34.9726650185512, -20.81106335548793, 31.75799401939048, 30.169547510370194, -209.7388685805654, -192.33010069818693, -154.37925821552972, -114.91269825538484, -83.15866708917929, -73.77393175364386, -44.238534471149705, -21.938627196541347, -17.335237734874227, -0.2283171188205415, 2.01057571351339, -2.518806797915204, 4.161298948127751, 6.379064714235028, 6.379064714235028, 4.161298948127751, -2.518806797915204, 2.01057571351339, -0.2283171188205415, -17.33523773487468, -21.938627196541347, -44.238534471149705, -73.77393175364432, -83.15866708917974, -114.9126982553853, -154.37925821553063, -192.33010069818738, -209.73886858056585, 30.169547510369284, 31.75799401938957, -20.81106335548884, 34.97266501855029, 37.114999372128295, -27.048464306648384, -29.371414884890328, 43.093265814215556, -34.98703863385208, -37.77746461042125, -40.960590066513305]
#sol plat pour formationDesVoies(3.7,5.7,thetaMax,N=100,n=31,d=20,f=1000)
L_2=[[5.495000000000466, -0.7775441817634738], [5.497000000000467, -0.7618362184955249], [5.495000000000466, -0.7461282552275759], [5.495000000000466, -0.7304202919596269], [5.200000000000368, -0.7147123286916779], [5.198000000000367, -0.6990043654237289], [5.197000000000367, -0.6832964021557799], [5.200000000000368, -0.6675884388878309], [4.953000000000285, -0.6518804756198819], [4.954000000000286, -0.636172512351933], [4.953000000000285, -0.620464549083984], [4.844000000000249, -0.604756585816035], [4.843000000000249, -0.589048622548086], [4.747000000000217, -0.573340659280137], [4.745000000000216, -0.557632696012188], [4.655000000000186, -0.541924732744239], [4.656000000000186, -0.52621676947629], [4.574000000000159, -0.510508806208341], [4.5730000000001585, -0.49480084294039206], [4.0729999999999915, -0.4790928796724431], [4.499000000000134, -0.4633849164044941], [4.42900000000011, -0.4476769531365451], [4.430000000000111, -0.4319689898685961], [4.080999999999994, -0.4162610266006471], [4.0819999999999945, -0.40055306333269813], [4.0819999999999945, -0.38484510006474915], [4.058999999999987, -0.36913713679680016], [4.056999999999986, -0.35342917352885117], [4.058999999999987, -0.3377212102609022], [4.065999999999989, -0.3220132469929532], [4.065999999999989, -0.3063052837250042], [4.06799999999999, -0.2905973204570552], [4.0459999999999825, -0.27488935718910623], [4.047999999999983, -0.25918139392115724], [4.047999999999983, -0.24347343065320828], [4.0519999999999845, -0.22776546738525932], [4.049999999999984, -0.21205750411731036], [4.034999999999979, -0.1963495408493614], [4.0369999999999795, -0.18064157758141244], [4.03899999999998, -0.16493361431346348], [4.0369999999999795, -0.14922565104551452], [4.0249999999999755, -0.13351768777756556], [4.026999999999976, -0.1178097245096166], [4.026999999999976, -0.10210176124166764], [4.00899999999997, -0.08639379797371868], [4.0099999999999705, -0.07068583470576972], [4.010999999999971, -0.054977871437820756], [4.010999999999971, -0.03926990816987179], [4.00899999999997, -0.023561944901922822], [4.0099999999999705, -0.007853981633973856], [4.0099999999999705, 0.007853981633975111], [4.00899999999997, 0.02356194490192408], [4.010999999999971, 0.039269908169873045], [4.010999999999971, 0.05497787143782201], [4.0099999999999705, 0.07068583470577097], [4.00899999999997, 0.08639379797371993], [4.026999999999976, 0.10210176124166889], [4.026999999999976, 0.11780972450961785], [4.0249999999999755, 0.1335176877775668], [4.0369999999999795, 0.14922565104551577], [4.03899999999998, 0.16493361431346473], [4.0369999999999795, 0.1806415775814137], [4.034999999999979, 0.19634954084936265], [4.049999999999984, 0.2120575041173116], [4.0519999999999845, 0.22776546738526057], [4.047999999999983, 0.24347343065320953], [4.047999999999983, 0.2591813939211585], [4.0459999999999825, 0.2748893571891075], [4.06799999999999, 0.2905973204570565], [4.065999999999989, 0.3063052837250055], [4.065999999999989, 0.32201324699295447], [4.058999999999987, 0.33772121026090346], [4.056999999999986, 0.35342917352885245], [4.058999999999987, 0.36913713679680143], [4.0819999999999945, 0.3848451000647504], [4.0819999999999945, 0.4005530633326994], [4.080999999999994, 0.4162610266006484], [4.430000000000111, 0.4319689898685974], [4.42900000000011, 0.4476769531365464], [4.499000000000134, 0.46338491640449536], [4.0729999999999915, 0.47909287967244435], [4.5730000000001585, 0.49480084294039334], [4.574000000000159, 0.5105088062083423], [4.656000000000186, 0.5262167694762913], [4.655000000000186, 0.5419247327442402], [4.745000000000216, 0.5576326960121892], [4.747000000000217, 0.5733406592801382], [4.843000000000249, 0.5890486225480872], [4.844000000000249, 0.6047565858160362], [4.953000000000285, 0.6204645490839852], [4.954000000000286, 0.6361725123519342], [4.953000000000285, 0.6518804756198832], [5.200000000000368, 0.6675884388878321], [5.197000000000367, 0.6832964021557811], [5.198000000000367, 0.6990043654237301], [5.200000000000368, 0.7147123286916791], [5.339000000000414, 0.7304202919596281], [5.341000000000415, 0.7461282552275771], [5.497000000000467, 0.7618362184955261], [5.495000000000466, 0.7775441817634751]]
erreur2=[-63.038503879247855, -16.90269285056729, 26.326642012076263, 69.89463072848366, -54.400932087575256, -15.76369219698472, 22.688532949790897, 62.7360304351223, -46.980463253576545, -11.342327153828592, 22.351987783223194, -11.346998030061968, 20.10549928607543, -9.05692473115505, 19.63572756556414, -8.98496226227553, 19.579334296502566, -6.902447736665181, 18.397097314114944, -289.17377259565956, 18.417250973546743, -5.591464732322493, 17.305695033908705, -200.6161356463972, -180.83156254825144, -162.42853244777325, -160.8136537966443, -145.31831262187052, -127.71309465718059, -107.24370648953072, -92.4415015132131, -76.91958374047135, -79.42958498141934, -65.40209027668107, -53.54234654951688, -39.48707699863917, -30.540189039460074, -31.898545179739358, -21.515643698057374, -11.859172698115799, -5.898903426341349, -8.117637638981705, -0.6849928819010529, 4.520966155836959, -4.464045479870947, -0.010339778089928586, 3.704827405558717, 5.930748271133325, 5.91541705795089, 7.407241616682768, 7.407241616682768, 5.91541705795089, 5.93074827113287, 3.704827405558717, -0.010339778089928586, -4.464045479870947, 4.520966155836504, -0.6849928819019624, -8.117637638981705, -5.898903426341803, -11.859172698115799, -21.515643698058284, -31.898545179739813, -30.54018903946053, -39.48707699863962, -53.54234654951779, -65.40209027668197, -79.42958498142025, -76.91958374047226, -92.441501513214, -107.24370648953209, -127.71309465718195, -145.31831262187188, -160.81365379664567, -162.42853244777461, -180.8315625482528, -200.61613564639856, 17.305695033906886, -5.591464732324312, 18.41725097354447, -289.1737725956614, 18.39709731411267, -6.902447736667, 19.579334296500747, -8.98496226227735, 19.635727565561865, -9.056924731157778, 20.105499286073155, -11.346998030064697, 22.351987783220466, -11.34232715383132, -46.98046325357927, 62.736030435119574, 22.688532949787714, -15.76369219698745, -54.40093208757844, -17.257973892769314, -58.48760782777708, -16.902692850570475, -63.03850387925104]
def formationDesVoies(a,b,thetaMax,N=100,n=31,d=20,f=100):#-->renvoie des doublets (faisceau,temps)
#N nombre de voies souhaitées
#n : nombre de transducteurs
#d : distance entre les transducteurs
#theta en rad
#f: fréquence d'échantillonage
eps=1/f
pasAngle=thetaMax/N
decalage=pasAngle/2
angleVoie=-thetaMax/2+decalage
z,x=0,0
tempsDétecté=0
Temps=[]
for k in range(N):
#v=0
#for i in range(n):
# if v<ondeRéflechie(reflecteurs,x+((N-1)/2+i)*d,z,t+i*d*sin(angleVoie)):
# v=ondeRéflechie(reflecteurs,x+((N-1)/2+i)*d,z,t+i*d*sin(angleVoie))
#def s(t):return sum(ondeRéflechie2(pasAngle,angleVoie,reflecteurs,x-((n-1)/2-i)*d,z,t+((n-1)/2-i)*d*sin(angleVoie)/c)for i in range(n))
def s(t):return sum(ondeRéflechie(reflecteurs,x-((n-1)/2-i)*d,z,t+((n-1)/2-i)*d*sin(angleVoie)/c)for i in range(n))
tempsDétecté=rechercheMax2(s,eps,a,b)
if tempsDétecté==None:
return None
Temps.append([tempsDétecté,angleVoie])
print(k,angleVoie,tempsDétecté)
angleVoie+=pasAngle
return Temps
def bathymétrie(Temps):
N=len(Temps)
Sx,Sz=[],[]
for k in range(N):
profondeur=Temps[k][0]*c/2*cos(Temps[k][1])
longueur=profondeur*tan(Temps[k][1])
Sx.append(longueur)
Sz.append(profondeur)
plt.plot(Sx,Sz);plt.show()
return Sz
def bathymétrieCorrigé(L):
N=len(L)
Sx,Sz=[],[]
for k in range(N):
profondeur=L[k][0]*c/2*cos(L[k][1])-erreur2[k]
longueur=profondeur*tan(L[k][1])
Sx.append(longueur)
Sz.append(profondeur)
plt.plot(Sx,Sz);plt.show()
def erreurs(Sz):
L2=[]
N=len(Sz)
c=0
for k in range(N):
c=Sz[k]-3000
L2.append(c)
return L2
def corrige(Sz,L2):
N=len(Sz)
#def dectectionAmplitude(theta,hydrophones,thetaMax,N,n,d,Dtemps,a):
#amplitudeMax=0
#instantAmplitudeMax=0
#for j in range(floor(((n//2*d*sin(thetaMax)/c)+1)*(a/Dtemps)),floor((1-(n//2*d*sin(thetaMax)/c))*(a/Dtemps))): #on parcourt le temps
# if Amax>sum(hydrophones[i][j+(n//2-j)*d*sin(theta)/c] for j in range(n)): #on somme les valeurs de tous les transducteeurs
# amplitudeMax=sum(hydrophones[i][j+(n//2-j)*d*sin(theta)/c] for j in range(n))#sélection de l'instant d'amplitude max
#instantAmplitudeMax=j*Dtemps/a
#retards.append([k,instantAmplitudeMax])
#def interferometrie(theta,hydrophones,thetaMax,N,n,d,Dtemps,a):
# antenne1,antenne2=hydrophones[n//2+1:],hydrophones[:n//2+1]
def ping(w,t,t0,tf):
if t0<=t<=tf:
return 1
else :
return 0
def amplitude(A,r):
return A
def générerPlancher(profondeur=3000,alpha=pi/2,l=10):
L=0 #longueur du plancher
x0=-1-tan(alpha/2)*profondeur #position de départ du plancher
z=profondeur #variable pour contrôler la profondeur
Lz,Lx=[z],[x0]
while L<-x0+tan(alpha/2)*z:
beta=pi*rd.gauss(0,0.3)
L+=l#*cos(beta)
#z-=l*sin(beta)
Lz.append(z)
Lx.append(x0+L)
plt.plot(Lx,Lz);plt.show()
return Lx,Lz
def valeursAngulaires(Lx,Lz):#renvoie les valeurs angulaires des "sommets" du plancher
valeursAngulaires=[]
l=len(Lx)
for k in range(l):
valeursAngulaires.append(atan2(Lx[k],Lz[k]))#k pour conserver le rang du "sommet"
return valeursAngulaires
def rechercheMax(s,eps,a=t0,b=tf):
max_=0
while a<b:
if s(a)!=0:
return a
a+=eps
def rechercheMax2(s,eps,a=t0,b=tf):
max_=0
v=0
while a<b:
if s(a)>max_:
max_=s(a)
v=a
a+=eps
return v
def reflecteurs(Lx,Lz,R=1000,alpha=pi/2): #R la résolution voulue #renvoie les coordonnées des "réflecteurs"
angleSommets=valeursAngulaires(Lx,Lz)
anglesClassés=sorted(angleSommets,key=lambda angle: angleSommets[0])
pas=alpha/R
angle=-alpha/2
l=len(Lx)-1#nombre d'arrêtes du plancher
reflecteurs=[]
reflecteurs1,reflecteurs2=[],[]
for k in range(R):#on place chacun des réflecteurs
angle+=pas #angle du réflecteur
arretes=[]
arrete=0
for i in range(l):#on extrait les arrê tes de plancher qui croisées par le faisceau
if (angleSommets[i]-angle)*(angleSommets[i+1]-angle)<0: #= si croisés par le faisceau
arretes.append([i,sqrt(Lx[i]**2+Lz[i]**2)+sqrt(Lx[i+1]**2+Lz[i+1]**2)])#arrête comprise entre les sommets i et i+1 et sa "distance"
if len(arretes)>1: #si plus d'une arrête croise un rayon
arretesClassees=[]
arretesClassees=sorted(arretes,key=lambda distance: distance[1])
arrete=arretesClassees[0][0] #on récupère le rang de l'arrête la plus petite
else:
arrete=arretes[0][0]
points=[Lx[arrete],Lz[arrete],Lx[arrete+1],Lz[arrete+1]]
a,b=coefFonctionAffine(points)[0],coefFonctionAffine(points)[1]
def f(x):return a*x+b-(cos(angle)/sin(angle))*x
t=dichotomie(Lx[0],Lx[-1],f,0.0001)
coordonnees=[t,a*t+b]
reflecteurs1.append(coordonnees[0])
reflecteurs2.append(coordonnees[1])
reflecteurs.append(coordonnees)
plt.plot(reflecteurs1,reflecteurs2);plt.show()
return reflecteurs
def ondeSonar(x,z,t,A,w):
r=sqrt(x**2+z**2) #distance radiale au sonar
angle=atan2(x,z)
j=1
ti=t
ti-=r/c
return amplitude(A,r)*ping(w,ti,t0,tf)
def ondeSonar2(x,z,t,A,w): #donne la forme de l'onde émise par le sonar
r=sqrt(x**2+z**2) #distance radiale au sonar
angle=atan2(x,z)
j=1
ti=t
while z> lois[j][0]:
ti-=retard(angle,lois[j-1][0]/cos(angle),lois[j][0]/cos(angle),coefFonctionAffine(loisDeVitesse[j-1])[0],coefFonctionAffine(loisDeVitesse[j-1])[1])
j=j+1
ti-=retard(angle,lois[j-1][0]/cos(angle),r,coefFonctionAffine(loisDeVitesse[j-1])[0],coefFonctionAffine(loisDeVitesse[j-1])[1])
return amplitude(A,r)*ping(w,ti,t0,tf)
def ondeReflecteur(coordonnees,t,x,z):
xr,zr=coordonnees[0],coordonnees[1]
r=sqrt(xr**2+zr**2)
r+=sqrt((xr-x)**2+(zr-z)**2)
ti=t
ti-=r/c
return amplitude(A,r)*ping(w,ti,t0,tf)
def ondeReflecteur2(coordonnees,t,x,z):#onde générée par le réflecteur de "coordonnées"
xr,zr=coordonnees[0],coordonnees[1]
rr=sqrt(xr**2+zr**2)
d=sqrt((xr-x)**2+(zr-z)**2)
angle=atan(abs(x-xr)/abs(z-zr))
#ondeSol=pas*ondeSonar(xr,zr,t,A,w)#valeur de l'onde réfléchie par 1 réflecteur au niveau du sol
#calcul du temps de "retour"
ti=t
j=len(lois)-1;print(j)
while lois[j][0]>zr:
j=j-1
#ti-=(abs(zr-loi[j][0])/cos(angle))/((loisDeVitesse[j][0]*z+loisDeVitesse[j][1]+lois[j][1])/2) #sol au palier le plus proche
ti-=(abs(zr-loi[j][0])/cos(angle))/c
#ti-=retard(angle, ,,coefFonctionAffine(loisDeVitesse[j])[0],coefFonctionAffine(loisDeVitesse[j])[1])
while lois[j][0]<z:
j-=1
#ti-=retard(angle,cos(angle)*(loi[j-1][0]),cos(angle)*(loi[j][0]),coefFonctionAffine(loisDeVitesse[j-1])[0],coefFonctionAffine(loisDeVitesse[j-1])[1])
ti-=(loi[j+1][0]-loi[j][0])/cos(angle)/c
#ti-=((loi[j+1][0]-loi[j][0])/cos(angle))/((lois[j+1][1]+lois[j][1])/2)
#ti-=(abs(z-loi[j-1][0])/cos(angle))/((loisDeVitesse[j][0]*z+loisDeVitesse[j][1]+lois[j-1][1])/2)
ti-=(abs(z-loi[j-1][0])/cos(angle))/c
#ti-=retard(angle,r1,r2,a,b)
return pas*ondeSonar(xr,zr,ti,A,w)
def ondeRéflechie(reflecteurs,x,z,ta): #coordonnées des réflecteurs
R=len(reflecteurs)
s=0
for k in range(R):
s+=ondeReflecteur(reflecteurs[k],ta,x,z)
return s
def ondeRéflechie2(pas,angle,reflecteurs,x,z,ta): #coordonnées des réflecteurs
R=len(reflecteurs)
s=0
for k in range(R):
if abs(atan2(reflecteurs[k][0],reflecteurs[k][1])-angle)<pas:
s+=ondeReflecteur(reflecteurs[k],ta,x,z)
return s
def visualiserOndeSonar(x,z,durée=10,ti=43,dt=0.0001):
iterations=floor(tf-ti)
t=ti
Lx,Lz=[],[]
while t<ti+durée:
Lx.append(t),Lz.append(ondeSonar(x,z,t,A,w))
t+=dt
plt.plot(Lx,Lz);plt.show()
def visualiserOndeRéflechie(reflecteurs,x,z,tf,t,dt=0.00001):
ti=t
Lx,Lz=[],[]
while ti<tf:
Lx.append(ti),Lz.append(ondeRéflechie(reflecteurs,x,z,ti))
ti+=dt
plt.plot(Lx,Lz);plt.show()
def loisDeVitesse(lois):#liste %2 elts :[profondeur, vitesse]#renvoie les coeff a et b des lois affines de vitesse
#transformer lois en liste de segments
L=[]
n=len(lois)-1
for k in range(n):
L.append([lois[k][0],lois[k][1],lois[k+1][0],lois[k+1][1]])
return L
def coefFonctionAffine(L): #renvoie les coefficients a et b tels que y=ax+b
iterations=len(L)//2-1
coeff=[]
for k in range(iterations):
a=(L[k+1]-L[k+3])/(L[k+0]-L[k+2])
b=L[k+1]-a*L[k+0]
coeff.append(a);coeff.append(b)
return coeff
loisDeVitesse=loisDeVitesse(lois)
def retard(angle,r1,r2,a,b):
def g(x):return 1/(a*x*cos(angle)+b)
return sc.integrate.quad(g,min(r1,r2),max(r1,r2))[0]
def echantillonnageSignal(f,s,t):
L=[]
#Lx,Ly=[],[]
dt=1/f
durée=0
while durée<t:
L.append(s(durée))
durée+=dt
#Lx.append(durée);Ly.append(s(durée))
#plt.plot(Lx,Ly);plt.show()
return L
#def temps(a,b,x):
#f=lambda u:a*u+b
#return f(x)
def dichotomie(a,b,f,eps):
while abs(b-a)>eps:
m=(b+a)/2
if f(m)*f(b)>0:
b=m
else :
a=m
return m
def dichotomie2(x1,x2,a,b,c,eps):
while abs(x1-x2)>eps:
m=(x1+x2)/2
if (a*m+b-c*m)*(a*x2+b-(c)*x2)>0:
x2=m
else :
x1=m
return m
def g(x):return cos(10*x)
Lx,Lz=générerPlancher(profondeur=3000,alpha=pi/2,l=20)
reflecteurs=reflecteurs(Lx,Lz,R=50,alpha=pi/2)
#Temps=formationDesVoies(4,6,thetaMax,N=50,n=31,d=20,f=1000)
from math import*
import random as rd
import matplotlib.pyplot as plt
Lois=[] #list de [profondeur,c]
c=340#m/s
def formationDesVoies(hydrophones,thetaMax,N,n,d,Dtemps):#-->renvoie des doublets (faisceau,temps)
#hydrophones : tableau des valeurs transducteurs enfonction du temps
#N nombre de voies souhaitées
#n : nombre de transducteurs
#d : distance entre les transducteurs
#theta en degrés
retards=[]
a=len(hydrophones[0])
for k in range(N): #on parcourt les N faisceaux
theta=-thetaMax+k*(thetaMax/2)
if abs(theta)<30: #Détection par amplitude (Instant d'Amplitude Maximale)
dectectionAmplitude(theta,d,hydrophones,thetaMax,theta,a,Dtemps)
#else :
#interferometrie(theta,hydrophones,thetaMax,N,n,d,Dtemps,a)
def dectectionAmplitude(theta,hydrophones,thetaMax,N,n,d,Dtemps,a):
amplitudeMax=0
instantAmplitudeMax=0
for j in range(floor(((n//2*d*sin(thetaMax)/c)+1)*(a/Dtemps)),floor((1-(n//2*d*sin(thetaMax)/c))*(a/Dtemps))): #on parcourt le temps
if Amax>sum(hydrophones[i][j+(n//2-j)*d*sin(theta)/c] for j in range(n)): #on somme les valeurs de tous les transducteeurs
amplitudeMax=sum(hydrophones[i][j+(n//2-j)*d*sin(theta)/c] for j in range(n))#sélection de l'instant d'amplitude max
instantAmplitudeMax=j*Dtemps/a
retards.append([k,instantAmplitudeMax])
#def interferometrie(theta,hydrophones,thetaMax,N,n,d,Dtemps,a):
# antenne1,antenne2=hydrophones[n//2+1:],hydrophones[:n//2+1]
def ping(w,t,t0,tf):
if t0<=t<=tf:
return cos(w*t)
else :
return 0
def amplitude(A,r):
return A/(pi*r)
def générerPlancher(profondeur=3000,alpha=pi/4,l=20):
Lz,Lx=[],[]
L=0 #longueur du plancher
x0=-1-tan(alpha/2)*profondeur #position de départ du plancher
z=profondeur #variable pour contrôler la profondeur
while L<-x0+tan(alpha/2)*z:
beta=pi*rd.gauss(0,0.2)
L+=l*cos(beta)
z+=l*sin(beta)
Lz.append(z)
Lx.append(x0+L)
plt.plot(Lx,Lz);plt.show()
#return Lx,Ly
def valeursAngulaires(Lx,Lz):#renvoie les valeurs angulaires des "sommets" du plancher
valeursAngulaires=[]
l=len(Lx)
for k in range(l):
valeursAngulaires.append(atan2(Lx,L,y))#k pour conserver le rang du "sommet"
return valeursAngulaires
def reflecteurs(Lx,Lz,R,alpha): #R la résolution voulue #renvoie les coordonnées des "réflecteurs"
#renvoie les coordonnées des réflecteurs
angleSommets=valeursAngulaires(Lx,Lz)
anglesClassés=sorted(angleSommets,key=lambda angle: angle[0])
pas=alpha/(R-1)
l=len(Lx)-1
reflecteurs=[]
for k in range(R):#on place chacun des réflecteurs
angle=k*pas #angle du réflecteur
arretes=[]
arrete=0
for i in range(l):#on extrait les arrêtes de plancher qui croisées par le faisceau
if (angleSommets[i]-angle)*(angleSommets[i+1]-angle)<0:
arretes.append([i,sqrt(Lx[i]**2+Lz[i]**2)+sqrt(Lx[i+1]**2+Lz[i+1]**2)])#arrête comprise entre les sommets i et i+1 et sa "distance"
if len(arretes)>1:
arretesClassees=[]
arretesClassees=sorted(arretes,key=lambda distance: distance[1])
arrete=arretesClassees[0][0]
else:
arrete=arretes[0]
points=[Lx[arrete],Lz[arrete],Lx[arrete+1],Lz[arrete+1]]
a,b=coefFonctionAffine(points)[0],coefFonctionAffine(points)[1]
def f(x):return a*x+b-(sin(angle)/cos(angle))*x
t=dichotomie(0,point[1],f,1E-5)
coordonnees=[t,f(t)]
reflecteurs.append(coordonnees)
def ondeSonar(x,z,t,A,w,lois): #donne la forme de l'onde émise par le sonar
r=sqrt(x**2+z**2)
j=0
while z> lois[j][3]:
def ondeReflecteur(xr,zr,t,pas):
rr=sqrt(xr**2+zr**2)
d=sqrt(xr**2+zr**2)-sqrt(x**2+z**2)
ampReflecteur=amplitude(A,rr+d)
ampReflecteur=pas*ampReflecteur
ti=t
while zr>lois[2*j]:
if j==0:
ti-=quad(temps(loisDeVitesse[0],loisDeVitesse[1]),0,lois[0])
else :
ti-=quad(temps(loisDeVitesse[2*j],loisDeVitesse[2*j+1]),lois[2*(j-1)],lois[2*j])
j+=1
ti-=quad(temps(loisDeVitesse[2*j],loisDeVitesse[2*j+1]),lois[2*(j-1)],zr)
return ampReflecteur*ping(w,ti,t0,tf)
def ondeRéflechie(coordonnees,x,z,t): #coordonnées du réflecteur
j=len(lois)//2
while z<lois[2*j]:
j=j-1
def loisDeVitesse(lois):#liste %2 elts :[profondeur, vitesse]
#renvoie les coeff a et b des lois affines de vitesse
loisDeVitesse=coefFonctionAffine(lois)
return loisDeVitesse
def coefFonctionAffine(L): #renvoie les coefficients a et b tels que y=ax+b
iterations=len(L)//2-1
coeff=[]
for k in range(iterations):
a=(L[k+1]-L[k+3])/(L[k+0]-L[k+2])
b=L[1]-a*L[0]
coeff.append(a);coeff.append(b)
return coeff
def temps(a,b,x):
f=lambda u:a*u+b
return f(x)
def dichotomie(a,b,f,eps):
while abs(b-a)>eps:
m=(b+a)/2
if f(m)*f(b)>0:
b=m
else :
a=m
return m
File added
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment