matthiasm@8: function [s,f,t] = chunkspectrogram(filename,d_windo,d_nOverlap,d_nFFT, maxf) matthiasm@8: %% matthiasm@8: % d_ are the downsampled things matthiasm@8: % o_ are the original things matthiasm@8: matthiasm@8: matthiasm@8: d_fs = 11025; matthiasm@8: matthiasm@8: [temp, o_fs] = wavread(filename,'size'); matthiasm@8: matthiasm@8: if mod(o_fs/d_fs,1) ~= 0 matthiasm@8: error('The sample frequency of the wave file has to be an integer multiple of %1.0f.',d_fs); matthiasm@8: end matthiasm@8: matthiasm@8: o_nSample = temp(1); matthiasm@8: d_nSample = floor(o_nSample*d_fs/o_fs); matthiasm@8: matthiasm@8: o_nOverlap = d_nOverlap * o_fs/d_fs; matthiasm@8: matthiasm@8: matthiasm@8: d_nSamplePerChunk = d_windo+200*(d_windo-d_nOverlap); matthiasm@8: matthiasm@8: if d_nSample < d_nSamplePerChunk matthiasm@8: d_nSamplePerChunk = d_nSample; matthiasm@8: end matthiasm@8: matthiasm@8: d_endsample = d_nSamplePerChunk:d_nSamplePerChunk:d_nSample; matthiasm@8: matthiasm@8: o_startsample = [1, d_endsample * o_fs / d_fs + 1]; matthiasm@8: o_endsample = d_endsample * o_fs / d_fs; matthiasm@8: o_endsample = min(o_endsample + o_fs / d_fs * d_nOverlap, o_nSample); % extend so that chunks overlap matthiasm@8: matthiasm@8: % in most cases the file length is not exactly a multiple of matthiasm@8: if o_endsample(end) < o_nSample matthiasm@8: o_endsample = [o_endsample o_nSample]; matthiasm@8: end matthiasm@8: matthiasm@8: %% matthiasm@8: matthiasm@8: nChunk = length(o_startsample); matthiasm@8: matthiasm@8: for iChunk = 1:nChunk matthiasm@8: fprintf(1,'_'); matthiasm@8: end matthiasm@8: leftpad = zeros(d_windo/2,1); matthiasm@8: fprintf(1,'\n.') matthiasm@8: x = resample(mean(wavread(filename,[o_startsample(1) o_endsample(1)]),2),d_fs,o_fs); matthiasm@8: s = spectrogram([leftpad; x], d_windo,d_nOverlap,d_nFFT, d_fs); matthiasm@8: f = (0:d_nFFT/2-1)/d_nFFT*d_fs; matthiasm@8: if maxf < max(f) matthiasm@8: maxbin = find(f>maxf,1)-1; matthiasm@8: else matthiasm@8: maxbin = length(f); matthiasm@8: end matthiasm@8: s = s(1:maxbin,:); matthiasm@8: f = f(1:maxbin); matthiasm@8: for iChunk = 2:nChunk-1 matthiasm@8: fprintf(1,'.') matthiasm@8: temps = spectrogram(resample(mean(wavread(filename,[o_startsample(iChunk) o_endsample(iChunk)]),2),d_fs,o_fs), ... matthiasm@8: d_windo,d_nOverlap,d_nFFT, d_fs); matthiasm@8: s = [s(1:maxbin,:),temps(1:maxbin,:)]; matthiasm@8: end matthiasm@8: x = resample(mean(wavread(filename,[o_startsample(nChunk) o_nSample]),2),d_fs,o_fs); matthiasm@8: if length(x)>d_windo matthiasm@8: temps = spectrogram(x, ... matthiasm@8: d_windo,d_nOverlap,d_nFFT, d_fs); matthiasm@8: s = [s(1:maxbin,:),temps(1:maxbin,:)]; matthiasm@8: end matthiasm@8: fprintf(1,'.\n') matthiasm@8: t = (0:size(s,2)-1) * (d_windo-d_nOverlap)/d_fs;