Post Go back to editing

Adalm2000 matlab analog example

Hi there, 

I'm enabling one of the analog input channels on my Adalm2000 using the following Matlab code:

%% Setup
import clib.libm2k.libm2k.*
m2k = context.m2kOpen("ip:");
%% Calibrate
%% Set up devices
ain = m2k.getAnalogIn();
%% Enables analog channels
%% Collect analog data
data = ain.getSamplesInterleaved(80000);
data = data.double;
% clib.libm2k.libm2k.context.contextCloseAll();
% clear m2k
However the data plotted is not correct. If I enabled Scopy running in the background I can get the correct input waveform. If I close the  Scopy the waveform is not correct again. What parameters I'm missing in the Matlab code?
Best wishes,

[edited by: kellybritney at 9:02 PM (GMT -4) on 6 Sep 2022]
  • Hi,

    Can you provide some more details about the version of Matlab and libm2k (base and bindings) that you are using?
    I see that you use: "data = ain.getSamplesInterleaved(80000);" and I assume you are using an older libm2k-matlab release, could you confirm?

    This method changed in the latest release and is now called: " data = ain.getSamplesInterleaved_matlab(80000); "
    Do you have the possibility to update to the latest libm2k-matlab release?

    Using an old version of libm2k could cause the issue you are describing. The calibration process was improved in the new versions. This might explain why using Scopy in the background makes it work fine (if Scopy has some newer version).

    Thank you!

  • Hi Alexandra, thanks for the reply. My Matlab is R2022a (installed on Windows) and the toolbox installed is v20.1.1 (which is the latest version available from Matlab, installed by using Matlab add-ons). The analog script is still using getSamplesInterleaved(80000). I've noticed that there is a v20.1.2 from Github which as you said uses getSamplesInterleaved_matlab(80000) (also is said to be compatible with at least R2021a), but the toolbox causes crashes of the Matlab when running the script. Should I downgrade my Matlab to R2020a?


  • Hi,

    We just tested the 20.1.2 installer from Github with Matlab R2022a and it worked fine.

    Could you check the following path : "C:\Users\<your username>\AppData\Roaming\MathWorks\MATLAB Add-Ons\Toolboxes" and let us know if you have any libm2k related directories?

    Did you uninstall the previous 20.1.1 from the Add-On Manager before installing this one? If not, could you uninstall the libm2k Toolbox first and then install the desired version?

    After uninstalling you should not have any directory related to libm2k in the location mentioned above. If you installed 2 separate versions, there might have been 2 directories created there, and the scripts were not using the correct one.

    Thank you!

  • Yes there are multiple copies of the libm2k binding files and I've tried to delete them and reinstall v20.1.2. The rest code is fine, but data = ain.getSamplesInterleaved_matlab(1000) will cause crash of my Matlab. 


  • "ain.getSamplesInterleaved_matlab " should be used for v20.1.0 while " ain.getSamplesInterleaved" would work for all the older versions.

    Can you run " disp(clib.libm2k.libm2k.context.getVersion() " and let us know what version is displayed?