This notebook is an attempt at trying to get the broadband directivity functions as Lasse suggested. 
In Madsen & Wahlberg 2007 (Deep Sea Research), the authors describe the integration of the directivity function over the signal's frequency range as a way to get the broadband directivity function. Let's try it out here. 

2021-05-21


```python
import matplotlib.pyplot as plt
import numpy as np 
import sympy 
from sympy import Integral, symbols, pi, lambdify
import beamshapes 
from beamshapes import piston_in_infinite_baffle as pib
from beamshapes.utilities import dB
import tqdm
```


```python
%matplotlib notebook
```


```python
a,k,theta,kmin,kmax = symbols('a k theta kmin kmax')
```

This is the famous piston in an infinite baffle directivity function. 


```python
pib.d_theta
```




$\displaystyle \frac{2 J_{1}\left(a k \sin{\left(\theta \right)}\right)}{a k \sin{\left(\theta \right)}}$



Let's now integrate it wrt to the k from kmin-->kmax


```python
Integral(pib.d_theta, (k,kmin,kmax))
```




$\displaystyle \int\limits_{kmin}^{kmax} \frac{2 J_{1}\left(a k \sin{\left(\theta \right)}\right)}{a k \sin{\left(\theta \right)}}\, dk$




```python
# make SymPy solve the integral 
integral_solution = Integral(pib.d_theta, (k,kmin,kmax)).doit()
integral_solution
```




$\displaystyle \frac{kmax \sqrt{\sin^{2}{\left(\theta \right)}} {{}_{1}F_{2}\left(\begin{matrix} \frac{1}{2} \\ \frac{3}{2}, 2 \end{matrix}\middle| {- \frac{a^{2} kmax^{2} \sin^{2}{\left(\theta \right)}}{4}} \right)}}{\sin{\left(\theta \right)}} - \frac{kmin \sqrt{\sin^{2}{\left(\theta \right)}} {{}_{1}F_{2}\left(\begin{matrix} \frac{1}{2} \\ \frac{3}{2}, 2 \end{matrix}\middle| {- \frac{a^{2} kmin^{2} \sin^{2}{\left(\theta \right)}}{4}} \right)}}{\sin{\left(\theta \right)}}$



So, it looks like SymPy could solve this integral - which is nice! Let's convert the expression into a function and get some outputs for broadband beamshapes!


```python
broadband_directivity = lambdify([kmin,kmax,a,theta,], integral_solution, 'sympy')
```


```python
broadband_directivity(100,200,0.1,0.001)
```




$\displaystyle 200.0 {{}_{1}F_{2}\left(\begin{matrix} 0.5 \\ 1.5, 2 \end{matrix}\middle| {-9.99999666666711 \cdot 10^{-5}} \right)} - 100.0 {{}_{1}F_{2}\left(\begin{matrix} 0.5 \\ 1.5, 2 \end{matrix}\middle| {-2.49999916666678 \cdot 10^{-5}} \right)}$




```python
thetas = np.linspace(-np.pi/2, np.pi/2,50)
kmin_v, kmax_v = 50,250
av = 0.01
bbd_dtheta = np.array(np.abs([broadband_directivity(kmin_v, kmax_v, av, each).evalf()  for each in thetas]), 'float32')
db_dtheta = dB(bbd_dtheta)
db_dtheta -= np.max(db_dtheta) # normalise to on-axis
```


```python
plt.figure()
a0 = plt.subplot(111, projection='polar')
plt.plot(thetas, db_dtheta)
a0.set_theta_zero_location("N");a0.set_thetamax(90);a0.set_thetamin(-90);plt.yticks(np.arange(-12,2,2));
plt.title(f'broadband beamshape, k:{kmin_v}-{kmax_v}')
```


    <IPython.core.display.Javascript object>









    Text(0.5, 1.0, 'broadband beamshape, k:50-250')



Let's compare this to the beamshapes at between $k=50-250$


```python
onefreq_dthetas = []
kvalues = np.arange(50,300,50)
for kv in tqdm.tqdm(kvalues):
    _, dtheta_onefreq = pib.piston_in_infinite_baffle_directivity(thetas, {'k':kv, 'a':av})
    onefreq_dthetas.append(dtheta_onefreq)

```

    100%|████████████████████████████████████████████████████████████████████████████████████| 5/5 [00:52<00:00, 10.58s/it]



```python
plt.figure()
a1 = plt.subplot(111, projection='polar')
for each, kv in zip(onefreq_dthetas,kvalues):
    a1.plot(thetas, each,label=str(kv))
a1.set_theta_zero_location("N");a1.set_thetamax(90);a1.set_thetamin(-90);plt.yticks(np.arange(-12,2,2));
plt.legend();
```


    <IPython.core.display.Javascript object>






### Extending this exercise to other models...To be done. 

ceba3927ea5e02b542d9d2495949b0a77350d028
ipynb
Jupyter Notebook
beamshapes/workshop/broadband directivity functions.ipynb
faroit/bat_beamshapes
9c2919b4e56dbd0cfc1039edc608ce1592b78df3
MIT
2022-01-05T02:06:33.000Z
2022-03-16T09:00:08.000Z
beamshapes/workshop/broadband directivity functions.ipynb
faroit/bat_beamshapes
9c2919b4e56dbd0cfc1039edc608ce1592b78df3
MIT
2021-08-10T20:48:34.000Z
2022-01-05T08:02:04.000Z
beamshapes/workshop/broadband directivity functions.ipynb
faroit/bat_beamshapes
9c2919b4e56dbd0cfc1039edc608ce1592b78df3
MIT
2022-01-04T14:50:17.000Z
2022-01-28T02:33:34.000Z
Qwen/Qwen-72B
1. YES
2. YES