Permalink
Browse files

Release of BioPatRec FRA

  • Loading branch information...
1 parent 08d0d53 commit 1da2a228e504d3e8186118e1f68841a8cb3db488 @maxoc maxoc committed Jul 19, 2016
Showing 370 changed files with 27,840 additions and 5,674 deletions.
View
@@ -24,6 +24,7 @@
% ------------------------- Updates & Contributors ------------------------
% 2009-04-02 / Max Ortiz / Creation of EMG_AQ
% 2011-22-06 / Max Ortiz / Software name changed from EMG_AQ to BioPatRec
+% 20XX-XX-XX / Author / Comments
close all;
clear all;
View
@@ -23,46 +23,84 @@
% SetDeviceStartAcquisition(),
% Acquire_tWs(), StopAcquisition(). This functions
% has been moved to COMM/AFE folder, into this new script.
-
+% 2015-1-19 / Enzo Mastinu / The ADS1299 part has been modified in way to be
+ % compatible with the new ADS1299 acquisition mode (DSP + FPU)
+% 2015-4-10 / Enzo Mastinu / The ADS1299_DSP acquisition has been optimized, only desired
+ % channels are transmitted to PC, not all as before
+% 2016-7-08 / Enzo Mastinu / The ADS_DSP/Neuromotus acquisition has been
+ % optimized introducing the re-synchronization
+ % in case the signal got lost
% 20xx-xx-xx / Author / Comment
% It acquire tWs samples from the selected device
-function cData = Acquire_tWs(deviceName, obj, nCh, tWs)
+function [cData, error] = Acquire_tWs(deviceName, obj, nCh, tWs)
- cData = zeros(tWs,nCh); % this is the data structure that the function must return
- ampPP = 0.0005;
- offVector = 0:nCh-1;
- offVector = offVector .* ampPP;
-
+ error = 0;
+ cData = zeros(tWs,nCh); % this is the data structure that the function must return
- %%%%% ADS1299 %%%%%
- if strcmp(deviceName, 'ADS1299')
- LSBweight = double(4.5/(24*8388607)); % ADS1299: if gain is set on 24 V/V
- for sampleNr = 1:tWs
- % 27bytes package mode
- byteData = fread(obj,27,'char'); % Acquire 27 bytes packet from Tiva (and from ADS1299), 3 status bytes + 3 byte (24bit) for each channel
- value = [65536 256 1]*reshape(byteData(4:end), 3, 8); % all channels data are now available on value vector, byteData(4:end) means throw away status bytes
- for k = 1:nCh
- if value(k) > 8388607 % the data must be converted from 2's complement
- value(k) = value(k) - 2^24;
+ % Set warnings to temporarily issue error (exceptions)
+ s = warning('error', 'instrument:fread:unsuccessfulRead');
+ try
+ %%%%% ADS1299 %%%%%
+ if strcmp(deviceName, 'ADS1299')
+ % LSBweight = double(4.5/(24*8388607)); % ADS1299: we always use the gain of 24 V/V
+ LSBweight = double(4.5/(8388607)); % It is better to plot data with gain scaling effect
+ for sampleNr = 1:tWs
+ % 27bytes package mode
+ byteData = fread(obj,27,'char'); % Acquire 27 bytes packet from Tiva (and from ADS1299), 3 status bytes + 3 byte (24bit) for each channel
+ value = [65536 256 1]*reshape(byteData(4:end), 3, 8); % all channels data are now available on value vector, byteData(4:end) means throw away status bytes
+ for k = 1:nCh
+ if value(k) > 8388607 % the data must be converted from 2's complement
+ value(k) = value(k) - 2^24;
+ end
+ cData(sampleNr,k) = value(k) * LSBweight;
+ end
+ end
+ end
+ if strcmp(deviceName, 'ADS_BP')
+ for sampleNr = 1:tWs
+ go = 0;
+ while go == 0
+ % nCh*4 bytes (float) mode
+ byteData = fread(obj,nCh,'float32'); % float data mode (4bytes X nCh channels)
+ if byteData < 10
+ go = 1;
+ else
+ % Synchronize the device again
+ fwrite(obj,'T','char');
+ % Read available data and discard it
+ if obj.BytesAvailable > 1
+ fread(obj,obj.BytesAvailable,'uint8');
+ end
+ fwrite(obj,'G','char');
+ fwrite(obj,nCh,'char');
+ fread(obj,1,'char');
+ go = 0;
+ end
end
- cData(sampleNr,k) = value(k) * LSBweight;
- end
+ cData(sampleNr,:) = byteData(1:nCh,:)';
+ end
end
- end
+
+ %%%%% INTAN RHA2216 %%%%%
+ if strcmp(deviceName, 'RHA2216')
+ % LSBweight = double(2.5/(200*65535)); % Intan differential gain is 200 V/V
+ LSBweight = double(2.5/(65535)); % It is better to plot data with gain scaling effect
+ for sampleNr = 1:tWs
+ value16 = fread(obj,nCh,'uint16');
+ for k = 1:nCh
+ % cData(sampleNr,k) = value16(k) - 16384; % Centers data and scales it to fit the graphs
+ cData(sampleNr,k) = value16(k)*LSBweight; % Convert data into volt
+ end
+ end
+ end
- %%%%% INTAN RHA2216 %%%%%
- if strcmp(deviceName, 'RHA2216')
- LSBweight = double(2.5/(200*65535)); % Intan differential gain is 200 V/V
- for sampleNr = 1:tWs
- value16 = fread(obj,nCh,'uint16');
- for k = 1:nCh
-% cData(sampleNr,k) = value16(k) - 16384; % Centers data and scales it to fit the graphs
- cData(sampleNr,k) = value16(k)*LSBweight; % Convert data into volt
- end
- end
- end
+ catch exception
+ error = 1;
+ end
+ %Set warning back to normal state
+ warning(s);
end
View
@@ -23,6 +23,8 @@
% SetDeviceStartAcquisition(),
% Acquire_tWs(), StopAcquisition(). This functions
% has been moved to COMM/AFE folder, into this new script.
+% 2015-1-19 / Enzo Mastinu / The ADS1299 part has been modified in way to be
+ % compatible with the new ADS1299 acquisition mode (DSP + FPU)
% 20xx-xx-xx / Author / Comment
@@ -41,23 +43,17 @@
sT = handles.sT;
nCh = handles.nCh;
sTall = handles.sTall;
-
- % Delete previous connection objects
- if exist('obj')
- fclose(obj);
- delete(obj);
- end
%%%%% WiFi %%%%%
if strcmp(ComPortType, 'WiFi')
%%%%% TI ADS1299 %%%%%
- if strcmp(deviceName, 'ADS1299')
- obj = tcpip('192.168.100.10',65100,'NetworkRole','client'); % WIICOM
- obj.InputBufferSize = sTall*sF*27; % 27bytes data package
+ if strcmp(deviceName, 'ADS_BP')
+ obj = tcpip('192.168.100.10',65100,'NetworkRole','client'); % ADS1299
+ obj.InputBufferSize = sTall*sF*nCh*4;
end
%%%%% INTAN RHA2216 %%%%%
if strcmp(deviceName, 'RHA2216')
- obj = tcpip('192.168.100.10',65100,'NetworkRole','client'); % WIICOM
+ obj = tcpip('192.168.100.10',65100,'NetworkRole','client'); % WIICOM
obj.InputBufferSize = sT*sF*nCh*2;
end
end
@@ -66,8 +62,12 @@
if strcmp(ComPortType, 'COM')
%%%%% TI ADS1299 %%%%%
if strcmp(deviceName, 'ADS1299')
- obj = serial (ComPortName, 'baudrate', 2500000, 'databits', 8, 'byteorder', 'bigEndian');
- obj.InputBufferSize = sTall*sF*27; % 27bytes data package
+ obj = serial (ComPortName, 'baudrate', 2000000, 'databits', 8, 'byteorder', 'bigEndian');
+ obj.InputBufferSize = sTall*sF*27; % 27bytes data package
+ end
+ if strcmp(deviceName, 'ADS_BP')
+ obj = serial (ComPortName, 'baudrate', 460800, 'databits', 8, 'byteorder', 'bigEndian');
+ obj.InputBufferSize = sTall*sF*nCh*4;
end
%%%%% INTAN RHA2216 %%%%%
if strcmp(deviceName, 'RHA2216')
View
@@ -28,13 +28,16 @@
% job
% 2012-05-29 / Max Ortiz / Removed the routine for sequentially adding
% channels to a loop.
+% 2016-02-10 / Max Ortiz / Modifed routine to use chAI directly as a
+% string of numbers identifying each channels
+% as in the GUI
% 20xx-xx-xx / Author / Comment on update
function [s] = InitSBI_NI(sF, sT, chAI, chAO)
% Auxiliar variables
-nChAI = size(chAI,2);
-chAIidx = find(chAI);
+% nChAI = size(chAI,2);
+% chAIidx = find(chAI);
% Close possible daq objects running
if (~isempty(daqfind))
@@ -50,8 +53,8 @@
% Add channels in a loop
-for i = 1 : size(chAIidx,2)
- chID = ['ai' num2str(chAIidx(i)-1)];
+for i = 1 : size(chAI,2)
+ chID = ['ai' num2str(chAI(i)-1)];
s.addAnalogInputChannel(dev.ID,chID,'Voltage');
s.Channels(i).InputType ='SingleEnded';
s.Channels(i).Range = [-5 5];
@@ -23,7 +23,16 @@
% SetDeviceStartAcquisition(),
% Acquire_tWs(), StopAcquisition(). This functions
% has been moved to COMM/AFE folder, into this new script.
-
+% 2015-1-19 / Enzo Mastinu / The ADS1299 part has been modified in way to be
+ % compatible with the new ADS1299 acquisition mode (DSP + FPU)
+% 2015-4-10 / Enzo Mastinu / The ADS1299_DSP acquisition has been optimized, only desired
+ % channels are transmitted to PC, not all as
+ % before. To do that PC sends start command
+ % followed by the number of channels requested
+% 2016-5-9 / Enzo Mastinu / The ADS_BP acquisition has been optimized. Now
+% % sF will be set before starting the recording.
+% % Only some values of sF are allowed.
+
% 20xx-xx-xx / Author / Comment
@@ -35,13 +44,12 @@ function SetDeviceStartAcquisition(handles, obj)
nCh = handles.nCh;
sTall = handles.sTall;
sF = handles.sF;
-
-
+
%%%%% INTAN RHA2216 %%%%%
if strcmp(deviceName, 'RHA2216')
% Setup the selected channels
- vCh = 0:nCh'-1; % Vector of channels
+ vCh = 0:nCh'-1;
fwrite(obj,'C','char');
fwrite(obj,nCh,'uint8');
for i = 1 : nCh
@@ -97,5 +105,58 @@ function SetDeviceStartAcquisition(handles, obj)
return
end
end
+ if strcmp(deviceName, 'ADS_BP')
+ % Set the ADS_BP datarate output
+ if(sF~=500 && sF~=1000 && sF~=2000)
+ disp('The selected sampling frequency is not valid for the ADS_BP. Errors may occur!');
+ errordlg('The selected sampling frequency is not valid for the ADS_BP. Errors may occur!','Erroneous sampling frequency');
+ end
+ fwrite(obj,'T','char');
+ % Read available data and discard it
+ if obj.BytesAvailable > 1
+ fread(obj,obj.BytesAvailable,'uint8');
+ end
+ fwrite(obj,'r','char');
+ replay = char(fread(obj,1,'char'));
+ if strcmp(replay,'r')
+ fwrite(obj,sF,'uint32');
+ replay = char(fread(obj,1,'char'));
+ if strcmp(replay,'r');
+ set(handles.t_msg,'String','sampling frequency set');
+ else
+ set(handles.t_msg,'String','Error Setting sampling frequency');
+ fclose(obj);
+ return
+ end
+ else
+ set(handles.t_msg,'String','Error Setting sampling frequency');
+ fclose(obj);
+ return
+ end
+ % Send the START command
+ fwrite(obj,'G','char');
+ fwrite(obj,nCh,'char');
+ replay = char(fread(obj,1,'char'));
+ switch replay
+ case 'G'
+ set(handles.t_msg,'String','EMG Start');
+ case 'L'
+ set(handles.t_msg,'String','Error: Neuromotus locked');
+ fclose(obj);
+ return
+ case 'B'
+ set(handles.t_msg,'String','Error: Battery Low!');
+ fclose(obj);
+ return
+ end
+ % the digital filtering introduce a transient not needed in recording
+ % session. To avoid that transient we can just skip the first
+ % samples coming from the device
+ settlingTime = 1;
+ settlingSamples = settlingTime*sF;
+ for sampleNr = 1:settlingSamples
+ fread(obj,nCh,'float32');
+ end
+ end
end
@@ -42,5 +42,9 @@ function StopAcquisition(deviceName, obj)
fwrite(obj,'G','char'); % Stop the aquisition ´
fclose(obj); % Close connection
end
+ if strcmp(deviceName, 'ADS_BP')
+ fwrite(obj,'T','char'); % Stop the aquisition ´
+ fclose(obj); % Close connection
+ end
end
@@ -1,39 +0,0 @@
-% ---------------------------- Copyright Notice ---------------------------
-% This file is part of BioPatRec © which is open and free software under
-% the GNU Lesser General Public License (LGPL). See the file "LICENSE" for
-% the full license governing this code and copyrights.
-%
-% BioPatRec was initially developed by Max J. Ortiz C. at Integrum AB and
-% Chalmers University of Technology. All authors’ contributions must be kept
-% acknowledged below in the section "Updates % Contributors".
-%
-% Would you like to contribute to science and sum efforts to improve
-% amputees’ quality of life? Join this project! or, send your comments to:
-% maxo@chalmers.se.
-%
-% The entire copyright notice must be kept in this or any source file
-% linked to BioPatRec. This will ensure communication with all authors and
-% acknowledge contributions here and in the project web page (optional).
-% ------------------- Function Description ------------------
-% Function to create the communicatio object
-
-% --------------------------Updates--------------------------
-% 2011-11-09 / Max Ortiz / Creation
-% 20xx-xx-xx / Author / Comment
-
-
-
-function obj = Connect_ALC(conn)
- %conn, Connection String
- %Find serial port objects with specified property values
- obj.io=instrfind('Status','open');
- if isempty(obj.io)
- obj.io=serial(conn, 'BaudRate', 14400);
- pause(1)
- % Open io for read and write access
- set(obj.io,'InputBuffer',1024*64)
- fopen(obj.io)
- pause(1)
- end
-
-end
Binary file not shown.
Oops, something went wrong.

0 comments on commit 1da2a22

Please sign in to comment.