develop FFT real time in matlab

조회 수: 4 (최근 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 and Video Data에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by