How to turn real time signal to spectrogram?

I have a code that capture a real time signal from my sensor. The graph was shown in time spectrum, but i want them shown as spectrogram. Do i need to save the graph first, then do the fft and finally plot the fft result to spectrogram? Can I do the fft while i capturing my real time signal and plot the spectrogram?
Heres my code:
clc; clear all;close all;
a= arduino;
ai_pin='A1';
tic;
i=0;
while (toc<4)
i=i+1;
t(i)=toc;
v(i)=readVoltage(a,ai_pin);
figure(1)
plot(t,v,'r');
pause(0.1);
end

Answers (1)

Your time differences are not going to be exactly consistent, so you cannot do a plain fft or plain spectrogram() call.
Probably your easiest way to proceed is to resample your signals to regular time intervals, followed by calling spectrogram(). See https://www.mathworks.com/help/signal/examples/resampling-nonuniformly-sampled-signals.html

2 Comments

When I use the function y = resample(v,115200,44100), it says Undefined function 'resample' for input arguments of type 'double'.
Why is that happening?
resample is from the signal processing toolbox.

Sign in to comment.

Categories

Asked:

on 12 Sep 2017

Commented:

on 13 Sep 2017

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!