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 CenterFile Exchange 中查找有关 Audio I/O and Waveform Generation 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by