dynamic parameter based on character of amplitude wav file matlab

1 view (last 30 days)
i have implemented noise gate to make noise(that's not include speech) in speech wav file to become silence, but there are five parameters(sended by main program) that i must fill the parameters by my self. i have question, how can my program give suggest parameters every i input the speech wav file with different character of noise? what i'm thinking: can i use the average of speech wav file amplitudes to get suggest parameters?
function n = noisegate( x, Fs, AT, RT, holdtime, ltrhold, utrhold)
% ------- Parameter Input ---------
% x - Input file
% Fs - sample frequency
% AT - Attack time
% RT - Release time
% ltrhold - lower threshold
% utrhold - upper threshold
att = round(AT*Fs); %calculate attack time in samples
rel = round(RT*Fs); %calculate release time in samples
ht = round(holdtime*Fs); %calculate hold time in samples
g = zeros(size(x)); %allocate an array for gain
%initialize low and high threshold counters
ltcnt = 0;
utcnt = 0;
%Calculate RMS Peak
%time average for peak measurement
tav = 0.2;
TAV =1 - exp(-2.2/(Fs*tav));
xrms(1) = 0;
for n = 2 : length(x)
xrms(n) = (1-TAV)*xrms(n-1) + TAV*x(n)^2;
if (xrms(n) <= ltrhold || (xrms(n) < utrhold && ltcnt > 0))
ltcnt = ltcnt + 1;
utcnt = 0;
if (ltcnt > ht), %hold time of low threshold exceeded
if(ltcnt > (ht + rel)) %hold and release time exceeded
%set gain to zero to completely fade out the sound
g(n) = 0;
else
%fade out the sound here
g(n) = 1 - (ltcnt - ht)/rel;
end
elseif (ltcnt < ht & (ltcnt == n))
g(n) = 0;
else
g(n) = 1;
end
elseif (xrms(n) > utrhold || (xrms(n) > ltrhold && utcnt > 0))
ltcnt = 0;
utcnt = utcnt + 1;
if(utcnt > ht)
%maximum attack and hold time exceeded
if(utcnt > (ht + att))
%set gain to 1
g(n) = 1;
else
%applay gain smoothening
g(n) = (utcnt - ht)/att;
end
else
g(n) = 0;
end
end
end
n = x.*g;
end

Answers (0)

Categories

Find more on Audio I/O and Waveform Generation in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!