how to plot the required data from two analog input separately?
7 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commento
Risposte (1)
Parag
il 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);
0 Commenti
Vedere anche
Categorie
Scopri di più su Hardware Discovery and Setup in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!