I have an audio file consisted of a sole 440 Hz sinusoidal wave, which can be heard here.

After some manipulation, I've added a noise to it, resulting in a second audio file, avilable here.

The noise is pretty noticeable with the human ear (especially when using earphones), so I wanted to visually evidence this noise as well, for a printed document.

To achieve this, I tried plotting the FFT and the Mel Spectrogram of both audios, using the Python code below:

import librosa
import matplotlib.pyplot as plt
import numpy as np
from scipy.fftpack import fft

def mel_spectrogram(audio, sample_rate, name):
    mel_spectrogram = librosa.feature.melspectrogram(y=audio, sr=sample_rate)
    librosa.display.specshow(librosa.power_to_db(mel_spectrogram,ref=np.max), sr=sample_rate, hop_length=512, y_axis='mel',x_axis='time')
    plt.colorbar(format='%+2.0f dB')
    plt.xlabel("Time [s]")
    plt.ylabel("Frequency [Hz]")
    plt.savefig('../charts/melspectrogram_' + name + '.png')

def fft_plot(audio, sample_rate, name):
  N = len(audio)    # Number of samples
  T = 1/sample_rate # Period
  y_freq = fft(audio)
  domain = len(y_freq) // 2
  x_freq = np.linspace(0, sample_rate//2, N//2)
  plt.plot(x_freq, abs(y_freq[:domain]))
  plt.xlabel("Frequency [Hz]")
  plt.ylabel("Amplitude |X(t)|")
  plt.savefig('../charts/fft_' + name + '.png')

FILENAMES = ['440Hz.wav','440Hz_noise.wav']

for filename in FILENAMES:
    signal, sample_rate = librosa.load('../arquivos/' + filename)
    fft_plot(signal, sample_rate, filename)
    mel_spectrogram(signal, sample_rate, filename)

This code results in the figures shown below, where a) and c) are of the noisy audio; and b) and d) are of the clear audio file.

As there is no significant differences in these plots, I imagine these are not the adequate tools to visually evidence the added noise. How could I make it noticeable that my treatment on the audio added a noise?

enter image description here

  • $\begingroup$ Welcome to SE.SP! I can't hear any difference between your two MP3 files. What should I be hearing? $\endgroup$
    – Peter K.
    Dec 10, 2023 at 14:42
  • $\begingroup$ If you do phase cancellation (cancel the original from noised signal) your resulting signal has quite low level (audacity shows below -48dB) . So, if you change plot scales a bit you might see some differences. $\endgroup$
    – Juha P
    Dec 10, 2023 at 14:51
  • $\begingroup$ @PeterK. There is a static noise throughout the second audio file. Indeed, I can only hear it with an earphone on. I should correct that in the original post $\endgroup$
    – JohnCalms
    Dec 10, 2023 at 15:12
  • 1
    $\begingroup$ I'd like to add that we're comparing quantized audio – MP3 to be precise, which will gladly mask any audible differences -48 dB below a tone. So, John, please put something losslessly compressed somewhere – FLAC, for example. It's possible that you observed more difference than we are able to observe, because by design, MP3 would suppress that noise. $\endgroup$ Dec 10, 2023 at 18:57
  • 1
    $\begingroup$ That may be the case @MarcusMüller. Thank you for noting that. I am in fact using wav format, but it seems that the website I used for uploading the files automatically converted them to mp3. However, I have followed Juha's recommendation of phase cancellation and achieved my goals. I appreciate everyone's efforts! $\endgroup$
    – JohnCalms
    Dec 10, 2023 at 19:20

2 Answers 2


How could I make it noticeable that my treatment on the audio added a noise?

Spectral analysis will do the trick, if you do it correctly. Here is an example of using Welch's method power spectral density estimator at an FFT length of $N_{FFT} = 16384$ normalized to 0dB at the peak frequency.

enter image description here

There are a few things we can take from this picture.

  1. The "clean" sine wave isn't all that clean. Most of that is done by the MP3 encoder which uses masking thresholds for different frequency band. That's the dominating noise source at low frequencies (the noise is masked by the tone).
  2. There is also quite a bit of widening of the main lobe which is due to the masking thresholds on the adjacent bands.
  3. The added noise appears to be white. At low frequencies it's masked by the MP3 encoder noise, but above the main peak it's clearly visible
  4. We can also see that the Encoder has a hard stop at 16 kHz.

The more tricky part would be to deduce the noise level. I looks like the noise floor is at -60dB, but that's NOT the case. For this type of spectral analysis the "visible" SNR is a function of the FFT size. If you double the FFT size, the amplitude of the peak will increase by 6dB whereas the noise floor will increase only by 3dB.

The reason why your pictures are not showing this is probably because your FFT size is way too long. All the noise energy is spread out over half a million frequency bins where as the sine wave is just in a single bin.

If you want the actual SNR it's easy enough to calculate it directly in the time domain.

$$ SNR = 10\cdot \log_{10} \frac{<(x_{noisy}-x_{clean})^2>}{<(x_{clean})^2>} $$


I can't see or hear any difference between the two MP3 files.

If I load both up into matlab and plot the first 10,000 points, they are identical.

Exactly the same plots from both MP3 files.


sine = audioread("sine.mp3");
sine_noisy = audioread("sine_noisy.mp3");

error = sine-sine_noisy;


I get


decibels as a noise-to-signal ratio... which is relatively clean.

Following @Juha P's advice, I've plotted the spectrum of the error:

Spectrum of the error.

It does looked shaped (flat for much of the frequency range).

  • $\begingroup$ Audacity shows (after inverting the original track and mixing the tracks) : postimg.cc/TLyXX92L $\endgroup$
    – Juha P
    Dec 10, 2023 at 15:31
  • $\begingroup$ @JuhaP Thanks! Yes, there is something there, but it's quite low down. My hearing isn't the best and even with headset I couldn't tell the difference. :-) $\endgroup$
    – Peter K.
    Dec 10, 2023 at 22:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.