Skip to content

Atmosphere Module

The atmosphere module contains functions and classes related to atmospheric acoustics and is based on ISO 9613-1:1993.

CLASS DESCRIPTION
Atmosphere

Class describing atmospheric conditions.

FUNCTION DESCRIPTION
soundspeed

Calculate the speed of sound.

saturation_pressure

Calculate the saturation pressure.

molar_concentration_water_vapour

Calculate the molar concentration of water vapour.

relaxation_frequency_nitrogen

Calculate the relaxation frequency of nitrogen.

relaxation_frequency_oxygen

Calculate the relaxation frequency of oxygen.

attenuation_coefficient

Calculate the attenuation coefficient.

Attributes

SOUNDSPEED module-attribute

SOUNDSPEED = 343.2

Speed of sound.

REFERENCE_TEMPERATURE module-attribute

REFERENCE_TEMPERATURE = 293.15

Reference temperature.

TRIPLE_TEMPERATURE module-attribute

TRIPLE_TEMPERATURE = 273.16

Triple point isotherm temperature.

Classes

Atmosphere

Atmosphere(
    temperature: float = REFERENCE_TEMPERATURE,
    pressure: float = REFERENCE_PRESSURE,
    relative_humidity: float = 0.0,
    reference_temperature: float = REFERENCE_TEMPERATURE,
    reference_pressure: float = REFERENCE_PRESSURE,
    triple_temperature: float = TRIPLE_TEMPERATURE,
)

Class describing atmospheric conditions.

PARAMETER DESCRIPTION
temperature

Temperature in kelvin.

TYPE: float DEFAULT: REFERENCE_TEMPERATURE

pressure

Pressure.

TYPE: float DEFAULT: REFERENCE_PRESSURE

relative_humidity

Relative humidity.

TYPE: float DEFAULT: 0.0

reference_temperature

Reference temperature.

TYPE: float DEFAULT: REFERENCE_TEMPERATURE

reference_pressure

Reference pressure.

TYPE: float DEFAULT: REFERENCE_PRESSURE

triple_temperature

Triple temperature.

TYPE: float DEFAULT: TRIPLE_TEMPERATURE

RETURNS DESCRIPTION

An instance of the Atmosphere class.

Source code in acoustic_toolbox/atmosphere.py
def __init__(
    self,
    temperature: float = REFERENCE_TEMPERATURE,
    pressure: float = REFERENCE_PRESSURE,
    relative_humidity: float = 0.0,
    reference_temperature: float = REFERENCE_TEMPERATURE,
    reference_pressure: float = REFERENCE_PRESSURE,
    triple_temperature: float = TRIPLE_TEMPERATURE,
):
    """Initialize atmosphere conditions.

    Args:
        temperature: Temperature in kelvin.
        pressure: Pressure.
        relative_humidity: Relative humidity.
        reference_temperature: Reference temperature.
        reference_pressure: Reference pressure.
        triple_temperature: Triple temperature.

    Returns:
        An instance of the Atmosphere class.
    """
    self.temperature = temperature
    """Ambient temperature $T$."""

    self.pressure = pressure
    """Ambient pressure $p_a$."""

    self.relative_humidity = relative_humidity
    """Relative humidity"""

    self.reference_temperature = reference_temperature
    """Reference temperature."""

    self.reference_pressure = reference_pressure
    """Reference pressure."""

    self.triple_temperature = triple_temperature
    """Triple temperature."""

Attributes

REF_TEMP class-attribute instance-attribute
REF_TEMP = 293.15

Reference temperature

REF_PRESSURE class-attribute instance-attribute
REF_PRESSURE = 101.325

International Standard Atmosphere in kilopascal

TRIPLE_TEMP class-attribute instance-attribute
TRIPLE_TEMP = 273.16

Triple point isotherm temperature.

temperature instance-attribute
temperature = temperature

Ambient temperature \(T\).

pressure instance-attribute
pressure = pressure

Ambient pressure \(p_a\).

relative_humidity instance-attribute
relative_humidity = relative_humidity

Relative humidity

reference_temperature instance-attribute
reference_temperature = reference_temperature

Reference temperature.

reference_pressure instance-attribute
reference_pressure = reference_pressure

Reference pressure.

triple_temperature instance-attribute
triple_temperature = triple_temperature

Triple temperature.

soundspeed property
soundspeed: float

Speed of sound \(c\).

The speed of sound is calculated using standards.iso_9613_1_1993.soundspeed.

RETURNS DESCRIPTION
float

The speed of sound.

TYPE: float

saturation_pressure property
saturation_pressure: float

Saturation pressure \(p_{sat}\).

The saturation pressure is calculated using standards.iso_9613_1_1993.saturation_pressure.

RETURNS DESCRIPTION
float

The saturation pressure.

TYPE: float

molar_concentration_water_vapour property
molar_concentration_water_vapour: float

Molar concentration of water vapour \(h\).

The molar concentration of water vapour is calculated using standards.iso_9613_1_1993.molar_concentration_water_vapour.

RETURNS DESCRIPTION
float

The molar concentration of water vapour.

TYPE: float

relaxation_frequency_nitrogen property
relaxation_frequency_nitrogen: float

Resonance frequency of nitrogen \(f_{r,N}\).

The resonance frequency is calculated using standards.iso_9613_1_1993.relaxation_frequency_nitrogen.

RETURNS DESCRIPTION
float

The resonance frequency of nitrogen.

TYPE: float

relaxation_frequency_oxygen property
relaxation_frequency_oxygen: float

Resonance frequency of oxygen \(f_{r,O}\).

The resonance frequency is calculated using standards.iso_9613_1_1993.relaxation_frequency_oxygen.

RETURNS DESCRIPTION
float

The resonance frequency of oxygen.

TYPE: float

Functions

attenuation_coefficient
attenuation_coefficient(
    frequency: float | NDArray[float64],
) -> float | NDArray[float64]

Attenuation coefficient \(\alpha\) describing atmospheric absorption in dB/m.

The attenuation coefficient is calculated using standards.iso_9613_1_1993.attenuation_coefficient.

PARAMETER DESCRIPTION
frequency

Frequencies to be considered.

TYPE: float | NDArray[float64]

RETURNS DESCRIPTION
float

The attenuation coefficient.

TYPE: float | NDArray[float64]

Source code in acoustic_toolbox/atmosphere.py
def attenuation_coefficient(
    self, frequency: float | NDArray[np.float64]
) -> float | NDArray[np.float64]:
    r"""Attenuation coefficient $\alpha$ describing atmospheric absorption in dB/m.

    The attenuation coefficient is calculated using
    [`standards.iso_9613_1_1993.attenuation_coefficient`][acoustic_toolbox.standards.iso_9613_1_1993.attenuation_coefficient].

    Args:
        frequency: Frequencies to be considered.

    Returns:
        float: The attenuation coefficient.
    """
    return attenuation_coefficient(
        self.pressure,
        self.temperature,
        self.reference_pressure,
        self.reference_temperature,
        self.relaxation_frequency_nitrogen,
        self.relaxation_frequency_oxygen,
        frequency,
    )
frequency_response
frequency_response(
    distance: float,
    frequencies: float | NDArray[float64],
    inverse: bool = False,
) -> NDArray[float64]

Calculate the frequency response.

PARAMETER DESCRIPTION
distance

Distance between source and receiver.

TYPE: float

frequencies

Frequencies for which to compute the response.

TYPE: float | NDArray[float64]

inverse

Whether the attenuation should be undone.

TYPE: bool DEFAULT: False

RETURNS DESCRIPTION
array

The frequency response.

TYPE: NDArray[float64]

Source code in acoustic_toolbox/atmosphere.py
def frequency_response(
    self,
    distance: float,
    frequencies: float | NDArray[np.float64],
    inverse: bool = False,
) -> NDArray[np.float64]:
    """Calculate the frequency response.

    Args:
        distance: Distance between source and receiver.
        frequencies: Frequencies for which to compute the response.
        inverse: Whether the attenuation should be undone.

    Returns:
        array: The frequency response.
    """
    return frequency_response(
        self,
        distance,
        frequencies,
        inverse,
    )
impulse_response
impulse_response(
    distance: float,
    fs: float,
    ntaps: int,
    inverse: bool = False,
) -> NDArray[float64]

Calculate the impulse response of sound travelling through atmosphere.

PARAMETER DESCRIPTION
distance

Distance between source and receiver.

TYPE: float

fs

Sample frequency.

TYPE: float

ntaps

Amount of taps.

TYPE: int

inverse

Whether the attenuation should be undone.

TYPE: bool DEFAULT: False

RETURNS DESCRIPTION
array

The impulse response.

TYPE: NDArray[float64]

See Also

atmosphere.impulse_response

Source code in acoustic_toolbox/atmosphere.py
def impulse_response(
    self,
    distance: float,
    fs: float,
    ntaps: int,
    inverse: bool = False,
) -> NDArray[np.float64]:
    """Calculate the impulse response of sound travelling through atmosphere.

    Args:
        distance: Distance between source and receiver.
        fs: Sample frequency.
        ntaps: Amount of taps.
        inverse: Whether the attenuation should be undone.

    Returns:
        array: The impulse response.

    See Also:
        [`atmosphere.impulse_response`][acoustic_toolbox.atmosphere.impulse_response]
    """
    return impulse_response(
        self,
        distance,
        fs,
        ntaps,
        inverse,
    )
plot_attenuation_coefficient
plot_attenuation_coefficient(
    frequency: float | NDArray[float64],
) -> Figure

Plot the attenuation coefficient \(\alpha\) as function of frequency.

PARAMETER DESCRIPTION
frequency

Frequencies.

TYPE: float | NDArray[float64]

Note

The attenuation coefficient is plotted in dB/km!

RETURNS DESCRIPTION
Figure

matplotlib.figure.Figure: The generated figure.

Source code in acoustic_toolbox/atmosphere.py
def plot_attenuation_coefficient(
    self, frequency: float | NDArray[np.float64]
) -> Figure:
    r"""Plot the attenuation coefficient $\alpha$ as function of frequency.

    Args:
        frequency: Frequencies.

    Note:
        The attenuation coefficient is plotted in dB/km!

    Returns:
        matplotlib.figure.Figure: The generated figure.
    """
    fig = plt.figure()
    ax0 = fig.add_subplot(111)
    ax0.plot(frequency, self.attenuation_coefficient(frequency) * 1000.0)
    ax0.set_xscale("log")
    ax0.set_yscale("log")
    ax0.set_xlabel(r"$f$ in Hz")
    ax0.set_ylabel(r"$\alpha$ in dB/km")
    ax0.legend()

    return fig

Functions

soundspeed

soundspeed(
    temperature: float,
    reference_temperature: float = REFERENCE_TEMPERATURE,
) -> float

Calculate speed of sound \(c\) in air.

Notes

The speed of sound is calculated using the formula: $$ c = 343.2 \left( \frac{T}{T_0} \right) $$

PARAMETER DESCRIPTION
temperature

Ambient temperature \(T_0\).

TYPE: float

reference_temperature

Reference temperature \(T\).

TYPE: float DEFAULT: REFERENCE_TEMPERATURE

RETURNS DESCRIPTION
float

Speed of sound in m/s.

TYPE: float

Source code in acoustic_toolbox/standards/iso_9613_1_1993.py
def soundspeed(
    temperature: float, reference_temperature: float = REFERENCE_TEMPERATURE
) -> float:
    r"""Calculate speed of sound $c$ in air.

    Notes:
        The speed of sound is calculated using the formula:
        $$
        c = 343.2 \left( \frac{T}{T_0} \right)
        $$

    Args:
        temperature: Ambient temperature $T_0$.
        reference_temperature: Reference temperature $T$.

    Returns:
        float: Speed of sound in m/s.
    """
    return 343.2 * np.sqrt(temperature / reference_temperature)

saturation_pressure

saturation_pressure(
    temperature: float,
    reference_pressure: float = REFERENCE_PRESSURE,
    triple_temperature: float = TRIPLE_TEMPERATURE,
) -> float

Calculate saturation vapor pressure \(p_{sat}\).

Notes

The saturation vapor pressure is calculated using the formula: $$ p_{sat} = 10^C \cdot p_r $$

with exponent \(C\) given by: $$ C = -6.8346 \cdot \left( \frac{T_{01}}{T} \right)^{1.261} + 4.6151 $$

PARAMETER DESCRIPTION
temperature

Ambient temperature \(T\).

TYPE: float

reference_pressure

Reference pressure \(p_r\).

TYPE: float DEFAULT: REFERENCE_PRESSURE

triple_temperature

Triple point temperature \(T_{01}\).

TYPE: float DEFAULT: TRIPLE_TEMPERATURE

RETURNS DESCRIPTION
float

Saturation vapor pressure

TYPE: float

Source code in acoustic_toolbox/standards/iso_9613_1_1993.py
def saturation_pressure(
    temperature: float,
    reference_pressure: float = REFERENCE_PRESSURE,
    triple_temperature: float = TRIPLE_TEMPERATURE,
) -> float:
    r"""Calculate saturation vapor pressure $p_{sat}$.

    Notes:
        The saturation vapor pressure is calculated using the formula:
        $$
        p_{sat} = 10^C \cdot p_r
        $$

        with exponent $C$ given by:
        $$
        C = -6.8346 \cdot \left( \frac{T_{01}}{T} \right)^{1.261}  + 4.6151
        $$

    Args:
        temperature: Ambient temperature $T$.
        reference_pressure: Reference pressure $p_r$.
        triple_temperature: Triple point temperature $T_{01}$.

    Returns:
        float: Saturation vapor pressure
    """
    return reference_pressure * 10.0 ** (
        -6.8346 * (triple_temperature / temperature) ** (1.261) + 4.6151
    )

molar_concentration_water_vapour

molar_concentration_water_vapour(
    relative_humidity: float,
    saturation_pressure: float,
    pressure: float,
) -> float

Calculate molar concentration of water vapour \(h\).

Notes

The molar concentration of water vapour is calculated using the formula: $$ h = h_r \frac{p_{sat}}{p_a} $$

PARAMETER DESCRIPTION
relative_humidity

Relative humidity \(h_r\)

TYPE: float

saturation_pressure

Saturation pressure \(p_{sat}\)

TYPE: float

pressure

Ambient pressure \(p_a\)

TYPE: float

RETURNS DESCRIPTION
float

Molar concentration of water vapour

TYPE: float

Source code in acoustic_toolbox/standards/iso_9613_1_1993.py
def molar_concentration_water_vapour(
    relative_humidity: float, saturation_pressure: float, pressure: float
) -> float:
    r"""Calculate molar concentration of water vapour $h$.

    Notes:
        The molar concentration of water vapour is calculated using the formula:
        $$
        h = h_r  \frac{p_{sat}}{p_a}
        $$

    Args:
        relative_humidity: Relative humidity $h_r$
        saturation_pressure: Saturation pressure $p_{sat}$
        pressure: Ambient pressure $p_a$

    Returns:
        float: Molar concentration of water vapour
    """
    return relative_humidity * saturation_pressure / pressure

relaxation_frequency_oxygen

relaxation_frequency_oxygen(
    pressure: float,
    h: float,
    reference_pressure: float = REFERENCE_PRESSURE,
) -> float

Calculate relaxation frequency of oxygen \(f_{r,O}\).

Notes

The relaxation frequency of oxygen is calculated using the formula: $$ f_{r,O} = \frac{p_a}{p_r} \left( 24 + 4.04 \cdot 10^4 h \frac{0.02 + h}{0.391 + h} \right) $$

PARAMETER DESCRIPTION
pressure

Ambient pressure \(p_a\)

TYPE: float

h

Molar concentration of water vapour \(h\)

TYPE: float

reference_pressure

Reference pressure \(p_r\).

TYPE: float DEFAULT: REFERENCE_PRESSURE

RETURNS DESCRIPTION
float

Relaxation frequency of oxygen in Hz

TYPE: float

See Also

molar_concentration_water_vapour: Function to calculate molar concentration of water vapour

Source code in acoustic_toolbox/standards/iso_9613_1_1993.py
def relaxation_frequency_oxygen(
    pressure: float, h: float, reference_pressure: float = REFERENCE_PRESSURE
) -> float:
    r"""Calculate relaxation frequency of oxygen $f_{r,O}$.

    Notes:
        The relaxation frequency of oxygen is calculated using the formula:
        $$
        f_{r,O} = \frac{p_a}{p_r} \left( 24 + 4.04 \cdot 10^4 h \frac{0.02 + h}{0.391 + h}  \right)
        $$

    Args:
        pressure: Ambient pressure $p_a$
        h: Molar concentration of water vapour $h$
        reference_pressure: Reference pressure $p_r$.

    Returns:
        float: Relaxation frequency of oxygen in Hz

    See Also:
        [molar_concentration_water_vapour][acoustic_toolbox.standards.iso_9613_1_1993.molar_concentration_water_vapour]: Function to calculate molar concentration of water vapour
    """
    return (
        pressure
        / reference_pressure
        * (24.0 + 4.04 * 10.0**4.0 * h * (0.02 + h) / (0.391 + h))
    )

relaxation_frequency_nitrogen

relaxation_frequency_nitrogen(
    pressure: float,
    temperature: float,
    h: float,
    reference_pressure: float = REFERENCE_PRESSURE,
    reference_temperature: float = REFERENCE_TEMPERATURE,
) -> float

Calculate relaxation frequency of nitrogen \(f_{r,N}\).

Notes

The relaxation frequency of nitrogen is calculated by: $$ f_{r,N} = \frac{p_a}{p_r} \left( \frac{T}{T_0} \right)^{-½} \cdot \left( 9 + 280 \cdot h \cdot \exp \left( -4.170 \left[ \left(\frac{T}{T_0} \right)^{-⅓} -1 \right] \right) \right) $$

PARAMETER DESCRIPTION
pressure

Ambient pressure \(p_a\)

TYPE: float

temperature

Ambient temperature \(T\)

TYPE: float

h

Molar concentration of water vapour \(h\)

TYPE: float

reference_pressure

Reference pressure \(p_{ref}\).

TYPE: float DEFAULT: REFERENCE_PRESSURE

reference_temperature

Reference temperature \(T_{ref}\).

TYPE: float DEFAULT: REFERENCE_TEMPERATURE

RETURNS DESCRIPTION
float

Relaxation frequency of nitrogen in Hz

TYPE: float

Source code in acoustic_toolbox/standards/iso_9613_1_1993.py
def relaxation_frequency_nitrogen(
    pressure: float,
    temperature: float,
    h: float,
    reference_pressure: float = REFERENCE_PRESSURE,
    reference_temperature: float = REFERENCE_TEMPERATURE,
) -> float:
    r"""Calculate relaxation frequency of nitrogen $f_{r,N}$.

    Notes:
        The relaxation frequency of nitrogen is calculated by:
        $$
        f_{r,N} = \frac{p_a}{p_r} \left( \frac{T}{T_0} \right)^{-1/2} \cdot \left( 9 + 280 \cdot h \cdot \exp \left( -4.170 \left[ \left(\frac{T}{T_0} \right)^{-1/3} -1 \right] \right) \right)
        $$

    Args:
        pressure: Ambient pressure $p_a$
        temperature: Ambient temperature $T$
        h: Molar concentration of water vapour $h$
        reference_pressure: Reference pressure $p_{ref}$.
        reference_temperature: Reference temperature $T_{ref}$.

    Returns:
        float: Relaxation frequency of nitrogen in Hz
    """
    return (
        pressure
        / reference_pressure
        * (temperature / reference_temperature) ** (-0.5)
        * (
            9.0
            + 280.0
            * h
            * np.exp(
                -4.170 * ((temperature / reference_temperature) ** (-1.0 / 3.0) - 1.0)
            )
        )
    )

attenuation_coefficient

attenuation_coefficient(
    pressure: float,
    temperature: float,
    reference_pressure: float,
    reference_temperature: float,
    relaxation_frequency_nitrogen: float,
    relaxation_frequency_oxygen: float,
    frequency: float | NDArray[float64],
) -> float | NDArray[float64]

Calculate attenuation coefficient \(\alpha\) describing atmospheric absorption in dB/m for the specified frequency.

PARAMETER DESCRIPTION
pressure

Ambient pressure \(p_a\)

TYPE: float

temperature

Ambient temperature \(T\)

TYPE: float

reference_pressure

Reference pressure \(p_{ref}\)

TYPE: float

reference_temperature

Reference temperature \(T_{ref}\)

TYPE: float

relaxation_frequency_nitrogen

Relaxation frequency of nitrogen \(f_{r,N}\)

TYPE: float

relaxation_frequency_oxygen

Relaxation frequency of oxygen \(f_{r,O}\)

TYPE: float

frequency

Frequencies \(f\) to calculate \(\alpha\) for

TYPE: float | NDArray[float64]

RETURNS DESCRIPTION
float | NDArray[float64]

float | NDArray[np.float64]: Attenuation coefficient in dB/m

Source code in acoustic_toolbox/standards/iso_9613_1_1993.py
def attenuation_coefficient(
    pressure: float,
    temperature: float,
    reference_pressure: float,
    reference_temperature: float,
    relaxation_frequency_nitrogen: float,
    relaxation_frequency_oxygen: float,
    frequency: float | NDArray[np.float64],
) -> float | NDArray[np.float64]:
    r"""Calculate attenuation coefficient $\alpha$ describing atmospheric absorption in dB/m for the specified ``frequency``.

    Args:
        pressure: Ambient pressure $p_a$
        temperature: Ambient temperature $T$
        reference_pressure: Reference pressure $p_{ref}$
        reference_temperature: Reference temperature $T_{ref}$
        relaxation_frequency_nitrogen: Relaxation frequency of nitrogen $f_{r,N}$
        relaxation_frequency_oxygen: Relaxation frequency of oxygen $f_{r,O}$
        frequency: Frequencies $f$ to calculate $\alpha$ for

    Returns:
        float | NDArray[np.float64]: Attenuation coefficient in dB/m
    """
    return (
        8.686
        * frequency**2.0
        * (
            (
                1.84
                * 10.0 ** (-11.0)
                * (reference_pressure / pressure)
                * (temperature / reference_temperature) ** (0.5)
            )
            + (temperature / reference_temperature) ** (-2.5)
            * (
                0.01275
                * np.exp(-2239.1 / temperature)
                * (
                    relaxation_frequency_oxygen
                    + (frequency**2.0 / relaxation_frequency_oxygen)
                )
                ** (-1.0)
                + 0.1068
                * np.exp(-3352.0 / temperature)
                * (
                    relaxation_frequency_nitrogen
                    + (frequency**2.0 / relaxation_frequency_nitrogen)
                )
                ** (-1.0)
            )
        )
    )

frequency_response

frequency_response(
    atmosphere: Atmosphere,
    distance: float,
    frequencies: float | NDArray[float64],
    inverse: bool = False,
) -> NDArray[float64]

Calculate the single-sided frequency response.

PARAMETER DESCRIPTION
atmosphere

Atmosphere instance.

TYPE: Atmosphere

distance

Distance between source and receiver.

TYPE: float

frequencies

Frequencies for which to compute the response.

TYPE: float | NDArray[float64]

inverse

Whether the attenuation should be undone.

TYPE: bool DEFAULT: False

RETURNS DESCRIPTION
array

The frequency response.

TYPE: NDArray[float64]

Source code in acoustic_toolbox/atmosphere.py
def frequency_response(
    atmosphere: Atmosphere,
    distance: float,
    frequencies: float | NDArray[np.float64],
    inverse: bool = False,
) -> NDArray[np.float64]:
    """Calculate the single-sided frequency response.

    Args:
        atmosphere: Atmosphere instance.
        distance: Distance between source and receiver.
        frequencies: Frequencies for which to compute the response.
        inverse: Whether the attenuation should be undone.

    Returns:
        array: The frequency response.
    """
    sign = +1 if inverse else -1
    tf = 10.0 ** (
        float(sign) * distance * atmosphere.attenuation_coefficient(frequencies) / 20.0
    )
    return tf

impulse_response

impulse_response(
    atmosphere: Atmosphere,
    distance: float,
    fs: float,
    ntaps: int,
    inverse: bool = False,
) -> NDArray[float64]

Calculate the impulse response of sound travelling through atmosphere for a given distance sampled at fs.

The attenuation is calculated for a set of positive frequencies. Because the attenuation is the same for the negative frequencies, we have Hermitian symmetry. The attenuation is entirely real-valued. We like to have a constant group delay and therefore we need a linear-phase filter.

This function creates a zero-phase filter, which is the special case of a linear-phase filter with zero phase slope. The type of filter is non-causal. The impulse response of the filter is made causal by rotating it by M/2 samples and discarding the imaginary parts. A real, even impulse response corresponds to a real, even frequency response.

PARAMETER DESCRIPTION
atmosphere

Atmosphere instance.

TYPE: Atmosphere

distance

Distance between source and receiver.

TYPE: float

fs

Sample frequency.

TYPE: float

ntaps

Amount of taps.

TYPE: int

inverse

Whether the attenuation should be undone.

TYPE: bool DEFAULT: False

RETURNS DESCRIPTION
array

The impulse response.

TYPE: NDArray[float64]

Source code in acoustic_toolbox/atmosphere.py
def impulse_response(
    atmosphere: Atmosphere,
    distance: float,
    fs: float,
    ntaps: int,
    inverse: bool = False,
) -> NDArray[np.float64]:
    """Calculate the impulse response of sound travelling through `atmosphere` for a given `distance` sampled at `fs`.

    The attenuation is calculated for a set of positive frequencies. Because the
    attenuation is the same for the negative frequencies, we have Hermitian
    symmetry. The attenuation is entirely real-valued. We like to have a constant
    group delay and therefore we need a linear-phase filter.

    This function creates a zero-phase filter, which is the special case of a
    linear-phase filter with zero phase slope. The type of filter is non-causal. The
    impulse response of the filter is made causal by rotating it by M/2 samples and
    discarding the imaginary parts. A real, even impulse response corresponds to a
    real, even frequency response.

    Args:
        atmosphere: Atmosphere instance.
        distance: Distance between source and receiver.
        fs: Sample frequency.
        ntaps: Amount of taps.
        inverse: Whether the attenuation should be undone.

    Returns:
        array: The impulse response.
    """
    # Frequencies vector with positive frequencies only.
    frequencies = np.fft.rfftfreq(ntaps, 1.0 / fs)
    # Single-sided spectrum. Negative frequencies have the same values.
    tf = frequency_response(atmosphere, distance, frequencies, inverse)
    # Impulse response. We design a zero-phase filter (linear-phase with zero slope).
    # We need to shift the IR to make it even. Taking the real part should not be necessary, see above.
    # ir = np.fft.ifftshift(np.fft.irfft(tf, n=ntaps)).real
    ir = acoustic_toolbox.signal.impulse_response_real_even(tf, ntaps=ntaps)
    return ir

:::