0

I'm trying to perform a real time sound analysis. Currently I'm able to get real time streaming of the spectrum but when I try to plot the spectrogram it introduces a delay of about 4 seconds even if I try to reduce calculations.

I would like to know if there is a way to perform a faster plot of the spectrogram (as for plotting data, updating axes rather than update plot).

At the moment I'm using an input buffer with 1024 samples:

Spectrogram(audio, 256, round(256/2), 256, 1800)

I tried to reduce the window size and NFFT but the result is always the same.

Sga
  • 3,608
  • 2
  • 36
  • 47
Dodz
  • 35
  • 1
  • 8

1 Answers1

0

Try to just set the image CData for each update of the spectrogram (see example code below). Provided you can compute your spectrogram fast enough, this should not cause long delays. Generating a new image by just calling the spectogram with no ouput might actually cause the delays.

You can use

tic
S=Spectrogram(audio, 256, round(256/2), 256, 1800);
toc

to see how long each computation takes, but I suspect this will compute in sufficient time and your bottleneck is the generation of the whole figure, when you call spectrogram without ouputs.

figure
audio=randn(1024,1);
[S,F,T]=spectrogram(audio,256,round(256/2),256,1800);
im=image(F,T,abs(S).^2);

for i=1:100
    audio=randn(1024,1);
    S=spectrogram(audio,256,round(256/2),256,1800);
    set(im,'CData',abs(S).^2);
    pause(1/30);
end
Felix Darvas
  • 507
  • 3
  • 5
  • It seems to be a good way to improve the spectrogram plot speed. I´m trying to write my code to perform the analysis! thank you! – Dodz Dec 11 '15 at 12:16