フィルターのクリア

Add harmonic signals to White noise

5 ビュー (過去 30 日間)
Vladislav
Vladislav 2013 年 9 月 13 日
編集済み: Samya 2023 年 7 月 6 日
How can I add harmonics to white gaussian noise and listen to the sound?

回答 (1 件)

Samya
Samya 2023 年 7 月 6 日
編集済み: Samya 2023 年 7 月 6 日
Hi! To add harmonics to white Gaussian noise and listen to the resulting sound in MATLAB, you can follow these steps:
  • Generate white Gaussian noise using the randn function in MATLAB. You can specify the length of the noise signal and its variance (amplitude) as parameters. For example, to generate a 1-second noise signal with zero mean and unit variance, you can use:
fs = 44100; % Sampling frequency (Hz)
duration = 1; % Duration of the noise signal (seconds)
t = 0:1/fs:duration-1/fs; % Time vector
noise = randn(size(t));
  • Generate the harmonics by adding sinusoidal waves to the noise signal. You can specify the frequency and amplitude of each harmonic. For example, to add a 440 Hz fundamental frequency and its first three harmonics (880 Hz, 1320 Hz, and 1760 Hz) to the noise signal, you can use:
fundamental = 440; % Fundamental frequency (Hz)
harmonics = [1 2 3]; % Harmonic numbers
amplitudes = [1 0.5 0.3]; % Amplitudes of the harmonics
signal = noise; % Initialize the signal with the noise
for i = 1:length(harmonics)
harmonic = harmonics(i) * fundamental;
amplitude = amplitudes(i);
signal = signal + amplitude * sin(2 * pi * harmonic * t);
end
  • Normalize the signal to ensure that its amplitude falls within the range [-1, 1]. This step is necessary to prevent clipping and distortion when playing the sound. You can use the max function to find the maximum absolute value of the signal and divide the signal by this value. For example:
signal = signal / max(abs(signal));
  • Play the resulting sound using the sound function in MATLAB. Specify the sampling frequency (fs) and the signal (signal) as parameters. For example:
sound(signal, fs);

カテゴリ

Help Center および File ExchangeSpectral Measurements についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by