how to plot the required data from two analog input separately?
7 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentario
Respuestas (1)
Parag
el 5 de Mzo. de 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 comentarios
Ver también
Categorías
Más información sobre Hardware Discovery and Setup en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!