I am using this as my reference: https://www.mathworks.com/help/deeplearning/ug/denoise-speech-using-deep-learning-networks.html
Add washing machine noise to the speech signal. Set the noise power such that the signal-to-noise ratio (SNR) is zero dB.
noise = audioread("WashingMachine-16-8-mono-1000secs.mp3");
% Extract a noise segment from a random location in the noise file ind = randi(numel(noise) - numel(cleanAudio) + 1,1,1); noiseSegment = noise(ind:ind + numel(cleanAudio) - 1);
speechPower = sum(cleanAudio.^2); noisePower = sum(noiseSegment.^2); noisyAudio = cleanAudio + sqrt(speechPower/noisePower)*noiseSegment;
If I understand the method correctly, assuming both the signal and noise values are within range +/-1.0, it should not really matter what the average level of the signal and noise are. The combined signal will have SNR of 0 dB. I want to construct an audio file that contains sine tone as the signal and some recorded noise wav file as the noise. This is an outline of how I am doing it so far (in matlab):
clear; clc; close all
Fs = 48000;
td = 5; % seconds
ns = td * Fs;
T = 1/Fs;
F = 1000; % sine wave frequency
t = (0:ns -1)*T;
Amp = 0.05;
signal = Amp * sin(2*pi*F*t);
signal = signal'; % match array dimension with noise file
[noise_file, Fs] = audioread('noisy.wav');
speechPower = sum(signal.^2);
noisePower = sum(noise_file.^2);
x_snr = 251.1886; % multiplier = 10^(desired_snr/10), eg: 10^(24/10) = 251.1886
noisyAudio_xdB = signal + sqrt(speechPower/(x_snr * noisePower) ).*noise_file;
audiowrite('noisy_file.wav', noisyAudio_20dB_2ch, Fs);
- Is my thinking correct so far? Will this give me an audio file with 24 dB SNR?
- Is matlab's
R = snr(X, Fs, N)
function a good way to verify this? According to matlab help,
R = snr(X, Fs, N) computes the signal to noise ratio (snr) in dBc, of the real sinusoidal input signal, X, with sampling rate, Fs, and number of harmonics, N, to exclude from computation when computing snr. The default value of Fs is 1. The default value of N is 6 and includes the fundamental frequency.
For 0 dB and 10 dB SNR files that I created, this function gave me SNR values of -0.3111 and 9.7008 respectively which are close, but since these are calculation generated noise files I was hoping the SNR would be even closer than this. Is this an acceptable margin of error for this snr function?
- Is the way I calculated the multiplier above [
multiplier = 10^(desired_snr/10)
] correct? I think this is the correct way since I am calculating SNR using power (or maybe more correctly, energy) of the digital audio signals [sum(signal.^2);
] but I just want to make sure its not multiplier = 10^(desired_snr/20).