Mercurial > hg > camir-aes2014
comparison toolboxes/MIRtoolbox1.3.2/AuditoryToolbox/spectrogram.m @ 0:e9a9cd732c1e tip
first hg version after svn
author | wolffd |
---|---|
date | Tue, 10 Feb 2015 15:05:51 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:e9a9cd732c1e |
---|---|
1 function [array,raw] = spectrogram(wave,segsize,nlap,ntrans); | |
2 %function array = spectrogram(wave,segsize,nlap,ntrans); | |
3 % defaults spectrogram(wave,128,8,4) | |
4 % nlap is number of hamming windows overlapping a point; | |
5 % ntrans is factor by which transform is bigger than segment; | |
6 % returns a spectrogram 'array' with fourth root of power, | |
7 % filter smoothed and formatted for display. | |
8 | |
9 % Added option to return raw spectrogram.... Malcolm 5/26/95 | |
10 % Added code so that input could be any direction ... Malcolm 5/26/95 | |
11 % (c) 1998 Interval Research Corporation | |
12 | |
13 if nargin < 4; ntrans=4; end | |
14 if nargin < 3; nlap=8; end | |
15 if nargin < 2; segsize=128; end | |
16 | |
17 [r c] = size(wave); | |
18 if (r < c) | |
19 wave = filter([1 -0.95],[1],wave'); | |
20 else | |
21 wave = filter([1 -0.95],[1],wave); | |
22 end | |
23 | |
24 s = length(wave); | |
25 nsegs = floor(s/(segsize/nlap))-nlap+1; | |
26 array = zeros(ntrans/2*segsize,nsegs); | |
27 window = 0.54-0.46*cos(2*pi/(segsize+1)*(1:segsize)'); | |
28 for i = 1:nsegs | |
29 seg = zeros(ntrans*segsize,1); % leave half full of zeroes | |
30 seg(1:segsize) = ... | |
31 window.*wave(((i-1)*segsize/nlap+1):((i+nlap-1)*segsize/nlap)); | |
32 seg = abs(fft(seg)); | |
33 % reverse for image display | |
34 array(:,i) = seg(((ntrans/2*segsize)+1):(ntrans*segsize)); | |
35 end | |
36 | |
37 if nargout > 1 | |
38 raw = array; | |
39 end | |
40 | |
41 array = array .* array; % back into power domain for smoothing | |
42 | |
43 for i=1:nsegs % smooth the spectral slices | |
44 array(:,i) = filter([.2 1 .2],[1],array(:,i)); | |
45 end | |
46 | |
47 for i=1:ntrans/2*segsize % smooth the channels | |
48 array(i,:) = filter([.2 1 .2],[1],array(i,:)); | |
49 end | |
50 | |
51 % compress with square root of amplitude (fourth root of power) | |
52 off = 0.0001*max(max(array)); % low end stabilization offset, | |
53 array = (off+array).^0.25-off^0.25; % better than a threshold hack! | |
54 array = 255/max(max(array))*array; | |
55 | |
56 | |
57 |