# Signal to noise ratio for time series audio data

I am writing some software to benchmark an audio noise filtering method using SNR as an evaluation metric. One software component generates noisey audio by taking a clean audio file and a noise source file and simply adding the components. The clean file is usually longer, so the noise source is looped and/or padded to fill out all the samples.

I then pass this through my noise filter, getting a less noisey signal at the output.

How can I calculate SNR from the resultant data? My current method is to compute the RMS for the cleaned up signal and divide by RMS of the noise source giving the average power ratio. Is this the correct method?

Code is provided below:

float SignalCleaner::ComputeRMS(AudioFile<float> signal){
float total_square = 0.0f;
float n = (float) signal.getNumSamplesPerChannel() * (float) signal.getNumChannels();
for(int channel_idx = 0; channel_idx < signal.getNumChannels(); channel_idx++){
for(int sample_idx = 0; sample_idx < signal.getNumSamplesPerChannel(); sample_idx++){
total_square += std::pow(signal.samples[channel_idx][sample_idx], 2);
}
}

return std::sqrt(total_square / n);
}

float SignalCleaner::ComputeSNR(AudioFile<float> signal, AudioFile<float> noise){
float signal_rms = ComputeRMS(signal);
float noise_rms = ComputeRMS(noise);
return 20 * std::log(signal_rms/noise_rms);

}

float SignalCleaner::SNRPreFiltered() {
return ComputeSNR(noisey_signal, noise_source);
}

float SignalCleaner::SNRPostFiltered() {
return ComputeSNR(output, noise_source);
}



Thanks, happy to provide further clarification

• well, if you have the original noise-less audio, why don't you just subtract it from the output? Mar 17, 2022 at 18:44
• @MarcusMüller: I second that. Care should be taken to time-align the filtered signal with the original one.
– Max
Mar 18, 2022 at 11:12
• Point taken, I will work on time-alignment next. However, for my own understanding, is there any reason my current method does not give an estimate for SNR? Mar 18, 2022 at 12:30