Add harmonic signals to White noise

5 views (last 30 days)
Vladislav
Vladislav on 13 Sep 2013
Edited: Samya on 6 Jul 2023
How can I add harmonics to white gaussian noise and listen to the sound?

Answers (1)

Samya
Samya on 6 Jul 2023
Edited: Samya on 6 Jul 2023
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);

Categories

Find more on Audio I/O and Waveform Generation in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!