Transmission and Reception through MATLAB-LimeSDR interface

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) 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 = Amcos(2piFmt);

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 = Accos(2piFct + sin(2piFm*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(+1i2piFif*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(-1i2piFif*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 = 2X_t_cap.cos(2piFc*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 = Accos(sin(2piFmt));

[ 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 = -2X_t_cap.sin(2piFc*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 = Acsin(sin(2piFmt));

[ 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 = 2piFiltered_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"

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

1 Like