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:
t = 0:1/fs:duration-1/fs;
- 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:
amplitudes = [1 0.5 0.3];
for i = 1:length(harmonics)
harmonic = harmonics(i) * fundamental;
amplitude = amplitudes(i);
signal = signal + amplitude * sin(2 * pi * harmonic * t);
- 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: