Ploting analog input in real time
11 views (last 30 days)
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?
Gautam Vallabha on 8 Dec 2011
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);
plot(ax1, time, amplitude);
plot(ax2, freq, power);
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);