functioning examples
This commit is contained in:
parent
e746d7491b
commit
1f93e8bc1e
5 changed files with 102 additions and 30 deletions
48
.ipynb_checkpoints/sound_profile-checkpoint.py
Normal file
48
.ipynb_checkpoints/sound_profile-checkpoint.py
Normal file
|
|
@ -0,0 +1,48 @@
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
import numpy as np
|
||||||
|
import random
|
||||||
|
import acoustics.decibel as db
|
||||||
|
|
||||||
|
|
||||||
|
freq_upper = 10000 #size of the frequency spectrum we want to investigate
|
||||||
|
freq_div = 10
|
||||||
|
|
||||||
|
x = np.array(range(freq_upper)) #initialize frequencies (x-axis)
|
||||||
|
bkgd = np.zeros(freq_upper)
|
||||||
|
source = np.zeros(freq_upper)
|
||||||
|
|
||||||
|
for i in range(len(bkgd)):
|
||||||
|
bkgd[i] = np.log((x[i]+1)/freq_div) #input model for background here. each freq is assigned an SNR
|
||||||
|
|
||||||
|
tonals = [20,40,100,500, 800] #build our threat object here
|
||||||
|
widths = [2,2,2,2,2] #how diffuse is each tonal
|
||||||
|
decr = [.5,.5,.5,.95,.98] #sound decrement from ambient
|
||||||
|
|
||||||
|
|
||||||
|
for i in range(len(source)):
|
||||||
|
source[i] = random.randint(0,10)/200
|
||||||
|
|
||||||
|
|
||||||
|
for tone,wide,loud in zip(tonals, widths, decr): #right now the source is based on bkgd
|
||||||
|
freq = tone - wide//2 #strength, but we will need to just
|
||||||
|
while freq < tone + wide//2: #assign values
|
||||||
|
source[freq] = bkgd[freq]*(1-loud) #
|
||||||
|
freq += 1 #
|
||||||
|
|
||||||
|
|
||||||
|
received = db.dbadd(bkgd, source)
|
||||||
|
|
||||||
|
|
||||||
|
plt.plot(x/freq_div,received, label = "Legacy")
|
||||||
|
plt.plot(x/freq_div,source, label = "Distilled")
|
||||||
|
plt.xlabel("freq (Hz)")
|
||||||
|
plt.ylabel("SNR")
|
||||||
|
plt.title("Concept")
|
||||||
|
|
||||||
|
plt.legend()
|
||||||
|
plt.show()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1,38 +1,39 @@
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
from matplotlib.widgets import Slider, Button
|
from matplotlib.widgets import Slider, Button
|
||||||
|
import random
|
||||||
|
|
||||||
soundscape = np.empty((1000,1))
|
soundscape = np.empty((1000,1))
|
||||||
for i in range(1000):
|
for i in range(1000):
|
||||||
soundscape[(i,0)] = -.003*i-60
|
soundscape[(i,0)] = -.03*i-60
|
||||||
brgs = np.ones((1,360))
|
brgs = np.ones((1,360))
|
||||||
brg_freq = np.matmul(soundscape, brgs)
|
brg_freq = np.matmul(soundscape, brgs)
|
||||||
|
|
||||||
targ_brg = [60]
|
|
||||||
brg_width = [5]
|
targ_brg = [60,220]
|
||||||
tonals = [20,40,100,500, 800] #build our threat object here
|
brg_width = [5, 5]
|
||||||
tonal_widths = [2,2,2,2,2] #how diffuse is each tonal
|
tonals = [[20,40,100,500, 800], [30,60,200,250,500]] #build our threat object here
|
||||||
decr = [.8,.8,.8,.90,.90] #sound decrement from ambient
|
tonal_widths = [[2,2,2,2,2], [6,5,4,3,2]] #how diffuse is each tonal
|
||||||
|
decr = [[.8,.8,.8,.90,.90], [.7,.6,.5,.4,.3]] #sound decrement from ambient
|
||||||
|
|
||||||
|
i = 0
|
||||||
|
while i < 50000:
|
||||||
|
brg_freq[random.randint(0,999),random.randint(0,359)] = random.randint(-60,-50)
|
||||||
|
i+=1
|
||||||
|
|
||||||
|
|
||||||
for azim,spread in zip(targ_brg,brg_width):
|
for azim,spread,x,y,z in zip(targ_brg,brg_width, tonals, tonal_widths, decr):
|
||||||
brg = azim - spread//2
|
brg = azim - spread//2
|
||||||
while brg <= azim + spread//2:
|
while brg <= azim + spread//2:
|
||||||
for tone,wide,loud in zip(tonals, tonal_widths, decr):#right now the source is based on bkgd
|
for tone,wide,loud in zip(x,y,z):
|
||||||
freq = tone - wide//2 #strength, but we will need to just
|
freq = tone - wide//2 #strength, but we will need to just
|
||||||
while freq < tone + wide//2: #assign values
|
while freq < tone + wide//2: #assign values
|
||||||
brg_freq[(freq,brg)] = -50 #
|
brg_freq[(freq,brg)] = -35 #
|
||||||
freq += 1
|
freq += 1
|
||||||
brg += 1
|
brg += 1
|
||||||
|
|
||||||
axtime = plt.axes()
|
|
||||||
time = Slider(axtime, "Time", 0, 60)
|
|
||||||
def update(brg):
|
|
||||||
t = time.val
|
|
||||||
time.on_changed(update)
|
|
||||||
|
|
||||||
plt.imshow(brg_freq)
|
plt.imshow(brg_freq, origin="lower", aspect=.25)
|
||||||
plt.colorbar()
|
plt.colorbar()
|
||||||
plt.show()
|
plt.show()
|
||||||
|
|
||||||
|
|
@ -40,3 +41,5 @@ plt.show()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
BIN
mesh.png
Normal file
BIN
mesh.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 312 KiB |
|
|
@ -4,37 +4,55 @@ import random
|
||||||
import acoustics.decibel as db
|
import acoustics.decibel as db
|
||||||
|
|
||||||
|
|
||||||
freq_upper = 10000 #size of the frequency spectrum we want to investigate
|
freq_upper = 1000 #size of the frequency spectrum we want to investigate
|
||||||
freq_div = 10
|
#freq_div = 10
|
||||||
|
#freq_bin = freq_upper/freq_div
|
||||||
|
|
||||||
x = np.array(range(freq_upper)) #initialize frequencies (x-axis)
|
x = np.array(range(freq_upper)) #initialize frequencies (x-axis)
|
||||||
bkgd = np.zeros(freq_upper)
|
bkgd = np.zeros(freq_upper)
|
||||||
source = np.zeros(freq_upper)
|
source = np.zeros(freq_upper)
|
||||||
|
fav_received = np.zeros(freq_upper)
|
||||||
|
fav_source = np.zeros(freq_upper)
|
||||||
|
|
||||||
for i in range(len(bkgd)):
|
for i in range(len(bkgd)):
|
||||||
bkgd[i] = np.log((x[i]+1)/freq_div) #input model for background here. each freq is assigned an SNR
|
bkgd[i] = -.003*x[i]-60 #input model for background here. each freq is assigned an SNR
|
||||||
|
bkgd[i] = 10**(bkgd[i]/20)
|
||||||
|
|
||||||
tonals = [20,40,100,500, 800] #build our threat object here
|
tonals = [20,40,100,500, 800] #build our threat object here
|
||||||
widths = [2,2,2,2,2] #how diffuse is each tonal
|
widths = [2,2,2,2,2] #how diffuse is each tonal
|
||||||
decr = [.5,.5,.5,.95,.98] #sound decrement from ambient
|
decr = [.8,.8,.8,.90,.90] #sound decrement from ambient
|
||||||
|
|
||||||
|
|
||||||
for i in range(len(source)):
|
#for i in range(len(source)):
|
||||||
source[i] = random.randint(0,10)/200
|
# source[i] = random.randint(0,10)/200
|
||||||
|
|
||||||
|
|
||||||
for tone,wide,loud in zip(tonals, widths, decr): #right now the source is based on bkgd
|
for tone,wide,loud in zip(tonals, widths, decr): #right now the source is based on bkgd
|
||||||
freq = tone - wide//2 #strength, but we will need to just
|
freq = tone - wide//2 #strength, but we will need to just
|
||||||
while freq < tone + wide//2: #assign values
|
while freq < tone + wide//2: #assign values
|
||||||
source[freq] = bkgd[freq]*(1-loud) #
|
source[freq] = bkgd[i]*(1-loud) #
|
||||||
freq += 1 #
|
freq += 1 #
|
||||||
|
|
||||||
|
|
||||||
received = db.dbadd(bkgd, source)
|
received = bkgd + source
|
||||||
|
for i in range(freq_upper):
|
||||||
|
received[i] = 20*np.log10(received[i])
|
||||||
|
|
||||||
|
for i in range(freq_upper):
|
||||||
|
source[i] = 20*np.log10(source[i])
|
||||||
|
|
||||||
|
for i in range(freq_upper-1):
|
||||||
|
fav_received[i] = abs((received[i]-received[i+1])**3)
|
||||||
|
|
||||||
|
for i in range(freq_upper):
|
||||||
|
source[i] = db.dbsub(received[i],bkgd[i]/2)
|
||||||
|
|
||||||
|
for i in range(freq_upper-1):
|
||||||
|
fav_source[i] = abs((source[i]-source[i+1])**3)
|
||||||
|
|
||||||
|
|
||||||
plt.plot(x/freq_div,received, label = "Legacy")
|
plt.plot(x, received, label = "Legacy")
|
||||||
plt.plot(x/freq_div,source, label = "Distilled")
|
plt.plot(x, source, label = "Distilled")
|
||||||
|
|
||||||
plt.xlabel("freq (Hz)")
|
plt.xlabel("freq (Hz)")
|
||||||
plt.ylabel("SNR")
|
plt.ylabel("SNR")
|
||||||
plt.title("Concept")
|
plt.title("Concept")
|
||||||
|
|
@ -42,7 +60,10 @@ plt.title("Concept")
|
||||||
plt.legend()
|
plt.legend()
|
||||||
plt.show()
|
plt.show()
|
||||||
|
|
||||||
|
"""plt.plot(x, fav_received, label = "Traces")
|
||||||
|
plt.plot(x, fav_source+1, label = "Distilled Traces")
|
||||||
|
plt.legend()
|
||||||
|
plt.show()
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
0
test.py
Normal file
0
test.py
Normal file
Loading…
Add table
Add a link
Reference in a new issue