# Need Limesdr demo code for Tx/Rx in Matlab

**URL:** <https://discourse.myriadrf.org/t/need-limesdr-demo-code-for-tx-rx-in-matlab/2278>\
**Category:** LimeSDR\
**Created:** [22 January 2018 06:43 UTC](https://discourse.myriadrf.org/t/need-limesdr-demo-code-for-tx-rx-in-matlab/2278 "2018-01-22T06:43:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rochesterlmg](https://avatars.discourse-cdn.com/v4/letter/r/e95f7d/32.png) [@rochesterlmg](https://discourse.myriadrf.org/u/rochesterlmg)\
**Post date:** [22 January 2018 06:43 UTC](https://discourse.myriadrf.org/t/need-limesdr-demo-code-for-tx-rx-in-matlab/2278/1 "2018-01-22T06:43:03Z")

</div>

please share it with us if anyone have demo code for for Tx/Rx in Matlab.  
thanks!

> **[jocover/Simulink-MATLAB-LimeSDR](https://github.com/jocover/Simulink-MATLAB-LimeSDR)**
>
> Simulink blockset and MATLAB functions to interface with LimeSDR - jocover/Simulink-MATLAB-LimeSDR

I have use jocover’s interface for MATLAB-LimeSDR to captrue bluetooth signal successfully. But I need to more documents for Simulink-MATLAB-LimeSDR in detail to control LimeSDR 's Tx/Rx in Matlab.

below code can capture FM signal  
% LimeSDR MATLAB interface  
%  
% (1) Open a device handle:  
%  
dev = limeSDR(); % Open device  
%  
% (2) Setup device parameters. These may be changed while the device  
% is actively streaming.  
%  
dev.rx0.frequency = 93.4e6;  
dev.rx0.samplerate = 5e6;  
dev.rx0.gain = 30;  
dev.rx0.antenna = 2;  
%  
% (3) Enable stream parameters. These may NOT be changed while the device  
% is streaming.  
%  
dev.rx0.enable;  
%  
% (4) Start the module  
%  
dev.start();  
%  
% (5) Receive 5000 samples on RX0 channel  
%  
samples = dev.receive(5000,0);  
Fs=dev.rx0.samplerate;  
spectrum\_plot(Fs,samples)  
%  
% (6) Cleanup and shutdown by stopping the RX stream and having MATLAB  
% delete the handle object.  
%  
dev.stop();  
clear dev;

---

<div class="post-metadata">

**Author:** ![rochesterlmg](https://avatars.discourse-cdn.com/v4/letter/r/e95f7d/32.png) [@rochesterlmg](https://discourse.myriadrf.org/u/rochesterlmg)\
**Post date:** [22 January 2018 07:09 UTC](https://discourse.myriadrf.org/t/need-limesdr-demo-code-for-tx-rx-in-matlab/2278/2 "2018-01-22T07:09:20Z")

</div>

dev = limeSDR(); % does it complete below steps  
a. limeSDR.load\_library(); %load lib  
b. limeSDR.check\_status(calllib(‘libLimeSuite’, ‘LMS\_Open’, dptr,pdevlist,0)); %open Limesdr  
c. limeSDR.check\_status(calllib(‘libLimeSuite’, ‘LMS\_Init’, dptr));%init Limesdr

I guess ‘samples = dev.receive(5000,0);’ will call below function, but I don’t understand how match ‘receive(5000,0);’ with  
’ receive(obj, num\_samples, chan,timeout\_ms, timestamp\_in)’.

function [samples, timestamp\_out, actual\_count, overrun] = receive(obj, num\_samples, chan,timeout\_ms, timestamp\_in)

```
        if nargin < 3
            chan = 0;
        end
        
        if nargin < 4
            timeout_ms = 1000;
        end
        
        if nargin < 5
            timestamp_in = 0;
        end
        
        if ~obj.running
            error('please start device');
        end
        
        f32=single(zeros(2*num_samples, 1));
        
        metad = libstruct('lms_stream_meta_t');
        
        if timestamp_in == 0
            metad.waitForTimestamp=false;
        else
            metad.waitForTimestamp=true;
        end
        metad.timestamp=timestamp_in;
        if chan==0
            rx_stream=obj.rx0_stream;
            if isempty(rx_stream)
                error('rx0 stream not enabled');
            end
        else
            rx_stream=obj.rx1_stream;
            
            if isempty(rx_stream)
                error('rx1 stream not enabled');
            end
        end
        
        [actual_count, ~, f32, ~]=calllib('libLimeSuite', 'LMS_RecvStream', rx_stream,f32,num_samples,metad,timeout_ms);
        samples=(double(f32(1:2:end)) + double(f32(2:2:end))*1j);
        timestamp_out = metad.timestamp;
    end
```

---

<div class="post-metadata">

**Author:** ![rochesterlmg](https://avatars.discourse-cdn.com/v4/letter/r/e95f7d/32.png) [@rochesterlmg](https://discourse.myriadrf.org/u/rochesterlmg)\
**Post date:** [13 February 2018 23:13 UTC](https://discourse.myriadrf.org/t/need-limesdr-demo-code-for-tx-rx-in-matlab/2278/3 "2018-02-13T23:13:59Z")

</div>

hi, guys!  
could you share your FM transmitter code in matlab, which can transmitter a mp3 file through sdrlime?  
thanks!
