% --- Hardware Configuration ---
% Assuming you have a National Instruments DAQ device (e.g., USB-6008)
% and a sensor connected to analog input channel 0 (ai0).
% You may need to adjust the device and channel names based on your setup.
% --- Create DAQ Session ---
s = daq.createSession('ni'); % 'ni' for National Instruments devices
% --- Add Analog Input Channel ---
ch = addAnalogInputChannel(s, 'Dev1', 'ai0', 'Voltage'); % 'Dev1' might change.
% --- Configure Channel Properties ---
ch.Range = [-10 10]; % Set input voltage range (adjust as needed)
ch.TerminalConfig = 'SingleEnded'; % or 'Differential', 'PseudoDifferential'
% --- Set Acquisition Parameters ---
s.Rate = 1000; % Sampling rate (samples per second)
s.DurationInSeconds = 10; % Acquisition duration (seconds)
% --- Acquire Data ---
disp('Acquiring data...');
data = startForeground(s); % Acquire data synchronously
time = (0:length(data)-1)'/s.Rate; % Generate time vector
disp('Data acquisition complete.');
% --- Display and Analyze Data ---
figure;
plot(time, data);
xlabel('Time (s)');
ylabel('Voltage (V)');
title('Acquired Data');
% --- Basic Analysis ---
meanValue = mean(data);
stdValue = std(data);
fprintf('Mean Value: %.4f V\n', meanValue);
fprintf('Standard Deviation: %.4f V\n', stdValue);
% --- Saving Data to File ---
% Example: Saving to a CSV file
dataTable = table(time, data, 'VariableNames', {'Time', 'Voltage'});
writetable(dataTable, 'acquired_data.csv');
disp('Data saved to acquired_data.csv');
% --- Further Analysis ---
% You can perform more advanced analysis, such as:
% - Filtering (e.g., using `filter` function)
% - Frequency analysis (e.g., using `fft` function)
% - Signal processing techniques
% - Building predictive models
% - etc.
% --- Cleanup ---
clear s; % Clear the session object