develop FFT real time in matlab

5 次查看(过去 30 天)
yogan sganzerla
yogan sganzerla 2017-12-19
回答: Geoff Hayes 2017-12-22
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!

回答(1 个)

Geoff Hayes
Geoff Hayes 2017-12-22
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.

类别

Help CenterFile Exchange 中查找有关 Audio I/O and Waveform Generation 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by