% computeSPLunfiltered.m This function compute total unfiltered spl from complex sum

function [ splTotal, limitFreq ] = computeSPLunfiltered( complexSum, fullScaleLevel, spsMean, fs, nfft, overlap, ...
         plotSignalEnable )

    rmsTotal                    = ( sum( complexSum, 2 )' ) ./ 2;
    splTotal                    = fullScaleLevel + 10 * log10( rmsTotal );

    halfFrf                     = avgFft( spsMean, nfft, overlap );
    amplitudeFrfdB              = 20 * log10( mean( abs( halfFrf ), 3 ) );
    freq                        = linspace( 0, fs/2, nfft/2+1 ); 
    k                           = round( 20 / ( fs / nfft ) );
    j                           = round( 20000 / ( fs / nfft ) );
    limitFreq                   = [ min( amplitudeFrfdB( k:j ) ) max( amplitudeFrfdB( k:j ) ) ];

    if plotSignalEnable

        figure    
        semilogx( freq, amplitudeFrfdB )
        title( 'Unfiltered SPL' )
        grid on
        xlim( [ 20 20000 ] )
        xlabel( 'Frequency [Hz]' )
        ylim( limitFreq )
        ylabel( '[dB]' )
        
    end
    
end
