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

7 ビュー (過去 30 日間)
PUI SAN LO
PUI SAN LO 2011 年 7 月 6 日
回答済み: Parag 2025 年 3 月 5 日
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 件のコメント
Gerd
Gerd 2011 年 7 月 6 日
Do you want to have two separate plots or 2 plots in one figure?

サインインしてコメントする。

回答 (1 件)

Parag
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);

カテゴリ

Help Center および File ExchangeHardware Discovery and Setup についてさらに検索

タグ

タグが未入力です。

Community Treasure Hunt

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

Start Hunting!

Translated by