clarity.utils.car_noise_simulator package¶
Submodules¶
clarity.utils.car_noise_simulator.carnoise_parameters_generator module¶
Class to generate random parameters for the Car noise signal generation
These are 2 separated class to keep the logic separated
- class clarity.utils.car_noise_simulator.carnoise_parameters_generator.CarNoiseParametersGenerator(primary_filter_cutoff: float = 0.14, primary_filter_constant_hz: float = 2.86, secondary_filter_cutoff: float = 0.8, secondary_filter_constant_hz: float = 200, random_flag: bool = True, random_seed: int | None = None)[source]¶
Bases:
object
A class to generate noise parameters for a car. The constructor takes a boolean flag to indicate whether some parameters should be randomized or not.
The method gen_parameters takes a speed in kilometers per hour and returns a dictionary of noise parameters.
The global variables GEAR_LOOKUP and RPM_LOOKUP are used to determine the gear and RPM for a given speed.
Example
>>> car_noise_parameters = CarNoiseParameters(random_flag=True) >>> parameters = car_noise_parameters.gen_parameters(speed_kph=100) >>> parameters { "speed": 70, "gear": 4, "rpm": 1890.0, "primary_filter": { "order": 1, "btype": "lowpass", "cutoff_hz": 12.685320000000003, }, "secondary_filter": { "order": 2, "btype": "lowpass", "cutoff_hz": 276.22400000000005, }, "bump": {"order": 1, "btype": "bandpass", "cutoff_hz": [34, 66.64000000000001]}, "dip_low": {"order": 1, "btype": "lowpass", "cutoff_hz": 90}, "dip_high": {"order": 1, "btype": "highpass", "cutoff_hz": 220.12494775682322},
}
- GEAR_LOOKUP: Final = {50: [3], 60: [4], 75: [4, 5], 85: [5], 100: [5, 6], 110: [6]}¶
- REFERENCE_CONSTANT_DB: Final = 30¶
- RPM_LOOKUP: Final = {3: 0.6, 4: 0.45, 5: 0.34, 6: 0.28}¶
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)