how to plot the required data from two analog input separately?
2 次查看(过去 30 天)
显示 更早的评论
As the program below, it get the required data from two analog inputs and plot the both datum in a graph. However, i want to plot the required data from two analog inputs separately? Can any one teach me?THX~
AI=analoginput('winsound',0);
chan=addchannel(AI,1:2);
get(AI);
duration=1;
SampleRate=44100;
set(AI, 'SampleRate', SampleRate);
set(AI, 'SamplesPerTrigger', duration*SampleRate);
set(AI, 'TriggerType', 'Manual');
start(AI);
trigger(AI);
data=getdata(AI);
plot(data);
wait(AI,2);
delete(AI);
回答(1 个)
Parag
2025-3-5
Hi, to plot the data from two analog input channels separately, you need to extract each channel's data and use separate “plot” commands. Here’s how you can modify your MATLAB code:
AI = analoginput('winsound', 0);
chan = addchannel(AI, 1:2);
get(AI);
% Define parameters
duration = 1;
SampleRate = 44100;
set(AI, 'SampleRate', SampleRate);
set(AI, 'SamplesPerTrigger', duration * SampleRate);
set(AI, 'TriggerType', 'Manual');
% Start and trigger the acquisition
start(AI);
trigger(AI);
% Get data
data = getdata(AI);
% Extract channels
channel1 = data(:,1); % First column for channel 1
channel2 = data(:,2); % Second column for channel 2
% Time vector for x-axis
time = (0:length(channel1)-1) / SampleRate;
% Plot separately
figure;
subplot(2,1,1);
plot(time, channel1);
title('Analog Input Channel 1');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;
subplot(2,1,2);
plot(time, channel2);
title('Analog Input Channel 2');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;
% Cleanup
wait(AI, 2);
delete(AI);
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Hardware Discovery and Setup 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!