How can I interface BITalino with Matlab / Simulink?

Python, Java, Android OS, etc.
BITalino
Site Admin
Posts: 567
Joined: Tue Aug 27, 2013 3:47 pm

Re: How can I interface BITalino with Matlab / Simulink?

Postby BITalino » Sat Nov 08, 2014 9:00 am

Hi,

The call to the read(...) method is what actually retrieves the data, so any code for real-time plotting or processing should be added after that.

What you get in return to the read(...) call is a M x nSamples matrix, where nSamples is your requested number of samples and M is the data sent by the device.

M is variable depending on the analogChannels you've chosen to acquire, nonetheless each column should contain the structure described here:
http://forum.bitalino.com/viewtopic.php?t=29#p246

Note that the device can stream data at up to 1000Hz, which means that you'll need to had the calls to the read(...) method in some type of loop.

In order to plot the data in real time, you may want to look into Matlab's drawnow function, which forces the data to be drawn ASAP:
http://www.mathworks.com/help/matlab/ref/drawnow.html

Yet another detail that may be relevant for your intended use is the choice nSamples; a few recommendations can be found in the following thread:
http://forum.bitalino.com/viewtopic.php?f=13&t=129#p227

Hope you found this information useful. Do feel free to contact us for any further question you may have.

Best regards,
The BITalino Team

carlos arroyo
Posts: 8
Joined: Sun Feb 08, 2015 8:04 am

Re: How can I interface BITalino with Matlab / Simulink?

Postby carlos arroyo » Sun Feb 08, 2015 8:19 am

hello, I have a problem with the test API.m and with the Bitalino.m. once I run the code it displays this error message:

Undefined function or variable 'decoding'.

Error in bitalino (line 25)
self.decode = decoding;

Error in testAPI (line 10)
bit = bitalino();

I already put the correct mac address and open signal adquisition is working well.
I hope that you can help me with this.

BITalino
Site Admin
Posts: 567
Joined: Tue Aug 27, 2013 3:47 pm

Re: How can I interface BITalino with Matlab / Simulink?

Postby BITalino » Sun Feb 08, 2015 9:05 am

The Matlab API depends on the BlueCove driver and on a .jar library bundled with the API.

Please confirm if the library is in the correct directory and if you have BlueCove installed.

Best regards,
The BITalino Team

carlos arroyo
Posts: 8
Joined: Sun Feb 08, 2015 8:04 am

Re: How can I interface BITalino with Matlab / Simulink?

Postby carlos arroyo » Sun Feb 08, 2015 6:56 pm

thanks a lot. I forgot to add the lib folder to the directory path.

BITalino
Site Admin
Posts: 567
Joined: Tue Aug 27, 2013 3:47 pm

Re: How can I interface BITalino with Matlab / Simulink?

Postby BITalino » Sun Feb 08, 2015 8:29 pm

We're glad it worked. Anything else you need just let us know ;)

Best regards,
The BITalino Team

anaritam
Posts: 5
Joined: Fri Nov 07, 2014 8:21 pm

Re: How can I interface BITalino with Matlab / Simulink?

Postby anaritam » Fri Feb 13, 2015 1:05 pm

Hi again,

So, I'm having some problems with the display of the signal from 2 EMG sensors.
I'm using channels A3 and A4 so I used analogChannels = [3 4]. Then, when I'm reading the signal, I store each channel in a different array, just like this:

data=bit.read();
data_acq(1,:)=data(6,:);
data_acq(2,:)=data(7,:);

The problem is that if I just touch in one of the sensors the signal in the other channel has the same behaviour as the one I just touched (something that doesn't happen if I use Open Signals). It seems that the signals are exactly the same, just in a different scale. Even the FFT of the 2 signals are the same (only the "amplitude" of each frequency is different). I don't know if I'm doing something wrong or not...

Thanks ;)

BITalino
Site Admin
Posts: 567
Joined: Tue Aug 27, 2013 3:47 pm

Re: How can I interface BITalino with Matlab / Simulink?

Postby BITalino » Sat Feb 14, 2015 1:57 pm

Hi there,

Could you try acquiring all analog channels and see if the problem still persists?

Thanks,
The BITalino Team

anaritam
Posts: 5
Joined: Fri Nov 07, 2014 8:21 pm

Re: How can I interface BITalino with Matlab / Simulink?

Postby anaritam » Mon Feb 16, 2015 9:53 am

Hi again,

I also tried that and this is what I get:

http://s21.postimg.org/gs555izbr/untitled.jpg

Apart from all the noise, it's seems that channel A3 is beeing stored at data(7,:) instead of data(8,:) and subplots 1, 3 and 4 (which means data(6,:), data (8,:) and data(9,:) ) all show the same signal only with a scale difference (I'm only using channel A3 and A4)

This is the code that I used (can't find where the problem is):

Code: Select all

SamplingRate = 1000;
analogChannels = [1 2 3 4 5];

acq_time = 60; %in seconds

nSamples = acq_time*SamplingRate;

bit = bitalino();
bit = bit.open(mac,SamplingRate);

if bit.connection

    bit.version();
    pause(2);
   
    tg = transpose( 1/SamplingRate : 1/SamplingRate : nSamples/SamplingRate );
    time = transpose( linspace( 0 , max(tg) , nSamples ) );
   
    data_acq = NaN(6,nSamples);

    subplot(3,2,1)
    h1=plot( time,data_acq(1,:),'-k' );
    title('EMG Signal - Channel 1','Fontsize',14);
    xlabel('Time (s)','Fontsize',14)

    subplot(3,2,2)
    h2=plot(time,data_acq(2,:),'-k');
    title('EMG Signal - Channel 2','Fontsize',14);
    xlabel('Time (s)','Fontsize',14)

    subplot(3,2,3)
    h3=plot(time,data_acq(3,:),'-k');
    title('EMG Signal - Channel 3','Fontsize',14);
    xlabel('Time (s)','Fontsize',14)

    subplot(3,2,4)
    h4=plot(time,data_acq(4,:),'-k');
    title('EMG Signal - Channel 4','Fontsize',14);
    xlabel('Time (s)','Fontsize',14)

    subplot(3,2,5)
    h5=plot(time,data_acq(5,:),'-k');
    title('EMG Signal - Channel 5','Fontsize',14);
    xlabel('Time (s)','Fontsize',14)

    bit = bit.start(analogChannels);

    plotedSamples=0;

    win = 100;
   
    while plotedSamples<nSamples
       
          data = bit.read(win);
         
          %Data from Channel 1
          data_acq(1,plotedSamples + 1 : plotedSamples + win) = data(6,:);
         
          %Data from Channel 2
          data_acq(2,plotedSamples + 1 : plotedSamples + win)  = data(7,:);
         
          %Data from Channel 3
          data_acq(3,plotedSamples + 1 : plotedSamples + win) = data(8,:);
         
          %Data from Channel 4
          data_acq(4,plotedSamples + 1 : plotedSamples + win) = data(9,:);
         
          %Data from Channel 5
          data_acq(5,plotedSamples + 1 : plotedSamples + win) = data(10,:);
         
          set( h1 , 'ydata' , data_acq(1,:) );

          set( h2 , 'ydata' , data_acq(2,:) );

          set( h3 , 'ydata' , data_acq(3,:) );

          set( h4 , 'ydata' , data_acq(4,:) );

          set( h5 , 'ydata' , data_acq(5,:) );
         
          drawnow
       
          plotedSamples=plotedSamples+win;
         
    end
   
    %stop acquisition
    bit.stop();
end

%close connection
bit.close();

anaritam
Posts: 5
Joined: Fri Nov 07, 2014 8:21 pm

Re: How can I interface BITalino with Matlab / Simulink?

Postby anaritam » Mon Feb 16, 2015 11:25 am

So, I already understood that channel A1 corresponds to analogChannel = [0] and not analogChannel = [1]. Didn't thought about it because in matlab normally everything starts in 1 and there was no A0 channel on the board. Still don't understand why there is signals being acquired and displayed in channels that I'm not using... Is there any explanation for this?

Thanks,
Ana

BITalino
Site Admin
Posts: 567
Joined: Tue Aug 27, 2013 3:47 pm

Re: How can I interface BITalino with Matlab / Simulink?

Postby BITalino » Mon Feb 16, 2015 11:17 pm

Hi Ana,

The Matlab API builds upon our reference implementation in Python (where indexing starts in 0), although its definitely something to review in a next iteration.

As you've seen, the Matlab API has been community-contributed... we haven't been able to check but it may have been designed for an earlier version of BITalino where the channel mapping had a different setup.

We have the redesign of the Matlab API on our work pipeline, but unfortunately other tasks with higher priority have prevented us from addressing it so far. Hope that the current version is manageable to use as-is for your intended use.

Contact us at bitalino@plux.info in case its not, and we'll do our best to turnaround a new version of the Matlab API within a (hopefully) reasonable time frame.

Best regards,
The BITalino Team


Return to “Programming APIs”




cron