nove meritve z 31 polinomom

master
lso hp 8540w 2022-07-09 18:53:14 +02:00
parent ff5589b70a
commit a3512523cd
29 changed files with 74174 additions and 0 deletions

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,82 @@
#!/usr/bin/python3
print('*** Preprost zvočni spektralni analizator - S53MV 28.09.2020 ***')
print('*** popravek odziva za EliteBook 8540w - Andrej 11.2.2012 ***')
print('*** meritev faznega suma (interpolacija in povprecenje v frekvenci-sai) - Andrej 15.2.2012 ***')
fs=192000 #Frekvenca vzročenja zvočnega signala (max 192000Hz)
pts=2048 #Število točk spektra 0...fs/2 (potenca 2 za učinkovit FFT)
avg=128 #Število povprečenj spektra
import sounddevice as sd #Poiskati na spletu in naložiti s pip3!
import numpy as np #Uporaba učinkovitih funkcij numpy
import matplotlib.pyplot as plt #Risanje rezultata z matplotlib
import matplotlib.animation as animation
sd.default.device = 0
fskala=np.linspace(0,fs/2,2*pts+1)[:-1] #Izračunaj frekvenčno skalo [Hz]
### podatki za kalibracijo sistema
dSB = -67.5+11.7 #dB
L = 1256 #metrov
tau = L*1.4676/3e8
### popravek odziva
odziv = np.loadtxt("5mhz-polinom-2048tock.csv", delimiter=',')
a = odziv[:,1]
popravek = np.max(a[4:-1])-a[4:-1]
def spekter(fs,pts,avg,fskala): #Zajem signala z zvočno kartico in povprečenje spektra [dB]
s=sd.rec(pts*(1+avg),samplerate=fs,channels=1) #Vzorčenje ADC zvočne kartice, 2D polje!
sd.wait() #Počakaj do konca vzorčenja
nz=1.e-12 #Dodatek za neničelni argument logaritma
s2=np.square(s) #Izpis jakosti/max [dB]
print('Jakost:',"%.1f"%(10*np.log10(nz+np.mean(s2))),'dB Vrh:',"%.1f"%(10*np.log10(nz+np.amax(s2))),'dB',end=' ')
o=1+np.cos(np.linspace(-np.pi,np.pi,2*pts)) #Okno dvignjeni kosinus
k=0
s2=np.zeros(2*pts)
while k<pts*avg: #Seštevanje moči FFT
s2=s2+np.square(np.abs(np.fft.rfft(o*s.reshape(-1)[k:k+2*pts],n=4*pts)[:-1]))
k+=pts
s=10*np.log10(nz+0.5*s2/pts/pts/avg) #Povprečje [dB]
print(' Max:',"%.1f"%(np.amax(s[4:-1])),'dB @',"%.1f"%(fskala[np.argmax(s[4:-1])]),'Hz')
return s[4:-1]+popravek
### izris z animacijo
f=fskala[4:-1]
rbw = np.diff(f)[0]
print(rbw)
initsum = spekter(fs,pts,avg,fskala)
fig,ax = plt.subplots()
raw,pn, = ax.plot(f,initsum,f,initsum)
ax.set_xlim(100, 100000)
ax.set_ylim(-130,-30)
ax.set_ylabel("Fazni šum [dBc/Hz]")
ax.set_xlabel("Frekvenčni odmik [Hz]")
plt.yticks(np.arange(-130,-29,10))
plt.xscale('log')
ax.grid(True)
def meritev(nic):
s = spekter(fs,pts,avg,fskala)
Pcal = np.amax(s)
K = Pcal - 3 - dSB
fsum = s - K - 3 - 6 - 20*np.log10(np.sin(f*np.pi*tau)) -10*np.log10(rbw)
raw.set_data(f,s)
pn.set_data(f,fsum)
ax.figure.canvas.draw()
return raw,pn
ani = animation.FuncAnimation(fig,meritev,interval=50)
plt.show()
#shrani csv file
s = spekter(fs,pts,avg,fskala)
Pcal = np.amax(s)
K = Pcal - 3 - dSB
fsum = s - K - 3 - 6 - 20*np.log10(np.sin(f*np.pi*tau)) -10*np.log10(rbw)
data = np.column_stack((f,fsum,s))
np.savetxt('rezultat.csv',data,delimiter=',')
print('*** Konec ***')

View File

@ -0,0 +1,82 @@
#!/usr/bin/python3
print('*** Preprost zvočni spektralni analizator - S53MV 28.09.2020 ***')
print('*** popravek odziva za EliteBook 8540w - Andrej 11.2.2012 ***')
print('*** meritev faznega suma (interpolacija in povprecenje v frekvenci-sai) - Andrej 15.2.2012 ***')
fs=192000 #Frekvenca vzročenja zvočnega signala (max 192000Hz)
pts=2048 #Število točk spektra 0...fs/2 (potenca 2 za učinkovit FFT)
avg=128 #Število povprečenj spektra
import sounddevice as sd #Poiskati na spletu in naložiti s pip3!
import numpy as np #Uporaba učinkovitih funkcij numpy
import matplotlib.pyplot as plt #Risanje rezultata z matplotlib
import matplotlib.animation as animation
sd.default.device = 0
fskala=np.linspace(0,fs/2,2*pts+1)[:-1] #Izračunaj frekvenčno skalo [Hz]
### podatki za kalibracijo sistema
dSB = -64.1+14.0 #dB
L = 1256 #metrov
tau = L*1.4676/3e8
T = 2*1.4676/3e8
### popravek odziva
odziv = np.loadtxt("5mhz-polinom-2048tock.csv", delimiter=',')
a = odziv[:,1]
popravek = np.max(a[4:-1])-a[4:-1]
def spekter(fs,pts,avg,fskala): #Zajem signala z zvočno kartico in povprečenje spektra [dB]
s=sd.rec(pts*(1+avg),samplerate=fs,channels=1) #Vzorčenje ADC zvočne kartice, 2D polje!
sd.wait() #Počakaj do konca vzorčenja
nz=1.e-12 #Dodatek za neničelni argument logaritma
s2=np.square(s) #Izpis jakosti/max [dB]
print('Jakost:',"%.1f"%(10*np.log10(nz+np.mean(s2))),'dB Vrh:',"%.1f"%(10*np.log10(nz+np.amax(s2))),'dB',end=' ')
o=1+np.cos(np.linspace(-np.pi,np.pi,2*pts)) #Okno dvignjeni kosinus
k=0
s2=np.zeros(2*pts)
while k<pts*avg: #Seštevanje moči FFT
s2=s2+np.square(np.abs(np.fft.rfft(o*s.reshape(-1)[k:k+2*pts],n=4*pts)[:-1]))
k+=pts
s=10*np.log10(nz+0.5*s2/pts/pts/avg) #Povprečje [dB]
print(' Max:',"%.1f"%(np.amax(s[4:-1])),'dB @',"%.1f"%(fskala[np.argmax(s[200:-1])]),'Hz')
return s[4:-1]+popravek
### izris z animacijo
f=fskala[4:-1]
rbw = np.diff(f)[0]
print(rbw)
initsum = spekter(fs,pts,avg,fskala)
fig,ax = plt.subplots()
raw,pn, = ax.plot(f,initsum,f,initsum)
ax.set_xlim(100, 100000)
ax.set_ylim(-130,-30)
ax.set_ylabel("Fazni šum [dBc/Hz]")
ax.set_xlabel("Frekvenčni odmik [Hz]")
plt.yticks(np.arange(-150,-29,10))
plt.xscale('log')
ax.grid(True)
def meritev(nic):
s = spekter(fs,pts,avg,fskala)
Pcal = np.amax(s)
K = Pcal - 3 - dSB - 20*np.log10(np.pi*T*84e3)
fsum = s - K - 3 - 6 - 20*np.log10(np.sin(f*np.pi*tau)) -10*np.log10(rbw)
raw.set_data(f,s)
pn.set_data(f,fsum)
ax.figure.canvas.draw()
return raw,pn
ani = animation.FuncAnimation(fig,meritev,interval=50)
plt.show()
#shrani csv file
s = spekter(fs,pts,avg,fskala)
Pcal = np.amax(s[200:-1])
K = Pcal - 3 - dSB - 20*np.log10(np.pi*T*84e3)
fsum = s - K - 3 - 6 - 20*np.log10(np.sin(f*np.pi*tau)) -10*np.log10(rbw)
data = np.column_stack((f,fsum,s))
np.savetxt('floor.csv',data,delimiter=',')
print('*** Konec ***')

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,48 @@
#!/usr/bin/python3
print('*** Preprost zvočni spektralni analizator - S53MV 28.09.2020 ***')
print('*** popravek odziva za EliteBook 8540w - Andrej 11.2.2012 ***')
fs=192000 #Frekvenca vzročenja zvočnega signala (max 192000Hz)
pts=2048 #Število točk spektra 0...fs/2 (potenca 2 za učinkovit FFT)
avg=128 #Število povprečenj spektra
import sounddevice as sd #Poiskati na spletu in naložiti s pip3!
import numpy as np #Uporaba učinkovitih funkcij numpy
import matplotlib.pyplot as plt #Risanje rezultata z matplotlib
sd.default.device = 0
fskala=np.linspace(0,fs/2,2*pts+1)[:-1] #Izračunaj frekvenčno skalo [Hz]
### popravek odziva
odziv = np.loadtxt("5mhz-polinom-2048tock.csv", delimiter=',')
a = odziv[:,1]
popravek = np.max(a[4:-1])-a[4:-1]
def spekter(fs,pts,avg,fskala): #Zajem signala z zvočno kartico in povprečenje spektra [dB]
s=sd.rec(pts*(1+avg),samplerate=fs,channels=1) #Vzorčenje ADC zvočne kartice, 2D polje!
sd.wait() #Počakaj do konca vzorčenja
nz=1.e-12 #Dodatek za neničelni argument logaritma
s2=np.square(s) #Izpis jakosti/max [dB]
print('Jakost:',"%.1f"%(10*np.log10(nz+np.mean(s2))),'dB Vrh:',"%.1f"%(10*np.log10(nz+np.amax(s2))),'dB',end=' ')
o=1+np.cos(np.linspace(-np.pi,np.pi,2*pts)) #Okno dvignjeni kosinus
k=0
s2=np.zeros(2*pts)
while k<pts*avg: #Seštevanje moči FFT
s2=s2+np.square(np.abs(np.fft.rfft(o*s.reshape(-1)[k:k+2*pts],n=4*pts)[:-1]))
k+=pts
s=10*np.log10(nz+0.5*s2/pts/pts/avg) #Povprečje [dB]
print(' Max:',"%.1f"%(np.amax(s)),'dB @',"%.1f"%(fskala[np.argmax(s)]),'Hz')
return s[4:-1]+popravek
wfbp=None
while wfbp!=True: #Prvo risanje spektra z normalizacijo, ponovi s klikom miške
fig,ax=plt.subplots()
line,=ax.plot(fskala[4:-1],spekter(fs,pts,avg,fskala))
wfbp=plt.waitforbuttonpress(0.01)
while wfbp==None: #Zanka risanja spektra, izhod=pritisk tipke ali miške
line.set_ydata(spekter(fs,pts,avg,fskala))
fig.canvas.draw()
wfbp=plt.waitforbuttonpress(0.01)
plt.close()
print('*** Konec ***') #pritisk tipke na tipkovnici

View File

@ -0,0 +1,45 @@
#!/usr/bin/python3
print('*** Preprost zvočni spektralni analizator - S53MV 28.09.2020 ***')
fs=192000 #Frekvenca vzročenja zvočnega signala (max 192000Hz)
pts=2048 #Število točk spektra 0...fs/2 (potenca 2 za učinkovit FFT)
avg=128 #Število povprečenj spektra
import sounddevice as sd #Poiskati na spletu in naložiti s pip3!
import numpy as np #Uporaba učinkovitih funkcij numpy
import matplotlib.pyplot as plt #Risanje rezultata z matplotlib
sd.default.device = 0
fskala=np.linspace(0,fs/2,2*pts+1)[:-1] #Izračunaj frekvenčno skalo [Hz]
def spekter(fs,pts,avg,fskala): #Zajem signala z zvočno kartico in povprečenje spektra [dB]
s=sd.rec(pts*(1+avg),samplerate=fs,channels=1) #Vzorčenje ADC zvočne kartice, 2D polje!
sd.wait() #Počakaj do konca vzorčenja
nz=1.e-12 #Dodatek za neničelni argument logaritma
s2=np.square(s) #Izpis jakosti/max [dB]
print('Jakost:',"%.1f"%(10*np.log10(nz+np.mean(s2))),'dB Vrh:',"%.1f"%(10*np.log10(nz+np.amax(s2))),'dB',end=' ')
o=1+np.cos(np.linspace(-np.pi,np.pi,2*pts)) #Okno dvignjeni kosinus
k=0
s2=np.zeros(2*pts)
while k<pts*avg: #Seštevanje moči FFT
s2=s2+np.square(np.abs(np.fft.rfft(o*s.reshape(-1)[k:k+2*pts],n=4*pts)[:-1]))
k+=pts
s=10*np.log10(nz+0.5*s2/pts/pts/avg) #Povprečje [dB]
print(' Max:',"%.1f"%(np.amax(s)),'dB @',"%.1f"%(fskala[np.argmax(s)]),'Hz')
return s
meritev = spekter(fs,pts,avg,fskala)
#print(meritev)
#print(fskala)
data = np.column_stack((fskala, meritev))
np.savetxt('5mhz-polinom-2048tock.csv', data, delimiter=',')
#wfbp=None
#while wfbp!=True: #Prvo risanje spektra z normalizacijo, ponovi s klikom miške
# fig,ax=plt.subplots()
# line,=ax.plot(fskala,spekter(fs,pts,avg,fskala))
# wfbp=plt.waitforbuttonpress(0.01)
# while wfbp==None: #Zanka risanja spektra, izhod=pritisk tipke ali miške
# line.set_ydata(spekter(fs,pts,avg,fskala))
# fig.canvas.draw()
# wfbp=plt.waitforbuttonpress(0.01)
# plt.close()
#print('*** Konec ***') #pritisk tipke na tipkovnici

View File

@ -0,0 +1,45 @@
#!/usr/bin/python3
print('*** Preprost zvočni spektralni analizator - S53MV 28.09.2020 ***')
fs=192000 #Frekvenca vzročenja zvočnega signala (max 192000Hz)
pts=2048 #Število točk spektra 0...fs/2 (potenca 2 za učinkovit FFT)
avg=128 #Število povprečenj spektra
import sounddevice as sd #Poiskati na spletu in naložiti s pip3!
import numpy as np #Uporaba učinkovitih funkcij numpy
import matplotlib.pyplot as plt #Risanje rezultata z matplotlib
sd.default.device = 0
fskala=np.linspace(0,fs/2,2*pts+1)[:-1] #Izračunaj frekvenčno skalo [Hz]
def spekter(fs,pts,avg,fskala): #Zajem signala z zvočno kartico in povprečenje spektra [dB]
s=sd.rec(pts*(1+avg),samplerate=fs,channels=1) #Vzorčenje ADC zvočne kartice, 2D polje!
sd.wait() #Počakaj do konca vzorčenja
nz=1.e-12 #Dodatek za neničelni argument logaritma
s2=np.square(s) #Izpis jakosti/max [dB]
print('Jakost:',"%.1f"%(10*np.log10(nz+np.mean(s2))),'dB Vrh:',"%.1f"%(10*np.log10(nz+np.amax(s2))),'dB',end=' ')
o=1+np.cos(np.linspace(-np.pi,np.pi,2*pts)) #Okno dvignjeni kosinus
k=0
s2=np.zeros(2*pts)
while k<pts*avg: #Seštevanje moči FFT
s2=s2+np.square(np.abs(np.fft.rfft(o*s.reshape(-1)[k:k+2*pts],n=4*pts)[:-1]))
k+=pts
s=10*np.log10(nz+0.5*s2/pts/pts/avg) #Povprečje [dB]
print(' Max:',"%.1f"%(np.amax(s)),'dB @',"%.1f"%(fskala[np.argmax(s)]),'Hz')
return s
meritev = spekter(fs,pts,avg,fskala)
#print(meritev)
#print(fskala)
#data = np.column_stack((fskala, meritev))
#np.savetxt('10mhz-polinom-2048tock.csv', data, delimiter=',')
wfbp=None
while wfbp!=True: #Prvo risanje spektra z normalizacijo, ponovi s klikom miške
fig,ax=plt.subplots()
line,=ax.plot(fskala,spekter(fs,pts,avg,fskala))
wfbp=plt.waitforbuttonpress(0.01)
while wfbp==None: #Zanka risanja spektra, izhod=pritisk tipke ali miške
line.set_ydata(spekter(fs,pts,avg,fskala))
fig.canvas.draw()
wfbp=plt.waitforbuttonpress(0.01)
plt.close()
print('*** Konec ***') #pritisk tipke na tipkovnici

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,25 @@
#!/usr/bin/gnuplot
set datafile separator ","
set terminal pdf
set xlabel "Frequency offset (Hz)"
set ylabel "Phase noise (dBc/Hz)"
set format x "10^{%T}"
set xrange [100:100000]
set yrange [-150:-50]
set key bottom left
set grid
set grid mxtics
set logscale x
set output "floor.pdf"
set title "Noise floors"
plot "floor1m-oeo.csv" u 1:2 w lines title "oeo 1m",\
"floor2m-oeo.csv" u 1:2 w lines title "oeo 2m",\
"floor2m-kul-meritev.csv" u 1:2 w lines title "2m veriga",\
"floor3-1m-oeo.csv" u 1:2 w lines title "oeo 1m",\
"floor-oeo-1m-praviSB.csv" u 1:2 w lines title "oeo pravi sb",\
"floor1.csv" u 1:2 w lines t "ena",\
"floor2.csv" u 1:2 w l t "dva"

View File

@ -0,0 +1,24 @@
#!/usr/bin/gnuplot
set datafile separator ","
set terminal pdf
set xlabel "Frequency offset (Hz)"
set ylabel "Phase noise (dBc/Hz)"
set format x "10^{%T}"
set xrange [100:100000]
set yrange [-160:-60]
set key bottom left
set grid
set grid mxtics
set logscale x
set output "noise.pdf"
set title "Fazni sum"
plot "chain.csv" u 1:2 w lines title "vcxo 1",\
"chain1.csv" u 1:2 w lines title "vcxo 2",\
"veriga-dobra.csv" u 1:2 w lines title "vcxo 3",\
"oeo.csv" u 1:2 w lines title "oeo 1",\
"oeo-vidmar-amp.csv" u 1:2 w lines title "oeo 2",\
"oeo-3.csv" u 1:2 w lines t "oeo 3"

View File

@ -0,0 +1,17 @@
#!/usr/bin/python3
# brezvezno risanje popravka
import numpy as np
import matplotlib.pyplot as plt
sum = np.loadtxt("5mhz-polinom-2048tock.csv", delimiter=',')
print(sum)
f = sum[:,0]
a = sum[:,1]
print(f[4:9])
print(a[4:9])
popravek = np.max(a[4:-1])-a[4:-1]
plt.plot(f[4:-1],popravek)
plt.show()

View File

@ -0,0 +1,69 @@
#!/usr/bin/python3
print('*** Preprost zvočni spektralni analizator - S53MV 28.09.2020 ***')
print('*** Preprost zvočni spektralni analizator - S53MV 28.09.2020 ***')
fs=192000 #Frekvenca vzročenja zvočnega signala (max 192000Hz)
pts=2048 #Število točk spektra 0...fs/2 (potenca 2 za učinkovit FFT)
avg=128 #Število povprečenj spektra
import sounddevice as sd #Poiskati na spletu in naložiti s pip3!
import numpy as np #Uporaba učinkovitih funkcij numpy
import matplotlib.pyplot as plt #Risanje rezultata z matplotlib
import matplotlib.animation as animation
sd.default.device = 0
fskala=np.linspace(0,fs/2,pts+1)[:-1] #Izračunaj frekvenčno skalo [Hz]
### podatki za kalibracijo sistema
dSB = -61.95+15.53 #dB
L = 1256 #metrov
tau = L*1.4676/3e8
### popravek odziva
odziv = np.loadtxt("tcos-5mhz-polinom-2048tock.csv", delimiter=',')
a = odziv[:,1]
popravek = np.max(a[4:-1])-a[4:-1]
def spekter(fs,pts,avg,fskala): #Zajem signala z zvočno kartico in povprečenje spektra [dB]
s=sd.rec(pts*(1+avg),samplerate=fs,channels=1) #Vzorčenje ADC zvočne kartice, 2D polje!
sd.wait() #Počakaj do konca vzorčenja
nz=1.e-12 #Dodatek za neničelni argument logaritma
s2=np.square(s) #Izpis jakosti/max [dB]
print('Jakost:',"%.1f"%(10*np.log10(nz+np.mean(s2))),'dB Vrh:',"%.1f"%(10*np.log10(nz+np.amax(s2))),'dB',end=' ')
o=1+np.cos(np.linspace(-np.pi,np.pi,2*pts)) #Okno dvignjeni kosinus
k=0
s2=np.zeros(pts)
while k<pts*avg: #Seštevanje moči FFT
s2=s2+np.square(np.abs(np.fft.rfft(o*s.reshape(-1)[k:k+2*pts])[:-1]))
k+=pts
s=10*np.log10(nz+0.5*s2/pts/pts/avg) #Povprečje [dB]
print(' Max:',"%.1f"%(np.amax(s[4:-1])),'dB @',"%.1f"%(fskala[np.argmax(s[4:-1])]),'Hz')
return s[4:-1]+popravek
### izris z animacijo
f=fskala[4:-1]
initsum = spekter(fs,pts,avg,fskala)
fig,ax = plt.subplots()
raw,pn, = ax.plot(f,initsum,f,initsum)
ax.set_xlim(100, 100000)
ax.set_ylim(-130,-30)
ax.set_ylabel("Fazni šum [dBc/Hz]")
ax.set_xlabel("Frekvenčni odmik [Hz]")
plt.yticks(np.arange(-130,-29,10))
plt.xscale('log')
ax.grid(True)
def meritev(nic):
s = spekter(fs,pts,avg,fskala)
Pcal = np.amax(s)
K = Pcal - 3 - dSB
fsum = s - K - 3 - 6 - 20*np.log10(np.sin(f*np.pi*tau))
raw.set_data(f,s)
pn.set_data(f,fsum)
ax.figure.canvas.draw()
return raw,pn
ani = animation.FuncAnimation(fig,meritev,interval=50)
plt.show()
print('*** Konec ***') #pritisk tipke na tipkovnici

View File

@ -0,0 +1,47 @@
#!/usr/bin/python3
print('*** Preprost zvočni spektralni analizator - S53MV 28.09.2020 ***')
print('*** Preprost zvočni spektralni analizator - S53MV 28.09.2020 ***')
fs=192000 #Frekvenca vzročenja zvočnega signala (max 192000Hz)
pts=2048 #Število točk spektra 0...fs/2 (potenca 2 za učinkovit FFT)
avg=128 #Število povprečenj spektra
import sounddevice as sd #Poiskati na spletu in naložiti s pip3!
import numpy as np #Uporaba učinkovitih funkcij numpy
import matplotlib.pyplot as plt #Risanje rezultata z matplotlib
sd.default.device = 0
fskala=np.linspace(0,fs/2,pts+1)[:-1] #Izračunaj frekvenčno skalo [Hz]
### popravek odziva
odziv = np.loadtxt("tcos-5mhz-polinom-2048tock.csv", delimiter=',')
a = odziv[:,1]
popravek = np.max(a[4:-1])-a[4:-1]
def spekter(fs,pts,avg,fskala): #Zajem signala z zvočno kartico in povprečenje spektra [dB]
s=sd.rec(pts*(1+avg),samplerate=fs,channels=1) #Vzorčenje ADC zvočne kartice, 2D polje!
sd.wait() #Počakaj do konca vzorčenja
nz=1.e-12 #Dodatek za neničelni argument logaritma
s2=np.square(s) #Izpis jakosti/max [dB]
print('Jakost:',"%.1f"%(10*np.log10(nz+np.mean(s2))),'dB Vrh:',"%.1f"%(10*np.log10(nz+np.amax(s2))),'dB',end=' ')
o=1+np.cos(np.linspace(-np.pi,np.pi,2*pts)) #Okno dvignjeni kosinus
k=0
s2=np.zeros(pts)
while k<pts*avg: #Seštevanje moči FFT
s2=s2+np.square(np.abs(np.fft.rfft(o*s.reshape(-1)[k:k+2*pts])[:-1]))
k+=pts
s=10*np.log10(nz+0.5*s2/pts/pts/avg) #Povprečje [dB]
print(' Max:',"%.1f"%(np.amax(s)),'dB @',"%.1f"%(fskala[np.argmax(s)]),'Hz')
return s[4:-1]+popravek
wfbp=None
while wfbp!=True: #Prvo risanje spektra z normalizacijo, ponovi s klikom miške
fig,ax=plt.subplots()
line,=ax.plot(fskala[4:-1],spekter(fs,pts,avg,fskala))
wfbp=plt.waitforbuttonpress(0.01)
while wfbp==None: #Zanka risanja spektra, izhod=pritisk tipke ali miške
line.set_ydata(spekter(fs,pts,avg,fskala))
fig.canvas.draw()
wfbp=plt.waitforbuttonpress(0.01)
plt.close()
print('*** Konec ***') #pritisk tipke na tipkovnici

View File

@ -0,0 +1,47 @@
#!/usr/bin/python3
print('*** Preprost zvočni spektralni analizator - S53MV 28.09.2020 ***')
print('*** Preprost zvočni spektralni analizator - S53MV 28.09.2020 ***')
fs=192000 #Frekvenca vzročenja zvočnega signala (max 192000Hz)
pts=2048 #Število točk spektra 0...fs/2 (potenca 2 za učinkovit FFT)
avg=128 #Število povprečenj spektra
import sounddevice as sd #Poiskati na spletu in naložiti s pip3!
import numpy as np #Uporaba učinkovitih funkcij numpy
import matplotlib.pyplot as plt #Risanje rezultata z matplotlib
sd.default.device = 0
fskala=np.linspace(0,fs/2,pts+1)[:-1] #Izračunaj frekvenčno skalo [Hz]
def spekter(fs,pts,avg,fskala): #Zajem signala z zvočno kartico in povprečenje spektra [dB]
s=sd.rec(pts*(1+avg),samplerate=fs,channels=1) #Vzorčenje ADC zvočne kartice, 2D polje!
sd.wait() #Počakaj do konca vzorčenja
nz=1.e-12 #Dodatek za neničelni argument logaritma
s2=np.square(s) #Izpis jakosti/max [dB]
print('Jakost:',"%.1f"%(10*np.log10(nz+np.mean(s2))),'dB Vrh:',"%.1f"%(10*np.log10(nz+np.amax(s2))),'dB',end=' ')
o=1+np.cos(np.linspace(-np.pi,np.pi,2*pts)) #Okno dvignjeni kosinus
k=0
s2=np.zeros(pts)
while k<pts*avg: #Seštevanje moči FFT
s2=s2+np.square(np.abs(np.fft.rfft(o*s.reshape(-1)[k:k+2*pts])[:-1]))
k+=pts
s=10*np.log10(nz+0.5*s2/pts/pts/avg) #Povprečje [dB]
print(' Max:',"%.1f"%(np.amax(s)),'dB @',"%.1f"%(fskala[np.argmax(s)]),'Hz')
return s
meritev = spekter(fs,pts,avg,fskala)
#print(meritev)
#print(fskala)
data = np.column_stack((fskala, meritev))
np.savetxt('tcos-5mhz-polinom-2048tock.csv', data, delimiter=',')
wfbp=None
while wfbp!=True: #Prvo risanje spektra z normalizacijo, ponovi s klikom miške
fig,ax=plt.subplots()
line,=ax.plot(fskala,spekter(fs,pts,avg,fskala))
wfbp=plt.waitforbuttonpress(0.01)
while wfbp==None: #Zanka risanja spektra, izhod=pritisk tipke ali miške
line.set_ydata(spekter(fs,pts,avg,fskala))
fig.canvas.draw()
wfbp=plt.waitforbuttonpress(0.01)
plt.close()
print('*** Konec ***') #pritisk tipke na tipkovnici

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff