develop FFT real time in matlab
3 views (last 30 days)
Show older comments
Hello,
I have a microphone in front of a cooler because my goal is to define the RPM of the cooler. I have to develop a SCADA with this system.
Well, I don't know very much about the processing of the signal in Matlab and I found this code:
recObj = audiorecorder
disp('Start speaking.')
recordblocking(recObj, 5);
disp('End of Recording.');
It worked very well, but know, I would like to listen de song in real time and not hold on the matlab process the signal read the line
play(recObj);
What I need is REAL TIME!
cheers!
0 Comments
Answers (1)
Geoff Hayes
on 22 Dec 2017
yogan - you could use the non-blocking record function instead and just assign a callback to the TimerFcn of your recorder. Then whenever the callback fires, you can grab the latest set of audio samples and process them. A very crude example is the following piece of code
function myRecorder = nonBlockingAudioRecorder
figure;
hPlot = plot(NaN,NaN);
sampleRate = 8192;
myRecorder = audiorecorder(sampleRate,8,1);
set(myRecorder, 'TimerFcn', @myRecorderCallback, 'TimerPeriod', 1);
atSecond = 1;
record(myRecorder);
function myRecorderCallback(~, ~)
allSamples = getaudiodata(myRecorder);
newSamples = allSamples((atSecond - 1) * sampleRate + 1:atSecond * sampleRate);
xdata = get(hPlot, 'XData');
ydata = get(hPlot, 'YData');
if isnan(xdata)
xdata = linspace(0, atSecond - 1/sampleRate,sampleRate);
ydata = [];
else
xdata = [xdata linspace(atSecond, atSecond + 1 - 1/sampleRate, sampleRate)];
end
ydata = [ydata newSamples'];
set(hPlot, 'XData', xdata, 'YData', ydata);
atSecond = atSecond + 1;
if atSecond > 10
stop(myRecorder);
end
end
end
The above code records about a little over eleven seconds of data. Whenever the callback fires (about every one second), we grab the latest 8192 samples and plot them.
0 Comments
See Also
Categories
Find more on Annotations in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!