SebastianEwert@28: function computeMeanSpectralEnvelope(audiofile, fftLength) SebastianEwert@28: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SebastianEwert@28: % Audio Degradation Toolbox SebastianEwert@28: % SebastianEwert@28: % Centre for Digital Music, Queen Mary University of London. SebastianEwert@28: % This file copyright 2013 Sebastian Ewert, Matthias Mauch and QMUL. SebastianEwert@28: % SebastianEwert@28: % This program is free software; you can redistribute it and/or SebastianEwert@28: % modify it under the terms of the GNU General Public License as SebastianEwert@28: % published by the Free Software Foundation; either version 2 of the SebastianEwert@28: % License, or (at your option) any later version. See the file SebastianEwert@28: % COPYING included with this distribution for more information. SebastianEwert@28: % SebastianEwert@28: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SebastianEwert@28: SebastianEwert@28: [f_audio,samplingFreq]=wavread(audiofile); SebastianEwert@28: SebastianEwert@28: % compute mean spectral vector for f_audio SebastianEwert@28: [destMagFreqResp, destMagFreqResp_freqs] = internal_computeMeanSpectralVector(f_audio,samplingFreq,fftLength); SebastianEwert@28: destMagFreqResp = internal_standardizeMagFreqResp(destMagFreqResp); SebastianEwert@28: SebastianEwert@28: outputFilename = [audiofile(1:end-4),'_specEnv']; SebastianEwert@28: save(outputFilename,'destMagFreqResp','destMagFreqResp_freqs') SebastianEwert@28: SebastianEwert@28: end SebastianEwert@28: SebastianEwert@28: SebastianEwert@28: function [f_meanmagspec_db,freqs] = internal_computeMeanSpectralVector(f_audio,fs,fftLength) SebastianEwert@28: SebastianEwert@28: f_audio = mean(f_audio,2); SebastianEwert@28: SebastianEwert@28: [f_spec,freqs,time] = spectrogram(f_audio,hanning(fftLength),fftLength/2,fftLength,fs); SebastianEwert@28: SebastianEwert@28: f_magspec_db = 20 * log10(abs(f_spec)); SebastianEwert@28: SebastianEwert@28: f_magspec_db(:,isinf(sum(abs(f_magspec_db),1))) = []; % ignore rows with -inf/inf entries SebastianEwert@28: SebastianEwert@28: f_meanmagspec_db = mean(f_magspec_db,2); SebastianEwert@28: SebastianEwert@28: end SebastianEwert@28: SebastianEwert@28: function magFreqResp = internal_standardizeMagFreqResp(magFreqResp) SebastianEwert@28: SebastianEwert@28: maxRobust = max(magFreqResp(~isinf(magFreqResp))); SebastianEwert@28: SebastianEwert@28: magFreqResp = magFreqResp - maxRobust; SebastianEwert@28: SebastianEwert@28: magFreqResp(magFreqResp > 0) = 0; % remaining positive inf SebastianEwert@28: magFreqResp(magFreqResp < -80) = -80; % remaining positive inf SebastianEwert@28: SebastianEwert@28: end SebastianEwert@28: