-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathaddnoise_nonstationary.m
More file actions
30 lines (22 loc) · 889 Bytes
/
addnoise_nonstationary.m
File metadata and controls
30 lines (22 loc) · 889 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
function corrupted = addnoise_nonstationary(clean,SNR,noise)
%corrupted = addnoise_nonstationary(clean,SNR,noise);
% picks a random start point in 'noise' the same length as 'clean', generates
% a corrupted file with snr 'SNR'.
NL = length(noise);
NS = length(clean);
% ensure random seed
rand('twister',sum(100*clock));
start_point = floor((NL-NS)*rand(1));
noise_realisation = noise(start_point:(start_point+NS-1));
% ensure the mean is zero
noise_realisation = noise_realisation - mean(noise_realisation);
clean = clean - mean(clean);
% ensure the standard deviation is unity
noise_realisation = noise_realisation/std(noise_realisation);
% determine the power of the speech signal
pow = sum(clean.^2)/NS ;
% determine the noise power required to attain desired snr
ratio = 10^(SNR/10) ;
sd = sqrt(pow/ratio) ;
% add noise to speech
corrupted = clean + (sd*noise_realisation) ;