<jupyter_start><jupyter_text>Atmospheric attenuation In this notebook we have a look at the error in applying the atmospheric attenuation to a signal.<jupyter_code>import numpy as np
%matplotlib inline
import matplotlib.pyplot as plt
from auraliser.propagation import apply_atmospheric_absorption
from acoustics import Signal
from acoustics.atmosphere import Atmosphere
from IPython.parallel import Client
client = Client()
lview = client.load_balanced_view()
def calculate_signal(kwargs):
    
    def _calculate(fs, frequency, distance, n_blocks, n_distances, duration): 
        from auraliser.propagation import apply_atmospheric_absorption
        from acoustics import Signal
        from acoustics.atmosphere import Atmosphere
        import numpy as np
        atmosphere = Atmosphere()

        samples = int(fs*duration)
        t = np.arange(samples) / fs

        signal = Signal( np.sin(2.0*np.pi*frequency*t) , fs)

        out = Signal( apply_atmospheric_absorption(signal, fs, atmosphere, distance*np.ones(samples), 
                                                   n_blocks=n_blocks, n_distances=n_distances) , fs)

        att = atmosphere.attenuation_coefficient(frequency) * distance

        difference = signal.leq() - out.leq()
        return difference - att
    
    return _calculate(**kwargs)<jupyter_output><empty_output><jupyter_text>Parameters<jupyter_code>params = dict()
params['duration'] = 5.0
params['fs'] = 10025
params['frequency'] = 1000.0
params['distance'] = 100.0
params['n_blocks']= 512
params['n_distances'] = 10
def study(params, parameter, values):
    """Parameter study."""
    for value in values:
        out = params.copy()
        out[parameter] = value
        yield out<jupyter_output><empty_output><jupyter_text>Vary duration<jupyter_code>#values = [5.0, 10.0, 15.0, 20.0, 25.0, 30.0]
values = [2.0, 4.0, 8.0, 16.0]
parameters = list( study(params, 'duration', values) )
out = lview.map(calculate_signal, parameters)
fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(values, out)
ax.set_title("Error in dB")<jupyter_output><empty_output><jupyter_text>Vary sample frequency<jupyter_code>values = [5000.0, 8000.0, 12000.0, 20000.0, 30000.0, 44100.0]
parameters = list( study(params, 'fs', values) )
out = lview.map(calculate_signal, parameters)
fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(values, out)
ax.set_title("Error in dB")<jupyter_output><empty_output><jupyter_text>Vary frequency<jupyter_code>values = [100.0, 200.0, 800.0, 1600.0, 3200.0, 6400.0]
parameters = list( study(params, 'fs', values) )
out = lview.map(calculate_signal, parameters)
fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(values, out)
ax.set_title("Error in dB")<jupyter_output><empty_output><jupyter_text>Vary distance<jupyter_code>values = [100.0, 200.0, 400.0, 800.0, 1600.0, 3200.0]
parameters = list( study(params, 'distance', values) )
out = lview.map(calculate_signal, parameters)
fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(values, out)
ax.set_title("Error in dB")<jupyter_output><empty_output><jupyter_text>Vary blocks<jupyter_code>values = [16, 32, 64, 128, 256, 512, 1024, 2048]
parameters = list( study(params, 'n_blocks', values) )
out = lview.map(calculate_signal, parameters)
fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(values, out)
ax.set_title("Error in dB")<jupyter_output><empty_output><jupyter_text>Vary amount of unique distances<jupyter_code>values = [2, 4, 8, 16, 32, 64]
parameters = list( study(params, 'n_distances', values) )
out = lview.map(calculate_signal, parameters)
fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(values, out)
ax.set_title("Error in dB")
#lview.shutdown(restart=True)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12990855298547607, 'fraction_numerical': 0.05002689618074233, 'mean_word_length': 4.838304552590267, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '410342', 'license': 'BSD-2-Clause', 'n_tokens_mistral': 1454, 'n_tokens_neox': 1293, 'n_words': 290, 'path': 'examples/atmospheric_attenuation.ipynb', 'repo_name': 'FRidh/auraliser', 'size': '3718'}