%function that sets a reference for the vad. Therefore the power included in a certain time %frame of noise (input from the user) is calculated %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function P_ref = call_Pref(signal,framelength) %make sure some global variabels are used global n; display('Calculation of a power reference started.'),tic k = 1; while (length(signal)-k*framelength >=0) %read in the samples in = signal((k-1)*framelength+1:k*framelength); %obtain frequency spectrum of input signal I = fft(in); %calculate the power in the spectrum Pref(k) = sum(abs(I.^2)); k = k+1; end %calculate the mean during perio display('Calculation of a power reference finished.'),toc