How to turn real time signal to spectrogram?
Show older comments
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)
Walter Roberson
on 12 Sep 2017
0 votes
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
KwokSing Wong
on 13 Sep 2017
Edited: KwokSing Wong
on 13 Sep 2017
Walter Roberson
on 13 Sep 2017
resample is from the signal processing toolbox.
Categories
Find more on Time-Frequency Analysis in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!