how to plot the required data from two analog input separately?

5 views (last 30 days)
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);

Answers (1)

Parag
Parag on 5 Mar 2025
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);

Categories

Find more on Hardware Discovery and Setup in Help Center and File Exchange

Tags

No tags entered yet.

Community Treasure Hunt

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

Start Hunting!