From: drowe67 Date: Sun, 29 Apr 2018 05:26:27 +0000 (+0000) Subject: working spectrogram X-Git-Url: http://git.whiteaudio.com/gitweb/?a=commitdiff_plain;h=482465bde563decd258568b723938332bf6d2895;p=freetel-svn-tracking.git working spectrogram git-svn-id: https://svn.code.sf.net/p/freetel/code@3533 01035d8c-6547-0410-b346-abe4f91aad63 --- diff --git a/codec2-dev/octave/plot_specgram.m b/codec2-dev/octave/plot_specgram.m index 480253eb..adb50d6c 100644 --- a/codec2-dev/octave/plot_specgram.m +++ b/codec2-dev/octave/plot_specgram.m @@ -3,28 +3,18 @@ % % As the name suggests..... - function S = plot_specgram(x) - % set step size so we end up with an aray of pixels that is square. Otherwise - % imagesc will only use a ribbon on the figure. - Fs = 8000; - l = length(x); - - Nfft = 512; Nfft2 = Nfft/2; window = 512; nstep = window/2; - nsamples = floor(l/nstep) - 1; - S = zeros(nsamples,Nfft); - h = hanning(Nfft); - for i=1:nsamples - st = (i-1)*nstep+1; en = st+window-1; - %printf("i: %d st: %d en: %d l: %d\n", i, st, en, l); - S(i,:) = 20*log10(abs(fft(x(st:en).*h'))); - end - mx = ceil(max(max(S))/10)*10; - S = max(S,mx-30); - mesh((1:Nfft2)*4000/Nfft2, (1:nsamples)*nstep, S(:,1:Nfft2)); - view(90,-90); - %xlabel('Frequency (Hz)'); - %ylabel('Sample'); -en + + step = fix(20*Fs/1000); # one spectral slice every 5 ms + window = fix(160*Fs/1000); # 40 ms data window + fftn = 2^nextpow2(window); # next highest power of 2 + [S, f, t] = specgram(x, fftn, Fs, window, window-step); + S = abs(S(2:fftn*4000/Fs,:)); # magnitude in range 0