annotate _misc/featureextraction/.svn/text-base/chunkspectrogram.m.svn-base @ 9:4ea6619cb3f5 tip

removed log files
author matthiasm
date Fri, 11 Apr 2014 15:55:11 +0100
parents b5b38998ef3b
children
rev   line source
matthiasm@8 1 function [s,f,t] = chunkspectrogram(filename,d_windo,d_nOverlap,d_nFFT, maxf)
matthiasm@8 2 %%
matthiasm@8 3 % d_ are the downsampled things
matthiasm@8 4 % o_ are the original things
matthiasm@8 5
matthiasm@8 6
matthiasm@8 7 d_fs = 11025;
matthiasm@8 8
matthiasm@8 9 [temp, o_fs] = wavread(filename,'size');
matthiasm@8 10
matthiasm@8 11 if mod(o_fs/d_fs,1) ~= 0
matthiasm@8 12 error('The sample frequency of the wave file has to be an integer multiple of %1.0f.',d_fs);
matthiasm@8 13 end
matthiasm@8 14
matthiasm@8 15 o_nSample = temp(1);
matthiasm@8 16 d_nSample = floor(o_nSample*d_fs/o_fs);
matthiasm@8 17
matthiasm@8 18 o_nOverlap = d_nOverlap * o_fs/d_fs;
matthiasm@8 19
matthiasm@8 20
matthiasm@8 21 d_nSamplePerChunk = d_windo+200*(d_windo-d_nOverlap);
matthiasm@8 22
matthiasm@8 23 if d_nSample < d_nSamplePerChunk
matthiasm@8 24 d_nSamplePerChunk = d_nSample;
matthiasm@8 25 end
matthiasm@8 26
matthiasm@8 27 d_endsample = d_nSamplePerChunk:d_nSamplePerChunk:d_nSample;
matthiasm@8 28
matthiasm@8 29 o_startsample = [1, d_endsample * o_fs / d_fs + 1];
matthiasm@8 30 o_endsample = d_endsample * o_fs / d_fs;
matthiasm@8 31 o_endsample = min(o_endsample + o_fs / d_fs * d_nOverlap, o_nSample); % extend so that chunks overlap
matthiasm@8 32
matthiasm@8 33 % in most cases the file length is not exactly a multiple of
matthiasm@8 34 if o_endsample(end) < o_nSample
matthiasm@8 35 o_endsample = [o_endsample o_nSample];
matthiasm@8 36 end
matthiasm@8 37
matthiasm@8 38 %%
matthiasm@8 39
matthiasm@8 40 nChunk = length(o_startsample);
matthiasm@8 41
matthiasm@8 42 for iChunk = 1:nChunk
matthiasm@8 43 fprintf(1,'_');
matthiasm@8 44 end
matthiasm@8 45 leftpad = zeros(d_windo/2,1);
matthiasm@8 46 fprintf(1,'\n.')
matthiasm@8 47 x = resample(mean(wavread(filename,[o_startsample(1) o_endsample(1)]),2),d_fs,o_fs);
matthiasm@8 48 s = spectrogram([leftpad; x], d_windo,d_nOverlap,d_nFFT, d_fs);
matthiasm@8 49 f = (0:d_nFFT/2-1)/d_nFFT*d_fs;
matthiasm@8 50 if maxf < max(f)
matthiasm@8 51 maxbin = find(f>maxf,1)-1;
matthiasm@8 52 else
matthiasm@8 53 maxbin = length(f);
matthiasm@8 54 end
matthiasm@8 55 s = s(1:maxbin,:);
matthiasm@8 56 f = f(1:maxbin);
matthiasm@8 57 for iChunk = 2:nChunk-1
matthiasm@8 58 fprintf(1,'.')
matthiasm@8 59 temps = spectrogram(resample(mean(wavread(filename,[o_startsample(iChunk) o_endsample(iChunk)]),2),d_fs,o_fs), ...
matthiasm@8 60 d_windo,d_nOverlap,d_nFFT, d_fs);
matthiasm@8 61 s = [s(1:maxbin,:),temps(1:maxbin,:)];
matthiasm@8 62 end
matthiasm@8 63 x = resample(mean(wavread(filename,[o_startsample(nChunk) o_nSample]),2),d_fs,o_fs);
matthiasm@8 64 if length(x)>d_windo
matthiasm@8 65 temps = spectrogram(x, ...
matthiasm@8 66 d_windo,d_nOverlap,d_nFFT, d_fs);
matthiasm@8 67 s = [s(1:maxbin,:),temps(1:maxbin,:)];
matthiasm@8 68 end
matthiasm@8 69 fprintf(1,'.\n')
matthiasm@8 70 t = (0:size(s,2)-1) * (d_windo-d_nOverlap)/d_fs;