# Transmission and Reception through MATLAB-LimeSDR interface

**URL:** <https://discourse.myriadrf.org/t/transmission-and-reception-through-matlab-limesdr-interface/5111>\
**Category:** LimeSDR\
**Created:** [5 September 2019 09:25 UTC](https://discourse.myriadrf.org/t/transmission-and-reception-through-matlab-limesdr-interface/5111 "2019-09-05T09:25:33Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![BLACKAGAIN](https://avatars.discourse-cdn.com/v4/letter/b/958977/32.png) [@BLACKAGAIN](https://discourse.myriadrf.org/u/BLACKAGAIN)\
**Post date:** [5 September 2019 09:25 UTC](https://discourse.myriadrf.org/t/transmission-and-reception-through-matlab-limesdr-interface/5111/1 "2019-09-05T09:25:33Z")

</div>

Hello everyone,  
I am connecting TX1\_1 of LimeSDR with RX1\_L using the cable provided with the kit. Also i am using the MATLAB-LimeSDR interface ([GitHub - jocover/Simulink-MATLAB-LimeSDR: Simulink blockset and MATLAB functions to interface with LimeSDR](https://github.com/jocover/Simulink-MATLAB-LimeSDR)) to connect and use LimeSDR.

The following is the attached code to generate a sinusoidal waveform and transmit and receive back through the LimeSDR:

> %% MATLAB Initialization  
> close all  
> clear all  
> clc  
> %% Sine Wave Transmission-Reception Parameter Initialization  
> Fs = 2e6;  
> Time = 5;
> 
> t = 0 : (1/Fs) : (Time - (1/Fs));
> 
> Fm = 50e3;  
> Am = 1;  
> Fc = 100e3;  
> %Fc = 0;  
> Ac = 1;
> 
> Fif = 0.5e6;  
> Fosc = 80e6;  
> %% Sine Wave Generation  
> S\_t = Am_cos(2_pi_Fm_t);
> 
> figure(1)  
> plot(t, S\_t);  
> xlabel ( ‘Time (in secs)’ );  
> ylabel ( ‘Amplitude (in volts)’);  
> title ( ‘Original Message Signal in Time Domain’);
> 
> [Message\_Signal\_Spectrum] = fftshift (fft (S\_t));  
> dF = Fs/length(t); % hertz  
> f = -Fs/2: dF: Fs/2-dF; % hertz  
> figure(2)  
> plot (f, abs (Message\_Signal\_Spectrum) / length(t));  
> xlabel ( ‘Frequency (in hertz)’ );  
> ylabel ( ‘Amplitude (in volts)’);  
> title ( ‘Magnitude Response of Original Message Signal’ );  
> %% FM Signal Generation  
> X\_t = Ac_cos(2_pi_Fc_t + sin(2_pi_Fm\*t));
> 
> [Modulated\_Signal\_Spectrum] = fftshift (fft (X\_t));  
> dF = Fs/length(t); % hertz  
> f = -Fs/2: dF: Fs/2-dF; % hertz  
> figure(3)  
> plot (f, abs (Modulated\_Signal\_Spectrum) / length(t));  
> xlabel ( ‘Frequency (in hertz)’ );  
> ylabel ( ‘Amplitude (in volts)’);  
> title ( ‘Magnitude Response of FM Modulated Carrier Signal’ );  
> %% Transmit Signal Generation (For Transmission Through LimeSDR)  
> Z\_t = X\_t._exp(+1i_2_pi_Fif\*t);
> 
> [Transmitted\_Signal\_Spectrum] = fftshift (fft (Z\_t));  
> dF = Fs/length(t); % hertz  
> f = -Fs/2: dF: Fs/2-dF; % hertz  
> figure(4)  
> plot (f, abs (Transmitted\_Signal\_Spectrum) / length(t));  
> xlabel ( ‘Frequency (in hertz)’ );  
> ylabel ( ‘Amplitude (in volts)’);  
> title ( ‘Magnitude Response of Transmited Signal’ );  
> %% Transmission Through LimeSDR  
> [FlagSuccessTransmit] = Transmission(Z\_t, Fs, Fosc);  
> %% Reception Through LimeSDR  
> [Samples\_Received, FlagSuccessReceive] = Reception(Fs, Fosc);
> 
> % Samples\_Received = Z\_t’;
> 
> [Linear\_Received\_Signal\_Spectrum] = fftshift (fft (Samples\_Received));  
> dF = Fs/length(t); % hertz  
> f = -Fs/2: dF: Fs/2-dF; % hertz  
> figure(5)  
> plot(f, abs (Linear\_Received\_Signal\_Spectrum) / length(t));  
> xlabel ( ‘Frequency (in hertz)’ );  
> ylabel ( ‘Amplitude (in volts)’);  
> title ( ‘Linear Magnitude Response of Received Signal’ );
> 
> [Logarithmic\_Received\_Signal\_Spectrum] = fftshift (fft (Samples\_Received));  
> dF = Fs/length(t); % hertz  
> f = -Fs/2: dF: Fs/2-dF; % hertz  
> figure(6)  
> semilogy(f, abs (Logarithmic\_Received\_Signal\_Spectrum) / length(t));  
> xlabel ( ‘Frequency (in hertz)’ );  
> ylabel ( ‘Amplitude (in volts)’);  
> title ( ‘Logarithmic Magnitude Response of Received Signal’ );  
> %% DownConversion of Received Signal To BaseBand  
> X\_t\_cap = (Samples\_Received)'._exp(-1i_2_pi_Fif\*t);
> 
> [DownConverted\_Received\_Signal\_Spectrum] = fftshift (fft (X\_t\_cap));  
> dF = Fs/length(t); % hertz  
> f = -Fs/2: dF: Fs/2-dF; % hertz  
> figure(7)  
> plot (f, abs (DownConverted\_Received\_Signal\_Spectrum) / length(t));  
> xlabel ( ‘Frequency (in hertz)’ );  
> ylabel ( ‘Amplitude (in volts)’);  
> title ( ‘Magnitude Response of DownConverted Received Signal’ );
> 
> %% Defination Of LowPass Filter for Generation Of InPhase And QuadraturePhase Components  
> fsamp1 = Fs;  
> fcuts1 = [Fc 1.5\*Fc];  
> mags1 = [1 0];  
> devs1 = [0.05 0.01];
> 
> [n1, Wn1, Beta1, ftype1] = kaiserord(fcuts1,mags1,devs1,fsamp1);
> 
> LPF1 = fir1(n1, Wn1, ftype1, kaiser(n1+1, Beta1), ‘noscale’);  
> %% Generation Of InPhase Component And Comparision To Theorotical InPhase Signal  
> X\_t\_cap\_InPhase\_UnFiltered = 2_X\_t\_cap.cos(2pi_Fc\*t);
> 
> [InPhase\_Unfiltered\_Spectrum] = fftshift (fft (X\_t\_cap\_InPhase\_UnFiltered));  
> dF = Fs/length(t); % hertz  
> f = -Fs/2: dF: Fs/2-dF; % hertz  
> figure(8)  
> plot (f, abs (InPhase\_Unfiltered\_Spectrum) / length(t));  
> xlabel ( ‘Frequency (in hertz)’ );  
> ylabel ( ‘Amplitude (in volts)’);  
> title ( ‘Magnitude Response of InPhase Unfiltered Signal’ );
> 
> X\_t\_cap\_InPhase\_Filtered = filter(LPF1,1,X\_t\_cap\_InPhase\_UnFiltered);
> 
> [InPhase\_filtered\_Spectrum] = fftshift (fft (X\_t\_cap\_InPhase\_Filtered));  
> dF = Fs/length(t); % hertz  
> f = -Fs/2: dF: Fs/2-dF; % hertz  
> figure(9)  
> plot (f, abs (InPhase\_filtered\_Spectrum) / length(t));  
> xlabel ( ‘Frequency (in hertz)’ );  
> ylabel ( ‘Amplitude (in volts)’);  
> title ( ‘Magnitude Response of InPhase Filtered Signal’ );
> 
> Theorotical\_InPhase\_Component = Ac_cos(sin(2_pi_Fm_t));
> 
> [Theorotical\_InPhase\_Spectrum] = fftshift (fft (Theorotical\_InPhase\_Component));  
> dF = Fs/length(t); % hertz  
> f = -Fs/2: dF: Fs/2-dF; % hertz  
> figure(10)  
> plot (f, abs (Theorotical\_InPhase\_Spectrum) / length(t));  
> xlabel ( ‘Frequency (in hertz)’ );  
> ylabel ( ‘Amplitude (in volts)’);  
> title ( ‘Magnitude Response of Theorotical InPhase Signal’ );  
> %% Generation Of QuadPhase Component And Comparision To Theorotical QuadPhase Signal  
> X\_t\_cap\_QuadPhase\_UnFiltered = -2_X\_t\_cap.sin(2pi_Fc\*t);
> 
> [QuadPhase\_Unfiltered\_Spectrum] = fftshift (fft (X\_t\_cap\_QuadPhase\_UnFiltered));  
> dF = Fs/length(t); % hertz  
> f = -Fs/2: dF: Fs/2-dF; % hertz  
> figure(11)  
> plot (f, abs (QuadPhase\_Unfiltered\_Spectrum) / length(t));  
> xlabel ( ‘Frequency (in hertz)’ );  
> ylabel ( ‘Amplitude (in volts)’);  
> title ( ‘Magnitude Response of QuadPhase Unfiltered Signal’ );
> 
> X\_t\_cap\_QuadPhase\_Filtered = filter(LPF1,1,X\_t\_cap\_QuadPhase\_UnFiltered);
> 
> [QuadPhase\_filtered\_Spectrum] = fftshift (fft (X\_t\_cap\_QuadPhase\_Filtered));  
> dF = Fs/length(t); % hertz  
> f = -Fs/2: dF: Fs/2-dF; % hertz  
> figure(12)  
> plot (f, abs (QuadPhase\_filtered\_Spectrum) / length(t));  
> xlabel ( ‘Frequency (in hertz)’ );  
> ylabel ( ‘Amplitude (in volts)’);  
> title ( ‘Magnitude Response of QuadPhase Filtered Signal’ );
> 
> Theorotical\_QuadPhase\_Component = Ac_sin(sin(2_pi_Fm_t));
> 
> [Theorotical\_QuadPhase\_Spectrum] = fftshift (fft (Theorotical\_QuadPhase\_Component));  
> dF = Fs/length(t); % hertz  
> f = -Fs/2: dF: Fs/2-dF; % hertz  
> figure(13)  
> plot (f, abs (Theorotical\_QuadPhase\_Spectrum) / length(t));  
> xlabel ( ‘Frequency (in hertz)’ );  
> ylabel ( ‘Amplitude (in volts)’);  
> title ( ‘Magnitude Response of Theorotical QuadPhase Signal’ );  
> %% FM Demodulation And Filtering(To Remove Out-Of\_Band Components) And Amplitude Correction  
> Y\_Real = X\_t\_cap\_InPhase\_Filtered’;
> 
> Y\_Imag = X\_t\_cap\_QuadPhase\_Filtered’;
> 
> Y\_Real\_Delayed\_By\_One\_Time\_Unit = [0;Y\_Real(1:end-1)];
> 
> Y\_Imag\_Delayed\_By\_One\_Time\_Unit = [0;Y\_Imag(1:end-1)];
> 
> Y\_Demodulated\_Data = (Y\_Real.\*Y\_Imag\_Delayed\_By\_One\_Time\_Unit - Y\_Imag.\*Y\_Real\_Delayed\_By\_One\_Time\_Unit)./(Y\_Real.\*Y\_Real + Y\_Imag.\*Y\_Imag);
> 
> [Demodulated\_Signal\_Spectrum] = fftshift (fft (Y\_Demodulated\_Data));  
> dF = Fs/length(t); % hertz  
> f = -Fs/2: dF: Fs/2-dF; % hertz  
> figure(14)  
> plot (f, abs (Demodulated\_Signal\_Spectrum) / length(t));  
> xlabel ( ‘Frequency (in hertz)’ );  
> ylabel ( ‘Amplitude (in volts)’);  
> title ( ‘Magnitude Response of Demodulated Signal’ );
> 
> figure(15)  
> plot(t, (Y\_Demodulated\_Data))  
> xlabel ( ‘Time (in secs)’ );  
> ylabel ( ‘Amplitude (in volts)’);  
> title ( ‘Time Domain Demodulated Signal’ );
> 
> fsamp2 = Fs;  
> fcuts2 = [Fm 1.05\*Fm];  
> mags2 = [1 0];  
> devs2 = [0.05 0.01];
> 
> [n2, Wn2, Beta2, ftype2] = kaiserord(fcuts2,mags2,devs2,fsamp2);
> 
> LPF2 = fir1(n2, Wn2, ftype2, kaiser(n2+1, Beta2), ‘noscale’);
> 
> Filtered\_Y\_Demodulated\_Data = filter(LPF2,1,Y\_Demodulated\_Data);
> 
> Filtered\_Y\_Demodulated\_Data = 2_pi_Filtered\_Y\_Demodulated\_Data;
> 
> [Filtered\_Y\_Demodulated\_Data\_Spectrum] = fftshift (fft (Filtered\_Y\_Demodulated\_Data));  
> dF = Fs/length(t); % hertz  
> f = -Fs/2: dF: Fs/2-dF; % hertz  
> figure(16)  
> plot (f, abs (Filtered\_Y\_Demodulated\_Data\_Spectrum) / length(t));  
> xlabel ( ‘Frequency (in hertz)’ );  
> ylabel ( ‘Amplitude (in volts)’);  
> title ( ‘Magnitude Response of Filtered Demodulated Signal’ );
> 
> figure(17)  
> plot(t, abs(Filtered\_Y\_Demodulated\_Data));  
> xlabel ( ‘Time (in secs)’ );  
> ylabel ( ‘Amplitude (in volts)’);  
> title ( ‘Iime Domain Filtered Demodulated Signal’ );

I attach 2 results of this code: “Input original spectrum” and "output demodulated spectrum"

 ![Copy_of_Magnitude%20Response%20of%20Filtered%20Demodulated%20Signal](https://canada1.discourse-cdn.com/flex034/uploads/myriadrf/original/2X/c/cd9481ef31204620882a7833222c39a73b8520e9.jpeg) ![Copy_of_Magnitude%20Response%20of%20Original%20Message%20Signal](https://canada1.discourse-cdn.com/flex034/uploads/myriadrf/original/2X/3/3392aaee840b3fe3be8a25081189197d576ef0eb.jpeg)

As you can see, the plots are not at all the same.

Can someone please tell me what i am missing?

Please look at my MATLAB code too.

Thanks a lot
