develop FFT real time in matlab

3 visualizzazioni (ultimi 30 giorni)
yogan sganzerla
yogan sganzerla il 19 Dic 2017
Risposto: Geoff Hayes il 22 Dic 2017
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!

Risposte (1)

Geoff Hayes
Geoff Hayes il 22 Dic 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.

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by