comparison _misc/featureextraction/.svn/text-base/chunkspectrogram.m.svn-base @ 8:b5b38998ef3b

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