# Adding two audio files at a predefined SNR level

I have two speech audio wav files. file1 is primary speech, file2 is supposed to be interference.

I want to add them so that the SIR (signal to interference ratio) is 10 dB.

• How do I proceed?
• Do I do sample by sample addition like below?

Assuming $N$ is the data-length of both the files (single channel).

for i = 1:N
x = 0.1 * file1(i)^2 / file2(i)^2
file3(i) = file1(i) + x*file2(i)
end

file3 is the output file.

• Are there any better ways to do this?

Note: $\textrm{SIR(in dB) = 10 log (Power(signal) / Power(interference))}$

• better first confirm what the different energies are of the two files. – robert bristow-johnson Mar 29 '16 at 3:32
• @robertbristow-johnson In one case they're about the same, -80 and -78 (I used this one liner to compute average energy 10*log(sum(data.^2)/length(data)) – user13107 Mar 29 '16 at 3:45
• well, assuming the interference file is the -80 dB file, then i would scale the interference file by $10^{-(10-2)/20}$ and add it to the signal file. if the interference file is the -78 dB file, i would add 2 to the 10 rather than subtract. – robert bristow-johnson Mar 29 '16 at 4:12
• This might be useful, sen is signal and noise is interference signal_power = (1/length(sen))*sum(sen.*sen); noise_variance = signal_power / ( 10^(SNR/10) ); Y = sen + sqrt(noise_variance)/std(noise)*noise(1:length(sen)); – arpit jain Mar 29 '16 at 4:17
• @robertbristow-johnson that works. thanks. my original approach was giving scratchy sound. – user13107 Mar 29 '16 at 7:41