Matlab: if given nothing but an audio file, how do I modify it to produce incrementally lower signal to noise ratios? I have an audio file with a high sampling rate of 250khz. It contains animal noises. I've built a program which counts all the animal noises.

However, I want to find out how robust the program is and find what the minimum signal to noise is for the program to still work.

Hence the plan was to modify my audio file to produce different (incrementally lower) signal to noise ratios.

I would run the program for all of them and since I know how many the program should count, when I start getting lower counts, I will what the minimum signal to noise ratio is.

however I have no idea how to go about doing this. I still don't even know how to find the signal to noise of my audio as it is. my guess was to assume the background noise is similar throughout and hence, copy a section of the audio which has no animal calls, just noise, then use matlabs snr command:

r=snr(audio,backgroundnoise);

can anyone help with how to program this?

It is not enough to just randomly add noise, I need to know the actual signal to noise values in order to be able to quantify the minimum SNR needed for the program to still work
I like your noise model, I think that is really the best way to find SNR if you only have access to recordings. Using this same model couldn't you take your backgroundnoise scale it (duplicate it or trim it as necessary) and then add it to the signal? In this sense the noise wouldn't be entirely random but somewhat system specific

edit

in order to calculate your new noise value you would simply rearrange the SNR calculation solving for noise. Then scale the original noise accordingly. you can use some code like this 

desired_snr_db = 10;    %change this value

est_signal = audio - backgroundnoise;

%the original matlab equation for SNR is: 
%signalPow = rssq(x(:)).^2; 
%noisePow = rssq(y(:)).^2; 
%r = 10 * log10(signalPow / noisePow);
%solving for noisePow we get
noisePow = rssq(est_signal(:)).^2 / (10^(desired_snr_db / 10));

%assuming rssq(new_noise).^2 = (scale_factor * rssq(old)).^2
scale_factor = sqrt(noisePow / rssq(backgroundnoise).^2);

new_noise = scale_factor * backgroundnoise;

%add noise to our estimated signal
new_signal = est_signal + new_noise; %you may need to do stretching 
                                     %trimming to get the right sizes


new_snr = snr(new_signal - new_noise, new_noise)


if you want you can double check the snr by finding a lull in the new signal and comparing it to the known sounds just as before