1% spec.m 2% Jean Marc Valin 3% 4% Spectrogram function for Octave 5% 6% Copyright (c) John-Marc Valin 2012 7% 8% Redistribution and use in source and binary forms, with or without 9% modification, are permitted provided that the following conditions 10% are met: 11% 12% - Redistributions of source code must retain the above copyright 13% notice, this list of conditions and the following disclaimer. 14% 15% - Redistributions in binary form must reproduce the above copyright 16% notice, this list of conditions and the following disclaimer in the 17% documentation and/or other materials provided with the distribution. 18% 19% - Neither the name of Jean Marc Valin nor the names of its 20% contributors may be used to endorse or promote products derived from 21% this software without specific prior written permission. 22% 23% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 24% ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 25% LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 26% A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR 27% CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28% EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29% PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30% PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31% LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32% NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33% SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 35function X = spec(x, Fs, framesize, start, stop) 36 37 38gr=[zeros(1024,1),[0:1023]'/1023,.68*[0:1023]'/1023]; 39 40%gr=[.4*[0:1023]'/1023,[0:1023]'/1023,.68*[0:1023]'/1023]; 41 42%t=[0:1023]'/1023; 43%t=(1+.25*t-cos(pi*t))/2.25; 44%gr = [zeros(1024,1),t,.68*t]; 45 46 47%colormap(gr); 48 49if nargin < 2 || isempty(Fs) 50 Fs = 44100; 51end 52 53if nargin < 3 || isempty(framesize) 54 framesize = 2048; 55endif 56 57offset = framesize/8; 58 59X = 20*log10(abs(specgram(x, framesize, 48000, blackmanharris(framesize)', framesize-offset))); 60 61XM=max(max(X)); 62X = max(XM-30,X); 63%size(X) 64F = -[framesize/2-1:-1:0]/framesize*Fs; 65%F = [0:127]/128*24000; 66T=[1:size(X,2)]/Fs*offset; 67%imagesc(X(end:-1:1,:)); 68 69if nargin < 4 || isempty(start) 70 istart=1; 71else 72 istart = round(start*Fs/offset); 73end 74 75if nargin < 5 || isempty(stop) 76 istop = size(X,2); 77else 78 istop = round(stop*Fs/offset); 79endif 80 81istart = max(1,istart); 82istop = min(istop, size(X,2)); 83 84imagesc(T(1+istart:istop), F, X(end:-1:1,1+istart:istop)); 85 86X = X(:,1+istart:istop); 87