Ploting analog input in real time

조회 수: 3 (최근 30일)
Raldi
Raldi 2011년 12월 7일
Hey evereyone I have the following code
input=analoginput('winsound'); set (input, 'SampleRate', 8000); set (input, 'SamplesPerTrigger', 1000); num=1000; set (input, 'TriggerRepeat', inf); start(input)
while "something" data = getdata(input); flushdata(input); plot("data"); plot("fft data spectrum") stop(input) delete(input); end
The data plot shows fine, but the second plot will only show something for 1 second just after i run the code and then it shows nothing. Why is that happening?

답변 (2개)

Gautam Vallabha
Gautam Vallabha 2011년 12월 8일
It is possible that one of your plots is being overwritten by the other plot. The standard plot command (plot(x,y)) uses the current figure and axes (gcf and gca), the default behavior is that a new plot will replace any existing plots.
You might try explicitly using different axes, e.g.
ax1 = subplot(2,1,1);
ax2 = subplot(2,1,2);
while (...)
plot(ax1, time, amplitude);
...
plot(ax2, freq, power);
end
By the way, for better performance, instead of calling plot each time, consider calling it once (before the while loop), and then setting xdata and ydata, e.g.:
h = plot(ax1, time, amplitude);
...
set(h,'xdata', newTimeData, 'ydata', newAmplitudeData);
  댓글 수: 1
Raldi
Raldi 2011년 12월 8일
but they are on different objects axes1 and axes2, how can this happen?

댓글을 달려면 로그인하십시오.


Walter Roberson
Walter Roberson 2011년 12월 8일
Do not stop() and delete() input within the loop.
Within the loop, add a drawnow() call after the plot() call.
  댓글 수: 5
Walter Roberson
Walter Roberson 2011년 12월 9일
Please see my comment to my answer in http://www.mathworks.com/matlabcentral/answers/22208-show-figure
Raldi
Raldi 2011년 12월 11일
Either i didnt understand you answer well or it doesnt work in my case cause it still didnt show anything on the spectrum analisation axes.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Spectral Analysis에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by