Code:
PLZ complete this lab i have added all files and 2 sample labs i need you to write mine must be good at code on matlab and use my result with the name jennah on the files.
%% EMG_OptitrackSync_Biopac_updated
%Updated by Ashley MontJohnson on 3/29/2022
%
% Updated by Erick Nunez on 8/26/2025
% – Updated library location
% – Updated library version
% – Updated mptype value to 104 for MP36A box
% – Updated channelpresent.xml file location
% – Tested with all 4 channels
% – Tested with Duo camera (Sync output: Recording Gate, Inverted)
%
%This code sets up the biopac connection & settings. Then it will ask for a
%time (in seconds) for how long you want the experiment to run. From there
%it will count down and instruct you to hit record in Motive. Once you hit
%record you will see the Figure 1 box pop up with the EMG recording in real
%time. The EMG recording will end and you will be given an elapsed time
%(should be very close to the time you entered). Then you will enter a
%trial name. Then you will be instructed to go to motive and stop da10ta
%collection. IT IS IMPORTANT TO NOTE THAT THE START TIME WILL BE THE SAME
%BUT THE MOTIVE DATA WILL RUN LONGER – YOU MUST CUT THIS OUT IN POST
%PROCESSING OF THE MOTIVE DATA. You know when data collection ended with
%EMG in matlab from your time vector. Don’t forget to export Motive data
%separately!
clear all
clc
close all
ver = computer;
if strcmp(ver,’PCWIN64′)
dll = ‘C:Program FilesBIOPAC Systems, IncBIOPAC Hardware API 2.2.5 EducationVC14x64mpdev.dll’;
end
dothdir = ‘C:Program FilesBIOPAC Systems, IncBIOPAC Hardware API 2.2.5 Educationmpdev.h’;
mptype = 104; % MP36A
mpmethod = 10; % USB
sn = ‘auto’;
libname = ‘mpdev’;
%warning off MATLAB:loadlibrary:enumexists;
loadlibrary(dll,dothdir);
%% If not using phigets, keep this commented out
% loadphidget21;
% phid = libpointer(‘int32Ptr’);
% calllib(‘phidget21’, ‘CPhidgetBridge_create’, phid);
% calllib(‘phidget21’, ‘CPhidget_open’, phid, -1);
% calllib(‘phidget21’, ‘CPhidget_waitForAttachment’, phid, 500);
% calllib(‘phidget21’, ‘CPhidgetBridge_setEnabled’, phid, 0, 1); % Enables Phidget
% calllib(‘phidget21’, ‘CPhidgetBridge_setEnabled’, phid, 3, 1); % Enables Phidget
% sensorVal = libpointer(‘doublePtr’, 0);
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% gain = libpointer(‘CPhidgetBridge_Gain’,’PHIDGET_BRIDGE_GAIN_128′);
% gain.Value = ‘PHIDGET_BRIDGE_GAIN_128’;
% calllib(‘phidget21’, ‘CPhidgetBridge_setGain’,phid,0,gain.Value);
% calllib(‘phidget21’, ‘CPhidgetBridge_setGain’,phid,3,gain.Value);
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% calllib(‘phidget21’, ‘CPhidgetBridge_getBridgeValue’,phid,0,sensorVal);
% Bias1 = sensorVal.Value;
%% Set up settings on Biopac
sample_rate = 1000; % Sample Rate
channel_mask = [1 1 1 0]; % Channel selection
channels = {‘a111’ ‘a111’ ” ”}; % Channel presets
retval = calllib(libname,’connectMPDev’,mptype,mpmethod,sn) % connect to device
retval = calllib(libname, ‘setSampleRate’, double(1000/sample_rate)) % Set Sample Rate
retval = calllib(libname, ‘setAcqChannels’, channel_mask) % Set Acquisition Channels
retval = calllib(libname, ‘loadXMLPresetFile’, ‘C:Program FilesBIOPAC Systems, IncBIOPAC Hardware API 2.2.5 EducationPresetFileschannelpresets.xml’) % load preset file
k = find(channel_mask==1);
for i=1:length(k)
assignin(‘base’,strcat(‘ch’,num2str(k(i)),’data’),[])
retval = calllib(libname, ‘configChannelByPresetID’, k(i)-1, channels{k(i)}) % Configure the channels by preset ID
end
%% Data collection
T = input(‘Enter Collection Time: ‘); % collect total of T secons of data
t = 0.1; % collect t seconds of data per iteration
numValuesToRead = t*sample_rate*sum(channel_mask); % data points per iteration
remaining = T*sample_rate*sum(channel_mask); % remaining data points to acquire
tbuff(1:numValuesToRead) = double(0); % initialize the correct amount of data
numRead = 0;
figure
for q = 3:-1:1
disp(q)
pause(1)
end
count = 0;
% trigger from Biopac
retval = calllib(libname, ‘startMPAcqDaemon’) % Create virtual server
retval = calllib(libname, ‘startAcquisition’) % Start acquisition
%
tic
while remaining >0
count = count+1;
% Phidget Data
% calllib(‘phidget21’, ‘CPhidgetBridge_getBridgeValue’,phid,0,sensorVal);
% ForceTmp1 = sensorVal.Value;
% ForceTmp1 = (ForceTmp1-Bias1).*10;
% calllib(‘phidget21’, ‘CPhidgetBridge_getBridgeValue’,phid,3,sensorVal);
% ForceTmp2 = sensorVal.Value;
% ForceTmp2 = (ForceTmp2-Bias2).*10;
% Force2 = [Force2;ForceTmp2];
% Force(count) = ForceTmp1;
[retval, tbuff, numRead] = calllib(libname, ‘receiveMPData’,tbuff, numValuesToRead, numRead); % get data
pause(.05); clf; hold on
remaining = remaining – numRead;
% subplot(2,1,1)
for i=1:sum(channel_mask)
assignin(‘base’,strcat(‘ch’,num2str(k(i)),’data’),[eval(strcat(‘ch’,num2str(k(i)),’data’)) tbuff(i:sum(channel_mask):length(tbuff))]);
plot(eval(strcat(‘ch’,num2str(k(i)),’data’)))
end
time(count) = toc;
xlabel(‘Time’)
ylabel(‘EMG’);
% subplot(2,1,2)
% plot(time,Force)
% xlabel(‘Time’)
% ylabel(‘Force’);
hold off
end
toc
%% end of data collection.
fname = input(‘Enter a trial name: ‘,’s’);
save(fname,’ch1data’,’ch2data’,’ch3data’,’time’)
% calllib(‘phidget21’, ‘CPhidget_close’, phid);
% calllib(‘phidget21’, ‘CPhidget_delete’, phid);
retval = calllib(libname, ‘stopAcquisition’); % stop acquisition
calllib(libname, ‘disconnectMPDev’); % disconnect device
unloadlibrary(libname) % unload library
Attached Files (PDF/DOCX): Copy of BME384 Lab 2.pdf, ChannelPresetID.docx, index.pdf, Lab_2_S26.docx, The_ABC_of_EMG.pdf
Note: Content extraction from these files is restricted, please review them manually.

Leave a Reply
You must be logged in to post a comment.