clarity.utils.car_noise_simulator.carnoise_signal_generator module

Class to generate the car noise signal.

class clarity.utils.car_noise_simulator.carnoise_signal_generator.CarNoiseSignalGenerator(sample_rate: int, duration_secs: float, random_flag: bool = True)[source]

Bases: object

A class to generate car noise signal.

The constructor takes the sample_rate and duration of the generated signals.

The method generate_car_noise takes parameters for the noise and generates the signal. These parameters can be generated by the CarNoiseParameters class.

Example

>>> car_noise_parameters = CarNoiseParameters(random_flag=True)
>>> parameters = car_noise_parameters.gen_parameters(speed_kph=100)
>>> car_noise = CarNoiseGenerator(sample_rate=44100, duration_secs=5,
        random_flag=True)
>>> car_noise_signal = car_noise.generate_car_noise(parameters, 3, 0.5)
FINAl_MULTIPLIER: Final = 0.0005
REFERENCE_CONSTANT_DB: Final = 30
static apply_commonness(target_signal: ndarray, coherence_signal: ndarray, commonness_factor: float) ndarray[source]

Function to apply correlation between the target signal using the coherence signal.

Parameters:
  • target_signal (np.ndarray) – Target signal

  • coherence_signal (np.ndarray) – Coherence signal

  • commonness_factor (float) – Commonness factor

Returns:

Target signal with the coherence signal

Return type:

target_signal (np.ndarray)

generate_car_noise(noise_parameters: dict, number_noise_sources: int, commonness_factor: float) ndarray[source]

Method that generates the car noise signal. It organizes the parameters and calls the methods to generate the independent parts.

Parameters:
  • noise_parameters (dict) – Dictionary with the parameters for the noise as generated by the CarNoiseParameters class.

  • number_noise_sources (int) – Number of noise sources. First source is the engine noise. Following sources are other noise sources.

  • commonness_factor (float) – Commonness factor

Returns:

Car noise signal

Return type:

np.ndarray

generate_engine_noise(speed: float, rpm: float, reference_level_db: float, engine_num_harmonics: int, primary_filter: dict[str, ndarray], secondary_filter: dict[str, ndarray]) ndarray[source]

Method that generates the noise of the engine. :param speed: Speed of the car in km/h :type speed: float :param rpm: RPM of the engine :type rpm: float :param reference_level_db: Reference level in dB :type reference_level_db: float :param engine_num_harmonics: Number of harmonics of the engine :type engine_num_harmonics: int :param primary_filter: Primary filter :type primary_filter: Dict[str, np.ndarray] :param secondary_filter: Secondary filter :type secondary_filter: Dict[str, np.ndarray]

Returns:

Noise of the engine

Return type:

np.ndarray

generate_source_noise(reference_level_db: float, primary_filter: dict[str, ndarray], secondary_filter: dict[str, ndarray], bump_filter: dict[str, ndarray], dip_low_filter: dict[str, ndarray], dip_high_filter: dict[str, ndarray]) ndarray[source]

Method that generates the noise of a single source.

Parameters:
  • reference_level_db (float) – Reference level in dB

  • primary_filter (Dict[str, np.ndarray]) – Primary filter

  • secondary_filter (Dict[str, np.ndarray]) – Secondary filter

  • bump_filter (Dict[str, np.ndarray]) – Bump filter

  • dip_low_filter (Dict[str, np.ndarray]) – Low dip filter

  • dip_high_filter (Dict[str, np.ndarray]) – High dip filter

Returns:

Noise of a single source

Return type:

np.ndarray

get_bump_params(reference_level_db: float) tuple[float, float][source]

Method that gets the parameters of the bump noise :param reference_level_db: Reference level in dB :type reference_level_db: float

Returns:

Standard deviation of the low pass noise bump_gaussian_std (float): Standard deviation of the bump noise

Return type:

lowpass_noise_gaussian_std (float)

get_engine_params(speed: float, rpm: float, reference_level_db: float, engine_num_harmonics: int) tuple[ndarray, ndarray][source]

Method that gets the parameters of the engine noise

Parameters:
  • speed (float) – Speed of the car in km/h

  • rpm (float) – RPM of the engine

  • reference_level_db (float) – Reference level in dB

  • engine_num_harmonics (int) – Number of harmonics of the engine

Returns:

Frequency of the harmonic complex harmoniccomplex_ntones (int): Number of tones of the harmonic complex harmoniccomplex_power_db (np.ndarray): Power of the harmonic complex

Return type:

harmoniccomplex_freqs_hz (np.ndarray)