0
votes

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.

1

1 Answers

0
votes

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