Commit 8ef4ab12 authored by Florian Kaltenberger's avatar Florian Kaltenberger

removing rest of USERSPACE_TOOLS (unused or depricated)


git-svn-id: http://svn.eurecom.fr/openair4G/trunk@7224 818b1a75-f10b-46b9-bf7c-635c3b92a50f
parent b9ddfe65
This diff is collapsed.
updatefw: updatefw.c
$(CC) updatefw.c -o updatefw -I../../../targets/ARCH/EXMIMO
clean:
rm -f updatefw
This diff is collapsed.
/*******************************************************************************
OpenAirInterface
Copyright(c) 1999 - 2014 Eurecom
OpenAirInterface is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenAirInterface is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OpenAirInterface.The full GNU General Public License is
included in this distribution in the file called "COPYING". If not,
see <http://www.gnu.org/licenses/>.
Contact Information
OpenAirInterface Admin: openair_admin@eurecom.fr
OpenAirInterface Tech : openair_tech@eurecom.fr
OpenAirInterface Dev : openair4g-devel@eurecom.fr
Address : Eurecom, Campus SophiaTech, 450 Route des Chappes, CS 50193 - 06904 Biot Sophia Antipolis cedex, FRANCE
*******************************************************************************/
/*============================================================================
File: elftypes.h
Include file for Elf types. Define elf types for Elf structures.
Copyright Hewlett-Packard Co. 1995. All rights reserved.
============================================================================*/
#ifndef ELFTYPES_INCLUDED
#define ELFTYPES_INCLUDED
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __LP64__
typedef unsigned int Elf32_Addr; /* Unsigned program address */
typedef unsigned int Elf32_Off; /* Unsigned file offset */
typedef int Elf32_Sword; /* Signed large integer */
typedef unsigned int Elf32_Xword; /* Unsigned large integer */
#else
typedef unsigned long Elf32_Addr; /* Unsigned program address */
typedef unsigned long Elf32_Off; /* Unsigned file offset */
typedef long Elf32_Sword; /* Signed large integer */
typedef unsigned long Elf32_Xword; /* Unsigned large integer */
#endif
typedef unsigned int Elf32_Word; /* Unsigned large integer */
typedef unsigned short Elf32_Half; /* Unsigned medium integer */
typedef unsigned char Elf32_Char; /* Unsigned tiny integer */
typedef unsigned char Elf32_Byte; /* Unsigned tiny integer */
#ifdef __LP64__
typedef unsigned long Elf64_Addr;
typedef unsigned long Elf64_Off;
typedef unsigned long Elf64_Xword;
typedef long Elf64_Sxword;
#else
typedef unsigned long long Elf64_Addr;
typedef unsigned long long Elf64_Off;
typedef unsigned long long Elf64_Xword;
typedef long long Elf64_Sxword;
#endif
typedef unsigned short Elf64_Half;
typedef int Elf64_Sword;
typedef unsigned int Elf64_Word;
typedef unsigned char Elf64_Byte; /* Unsigned tiny integer */
#ifdef __cplusplus
}
#endif
#endif /* ELFTYPES_INCLUDED */
This diff is collapsed.
/*******************************************************************************
OpenAirInterface
Copyright(c) 1999 - 2014 Eurecom
OpenAirInterface is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenAirInterface is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OpenAirInterface.The full GNU General Public License is
included in this distribution in the file called "COPYING". If not,
see <http://www.gnu.org/licenses/>.
Contact Information
OpenAirInterface Admin: openair_admin@eurecom.fr
OpenAirInterface Tech : openair_tech@eurecom.fr
OpenAirInterface Dev : openair4g-devel@eurecom.fr
Address : Eurecom, Campus SophiaTech, 450 Route des Chappes, CS 50193 - 06904 Biot Sophia Antipolis cedex, FRANCE
*******************************************************************************/
/*
C Header file <updatefw.h> for updatefw tool.
K. Khalfallah, Aug, 2007
kkhalfallah@free.fr
*/
#ifndef UPDATEFW_H
#define UPDATEFW_H
#include <stdio.h>
#include <errno.h>
#define _testsyscall(x, y, z) {if (x==-1) { \
fprintf(stderr, "Error : %s() returned "z" (errno=%d)\n", y, x, errno); \
fprintf(stderr, "Warning : not leaving normally. Remove ipc ressources by hand !"); \
fprintf(stderr, " (use shell commands ipcs & ipcrm)\n"); \
exit(-1); \
}}
// else { \
// printf("Info : successfully called %s, returned "z"\n", y, x);}}
/* Intel is little-endian, sparc is big */
unsigned long ltmp;
#define invert4(x) {ltmp=x; x=((ltmp & 0xff)<<24) | ((ltmp & 0xff00)<<8) | \
((ltmp & 0xff0000)>>8) | ((ltmp & 0xff000000)>>24); }
unsigned short stmp;
#define invert2(x) {stmp=x; x=((stmp & 0xff)<< 8) | ((stmp & 0xff00)>>8);}
/* static variables, global */
char* virt_addr;
unsigned int packet_ndx = 0;
#define FSEEK_ORIGIN 0
#define FSEEK_CURRENT 1
#define READ_FILE_MODE "r"
/* Verbose levels */
#define VERBOSE_LEVEL_MAIN_STEPS 1
#define VERBOSE_LEVEL_ACCESS_FILES 2
#define VERBOSE_LEVEL_SECTION_DETAILS 3
#define VERBOSE_LEVEL_IOCTL 4
#endif /* UPDATEFW_H */
function [ratio,phi_est]=IQ_estimation(freq)
gpib_card=0; % first GPIB PCI card in the computer
sme=28; % this is configured in the signal generator Utilities->System->GPIB->Address menu (for SME)
gpib_send(gpib_card,sme,'*RST;*CLS'); % reset and configure the signal generator
sleep(.1);
gpib_send(gpib_card,sme,'POW -63dBm');
disp(freq)
gpib_send(gpib_card,sme,strcat('FREQ ',int2str(freq),'MHz'));
gpib_send(gpib_card,sme,'OUTP:STAT ON'); % activate output
cmd1='/homes/nussbaum/openair1/ARCH/LEON3/hostpc/user/tools/scripts/set_receiver -M ';
gain1=61;
gain2=61;
frequency=int2str(freq);
cmd=strcat(cmd1,frequency,' -g1 ',int2str(gain1),' -g2 ',int2str(gain2));
system(cmd);
sleep(.1);
s=oarf_get_frame(0);
signal=s(:,1);
size_data=20480;
Fs=7680; %in kHz
band = 2000; %in kHz
max_pos=0;
max=0;
f=abs(fft(signal)).^2;
for n=2:size_data
if(f(n) > max)
max=f(n);
max_pos=n;
end;
end;
disp(max_pos)
freq_max=Fs/size_data*max_pos - Fs/2 % corresponding frequency
if(abs(freq_max-2000)>100)
disp('Warning')
end;
cumI=0;
cumQ=0;
I=real(signal(1:2000));
Q=imag(signal(1:2000));
for i=1:2000
cumI=cumI + I(i)*I(i);
cumQ=cumQ + Q(i)*Q(i);
end;
amp= sqrt(2*cumI/length(I))
I=I/amp;
Q=Q/amp;
ratio=sqrt(cumI/cumQ)
n_fft=1024;
f=abs(fft(I(1:n_fft)));
max = 0;
index=0;
for i=1:n_fft/2
if f(i)> max
max=f(i);
index=i;
end;
end;
disp(max)
disp(index)
%figure
%plot(20*log10(abs(f)));
freq_estim=(index-1)/n_fft;
p=Q*ratio.*I;
sinphi=2*sum(p)/length(Q);
phi_est=-asin(sinphi)
Qcor=(sin(phi_est)*I+ratio*Q)/cos(phi_est);
%figure
%plot(I(1:100))
%hold on
%plot(Qcor(1:100),'g');
comp=I+j*Qcor;
%hold off
%figure
%plot(20*log10(abs(fft(comp))));
endfunction;
% per=round(1/freq_estim)
% figure;plot(I(1:per+1))
% opt_offset=-5
% min_diff=10^20;
% for offset=0:per
% diff=0;
% for k=1:n_fft
% diff=diff+abs(I(k+offset)-Q(k));
% end;
% if diff<min_diff
% min_diff=diff;
% opt_offset= offset;
% end;
% end;
% disp(opt_offset)
% % normally, as to be 3/4*per
% opt_offset=opt_offset-3*per/4;
% disp(opt_offset/per*2*pi)
s = oarf_get_frame(2);
sig0 = s(:,1);
sig1 = s(:,2);
sig0 = s(5000:end,1); % first channel
sig1 = s(5000:end,2); % 2nd channel
bw=7.68e6;
spec = abs(fft(sig1)).^2;
[a,b] = max(spec);
freq = (b-1)*bw/length(sig0);
L= 1000;
W = 1;
offset_vec = (0:L-1)*((2*W)+1);
W2 = 1+(2*W);
window_vec = (-W : W);
pn = zeros(1,(2*L) - 1);
for i = 1:L,
pn(i+L-1) = sum(spec(offset_vec(i) + b + window_vec));
end
for i = 2:L,
pn(L-i+1) = sum(spec(-offset_vec(i) + b + window_vec));
end
pn_2 = 20*log10(pn / pn(L)) - 10*log10(W2*bw/length(sig0));
f = ((-L+1):(L-1))*W2*bw/length(sig0);
ylabel('dBc/Hz')
xlabel("f_offset (Hz)")
title("Phase Noise @ IQ output for Fc = 1912.6 + Fs/4 MHz CW input at antenna")
semilogx(f(L:(2*L - 1)),pn_2(L:(2*L -1)))
sum(pn.^2*(f(2)-f(1)))
closeplot
figure(1)
gain2391=70; gain9862=0;
for rxrfmode=0:2
i=find( (m(:,2)==gain2391) & (m(:,3)==gain9862) & (m(:,4)==rxrfmode));
plot(m(i,1),m(i,5:8))
pause
end
gain2391=70; rxrfmode=1;
for gain9862=0:5:15
i=find((m(:,2)==gain2391) & (m(:,3)==gain9862) & (m(:,4)==rxrfmode));
plot(m(i,1),m(i,5:8))
pause
end
rxrfmode=1; power_dBm=-70;
i=find((m(:,1)==power_dBm) & (m(:,4)==rxrfmode));
plot(m(i,1),m(i,5:8))
pause
end
power_dBm=-90;
subplot(1,3,1)
rxrfmode=0;
i=find((m(:,1)==power_dBm) & (m(:,4)==rxrfmode));
mesh(0:10:150,[0 5 10 15],reshape(m(i,5)-m(i,6),4,16))
subplot(1,3,2)
rxrfmode=1;
i=find((m(:,1)==power_dBm) & (m(:,4)==rxrfmode));
mesh(0:10:150,[0 5 10 15],reshape(m(i,5)-m(i,6),4,16))
subplot(1,3,3)
rxrfmode=2;
i=find((m(:,1)==power_dBm) & (m(:,4)==rxrfmode));
mesh(0:10:150,[0 5 10 15],reshape(m(i,5)-m(i,6),4,16))
closeplot
figure(1);
%for power_dBm=ALL_power_dBm
for power_dBm=-65
disp(['input: ' num2str(power_dBm) ' dBm']);
xlabel('Gain 2391');
ylabel('Gain 9862');
zlabel('SNR');
rxrfmode=0;
idx=find((m(:,1)==power_dBm) & (m(:,4)==rxrfmode));
M0=zeros(length(ALL_gain2391),length(ALL_gain9862));
M1=zeros(length(ALL_gain2391),length(ALL_gain9862));
for i=idx.'
i1=find(ALL_gain2391==m(i,2));
i2=find(ALL_gain9862==m(i,3));
M0(i1,i2)=m(i,5)-m(i,6);
M1(i1,i2)=m(i,7)-m(i,8);
end
subplot(2,3,1); clg;
title('Channel 0, rxrfmode 0');
mesh(ALL_gain2391,ALL_gain9862,M0.')
subplot(2,3,4); clg;
title('Channel 1, rxrfmode 0');
mesh(ALL_gain2391,ALL_gain9862,M1.')
rxrfmode=1;
idx=find((m(:,1)==power_dBm) & (m(:,4)==rxrfmode));
M0=zeros(length(ALL_gain2391),length(ALL_gain9862));
M1=zeros(length(ALL_gain2391),length(ALL_gain9862));
for i=idx.'
i1=find(ALL_gain2391==m(i,2));
i2=find(ALL_gain9862==m(i,3));
M0(i1,i2)=m(i,5)-m(i,6);
M1(i1,i2)=m(i,7)-m(i,8);
end
subplot(2,3,2); clg;
title('Channel 0, rxrfmode 1');
mesh(ALL_gain2391,ALL_gain9862,M0.')
subplot(2,3,5); clg;
title('Channel 1, rxrfmode 1');
mesh(ALL_gain2391,ALL_gain9862,M1.')
rxrfmode=2;
idx=find((m(:,1)==power_dBm) & (m(:,4)==rxrfmode));
M0=zeros(length(ALL_gain2391),length(ALL_gain9862));
M1=zeros(length(ALL_gain2391),length(ALL_gain9862));
for i=idx.'
i1=find(ALL_gain2391==m(i,2));
i2=find(ALL_gain9862==m(i,3));
M0(i1,i2)=m(i,5)-m(i,6);
M1(i1,i2)=m(i,7)-m(i,8);
end
subplot(2,3,3); clg;
title('Channel 0, rxrfmode 2');
mesh(ALL_gain2391,ALL_gain9862,M0.')
subplot(2,3,6); clg;
title('Channel 1, rxrfmode 2');
mesh(ALL_gain2391,ALL_gain9862,M1.')
pause
end
%frequency = input('Input freq in MHz: ', 's');
% script to setup mxa and sign generator
size_data=20480;
Fs=7680; %sampling freq in kHz
band = 2500; % noise band in kHz
gpib_card=0; % first GPIB PCI card in the computer
sme=28; % this is configured in the signal generator Utilities->System->GPIB->Address menu (for SME)
openair_init;
freq=2000; % normally loop
% first, calculation of IQ missmatch
[ratio,phase]=IQ_estimation(freq);
gpib_send(gpib_card,sme,'*RST;*CLS'); % reset and configure the signal generator
gpib_send(gpib_card,sme,'POW -100dBm');
%disp('FREQ ',int2str(freq),'MHz');
gpib_send(gpib_card,sme,strcat('FREQ ',int2str(freq),'MHz'));
%disp('FREQ ',int2str(freq),'MHz');
%frequency = input('Input freq in MHz: ', 's');
cmd1='/homes/nussbaum/open_freya/arch/openair_CardBus_MIMO1/LEON3/hostpc/user/tools/scripts/set_receiver -M ';
frequency=int2str(freq);
ALL_gain1=0:16:3;
ALL_gain2=0:16:3;
i=0;
for gain1=ALL_gain1
for gain2= ALL_gain2
i=i+1;
end;
end;
table=zeros(i,4);
i=1;
for gain1=ALL_gain1
for gain2=ALL_gain2
cmd=strcat(cmd1,frequency,' -g1 ',int2str(gain1),' -g2 ',int2str(gain2));
system(cmd);
%system('set_receiver -M ' frequency ' -g1 ' int2str(gain1) ' -g2 ' int2str(gain2));
%system('sleep 1');
gpib_send(gpib_card,sme,'OUTP:STAT ON'); % activate output
sleep(.1);
table(i,1)=gain1;
table(i,2)=gain2;
s=oarf_get_frame(0);
plot(20*log10(abs(fft(s(:,1)))))
signal=s(:,1);
max_pos=0;
max=0;
f=abs(fft(signal)).^2;
for n=2:size_data
if(f(n) > max)
max=f(n);
max_pos=n;
end;
end;
disp(max_pos)
freq_max=Fs/size_data*max_pos - Fs/2 % corresponding frequency
if(abs(freq_max-2000)>100)
disp("Warning")
end;
% calculation of the signal power
Pu=sum(f(max_pos-20:max_pos+20))
ns_noise =round((band/Fs)*(size_data/2))
Pnoise=sum(f(max_pos-ns_noise:max_pos+ns_noise))-Pu
plot(10*log10(f))
% plot(10*log10(f(max_pos-ns_noise:max_pos+ns_noise)))
SNR=10*log10(Pu/Pnoise)
N_in = -174 +10*log10(1000*band)
S_in = -100;
SNR_in=S_in - N_in
NF=SNR_in-SNR
i=i+1;
end;
end;
disp(table);
P_num =100; %(warning, to be updated)
% Post processing of the table started here
Pmin = -40; % in dBm
Pmax = 20; % in dBm
% a Tx calibration file is calculated for a given board and frequency
%fid=fopen(['/tmp/cal_TX' frequency '_' int2str(n) '.dat'],'wb')
%fwrite(fid,signal);
%fclose(fid);
% Maxime Guillaud - created Wed May 10 18:08:04 CEST 2006
gpib_card=0; % first GPIB PCI card in the computer
gpib_device=28; % this is configured in the signal generator Utilities->System->GPIB->Address menu
freqband=2; % frequency band used by the openair card
cables_loss_dB = 6; % we need to account for the power loss between the signal generator and the card input (splitter, cables)
gpib_send(gpib_card,gpib_device,'*RST;*CLS'); % reset and configure the signal generator
gpib_send(gpib_card,gpib_device,'POW -70dBm');
gpib_send(gpib_card,gpib_device,'FREQ 1.91452GHz');
oarf_config(freqband,'openair_config.cfg','openair_scenario.scn')
saturation_threshold =5; % min number of samples (real+imaginary) equal to the max per frame to declare saturation
ALL_power_dBm = [-100:1:-60 -150];
ALL_rxrfmode = 0:2;
ALL_gain2391 = 0:5:120; % this is some strange scale
ALL_gain9862 = 0:1:18; % this in in dB
m=[];
%for power_dBm=ALL_power_dBm
power_dBm=-70
gpib_send(gpib_card,gpib_device,['POW ' int2str(power_dBm+cables_loss_dB) 'dBm']);
sleep(1)
for gain9862=ALL_gain9862
for gain2391= ALL_gain2391
gpib_send(gpib_card,gpib_device,'OUTP:STAT ON'); % activate output
oarf_set_rx_gain(gain2391,gain9862,gain2391,gain9862);
nacq=0; % count the number of tries to get data
do
s=oarf_get_frame(freqband); %oarf_get_frame
sleep(.1);
nacq=nacq+1;
until max(max(abs(s)))>0 % ensures that the frame is properly read
for gain9862=ALL_gain9862
for gain2391= ALL_gain2391
SpN0 = mean(abs(s(:,1)).^2) - abs(mean(s(:,1))).^2;
SpN1 = mean(abs(s(:,2)).^2) - abs(mean(s(:,2))).^2;
gpib_send(gpib_card,gpib_device,'OUTP:STAT OFF'); % deactivate output
oarf_set_rx_gain(gain2391,gain9862,gain2391,gain9862);
nacq=0; % count the number of tries to get data
do
sleep(.1);
s=oarf_get_frame(freqband);
nacq=nacq+1;
until max(max(abs(s)))>0 % ensures that the frame is properly read
N0 = mean(abs(s(:,1)).^2) - abs(mean(s(:,1))).^2;
N1 = mean(abs(s(:,2)).^2) - abs(mean(s(:,2))).^2;
<<<<<<< rx_calibration.m
S0 = 10*log10(SpN0-N0);
S1 = 10*log10(SpN1-N1);
G0 = S0 - power_dBm;
G1 = S1 - power_dBm;
NF0 = N0 - G0 + 108;
NF1 = N1 - G1 + 108;
fprintf(' %d %d : Signal strength (%d,%d), Gain (%d %d), NF (%d %d)\n',
gain2391,gain9862, S0,S1,G0,G1,NF0,NF1);
end
end
gpib_send(gpib_card,gpib_device,'OUTP:STAT OFF'); % deactivate output
% Maxime Guillaud - created Wed May 10 18:08:04 CEST 2006
% Raymond & Florian - last modified Fri Oct 26 17:12:10 CEST 2007
gpib_card=0; % first GPIB PCI card in the computer
gpib_device=28; % this is configured in the signal generator Utilities->System->GPIB->Address menu
freqband=2; % frequency band used by the openair card
cables_loss_dB = 6; % we need to account for the power loss between the signal generator and the card input (splitter, cables)
gpib_send(gpib_card,gpib_device,'*RST;*CLS'); % reset and configure the signal generator
gpib_send(gpib_card,gpib_device,'POW -70dBm');
gpib_send(gpib_card,gpib_device,'FREQ 1.91860GHz');
oarf_config(freqband,'openair_config.cfg','openair_scenario.scn')
saturation_threshold =5; % min number of samples (real+imaginary) equal to the max per frame to declare saturation
ALL_power_dBm = [-90];
ALL_rxrfmode = 0:2;
ALL_gain2391 = 0:5:180; % this is some strange scale
ALL_gain9862 = 0; %:1:18; % this in in dB
%fprintf(fid, 'Tx Power (dBm), gain2391, gain9862, Signal strength Rx0, Signal Strength Rx1, Gain Rx0, Gain Rx1, Noise Rx0, Noise Rx1, SNR Rx0, SNR Rx1, NF Rx0, NF Rx1\n');
SpN0 = zeros(length(ALL_power_dBm),length(ALL_gain2391));
SpN1 = zeros(length(ALL_power_dBm),length(ALL_gain2391));
N0 = zeros(length(ALL_power_dBm),length(ALL_gain2391));
N1 = zeros(length(ALL_power_dBm),length(ALL_gain2391));
S0 = zeros(length(ALL_power_dBm),length(ALL_gain2391));
S1 = zeros(length(ALL_power_dBm),length(ALL_gain2391));
G0 = zeros(length(ALL_power_dBm),length(ALL_gain2391));
G1 = zeros(length(ALL_power_dBm),length(ALL_gain2391));
NF0 = zeros(length(ALL_power_dBm),length(ALL_gain2391));
NF1 = zeros(length(ALL_power_dBm),length(ALL_gain2391));
SNR0 = zeros(length(ALL_power_dBm),length(ALL_gain2391));
SNR1 = zeros(length(ALL_power_dBm),length(ALL_gain2391));
min_agc_level = 96; %ceil(min(max(G0,[],1)));
max_agc_level = 150; %floor(max(max(G0,[],1)));
oarf_set_calibrated_rx_gain(0);
idx_power = 1;
for power_dBm=ALL_power_dBm
%power_dBm=-70
%while (min(max(max(G0)),max(max(G1))) <= max_agc_level)
gpib_send(gpib_card,gpib_device,['POW ' int2str(power_dBm+cables_loss_dB) 'dBm']);
sleep(.5)
for gain9862=ALL_gain9862
idx_gain2391 = 1;
for gain2391= ALL_gain2391
gpib_send(gpib_card,gpib_device,'OUTP:STAT ON'); % activate output
oarf_set_rx_gain(gain2391,gain2391,gain9862,gain9862);
nacq=0; % count the number of tries to get data
sleep(.1);
do
s=oarf_get_frame(freqband); %oarf_get_frame
s2 = s(1:8192,:);
sleep(.1);
nacq=nacq+1;
until max(max(abs(s)))>0 % ensures that the frame is properly read
SpN0(idx_power,idx_gain2391) = mean(abs(s2(:,1)).^2) - abs(mean(s2(:,1))).^2;
SpN1(idx_power,idx_gain2391) = mean(abs(s2(:,2)).^2) - abs(mean(s2(:,2))).^2;
gpib_send(gpib_card,gpib_device,'OUTP:STAT OFF'); % deactivate output
figure(1);
hold off
plot(20*log10(abs(fft(s2(:,1)))))
sleep(.1);
nacq=0; % count the number of tries to get data
do
s=oarf_get_frame(freqband); %oarf_get_frame
s2 = s(1:8192,:);
nacq=nacq+1;
until max(max(abs(s)))>0 % ensures that the frame is properly read
N0(idx_power,idx_gain2391) = mean(abs(s2(:,1)).^2) - abs(mean(s2(:,1))).^2;
N1(idx_power,idx_gain2391) = mean(abs(s2(:,2)).^2) - abs(mean(s2(:,2))).^2;
S0(idx_power,idx_gain2391) = 10*log10(SpN0(idx_power,idx_gain2391)-N0(idx_power,idx_gain2391));
S1(idx_power,idx_gain2391) = 10*log10(SpN1(idx_power,idx_gain2391)-N1(idx_power,idx_gain2391));
G0(idx_power,idx_gain2391) = S0(idx_power,idx_gain2391) - power_dBm;
G1(idx_power,idx_gain2391) = S1(idx_power,idx_gain2391) - power_dBm;
NF0(idx_power,idx_gain2391) = 10*log10(N0(idx_power,idx_gain2391)) - G0(idx_power,idx_gain2391) + 108; % 108 is the thermal noise
NF1(idx_power,idx_gain2391) = 10*log10(N1(idx_power,idx_gain2391)) - G1(idx_power,idx_gain2391) + 108;
SNR0(idx_power,idx_gain2391) = S0(idx_power,idx_gain2391)-10*log10(N0(idx_power,idx_gain2391));
SNR1(idx_power,idx_gain2391) = S1(idx_power,idx_gain2391)-10*log10(N1(idx_power,idx_gain2391));
printf(' %d %d : Signal strength (%f,%f), Gain (%f %f), N (%f %f) SNR (%f %f) NF (%f %f)\n',
gain2391,gain9862, S0(idx_power,idx_gain2391),S1(idx_power,idx_gain2391),G0(idx_power,idx_gain2391),G1(idx_power,idx_gain2391),10*log10(N0(idx_power,idx_gain2391)),10*log10(N1(idx_power,idx_gain2391)),SNR0(idx_power,idx_gain2391),SNR1(idx_power,idx_gain2391),NF0(idx_power,idx_gain2391),NF1(idx_power,idx_gain2391));
fflush(stdout);
%fprintf(fid,'%d, %d, %d, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f\n',
% power_dBm,gain2391,gain9862, S0,S1,G0,G1,10*log10(N0),10*log10(N1),SNR0,SNR1,NF0,NF1);
figure(2);
hold off
plot(20*log10(abs(fft(s2(:,1)))))
sleep(.1);
idx_gain2391 = idx_gain2391 + 1;
figure(3)
hold off
plot(ALL_gain2391,G0,'r')
hold on
plot(ALL_gain2391,G1,'b')
legend('Rx0','Rx1');
title('Gains')
figure(4)
hold off
plot(ALL_gain2391,NF0,'r')
hold on
plot(ALL_gain2391,NF1,'b')
legend('Rx0','Rx1');
title('Noise Figure')
end
end
%power_dBm = power_dBm + 20;
idx_power = idx_power + 1;
end
gpib_send(gpib_card,gpib_device,'OUTP:STAT OFF'); % deactivate output
%l0 = [ALL_gain2391; ones(size(ALL_gain2391))].'\G0;
%l1 = [ALL_gain2391; ones(size(ALL_gain2391))].'\G1;
gain_levels = zeros(max_agc_level-min_agc_level+1,2);
gain_levels(:,1) = round(interp1(max(G0,[],1),ALL_gain2391,min_agc_level:max_agc_level,'linear')).';
gain_levels(:,2) = round(interp1(max(G1,[],1),ALL_gain2391,min_agc_level:max_agc_level,'linear')).';
%gain_levels(isnan(gain_levels)) = 0;
write_table
\ No newline at end of file
function out=rx_post(nom,ratio,phase)
%load data.dat signal
%fid=fopen('/tmp/store1.dat',)
fid=fopen(nom,'rb')
signal=fread(fid,20480*2,'float');
disp(signal(1:10));
signal=signal(1:2:length(signal))+j*signal(2:2:length(signal));
size_data=20480;
Fs=7680; %in kHz
band = 2000; %in kHz
max_pos=0;
max=0;
f=abs(fft(signal)).^2;
for n=2:size_data
if(f(n) > max)
max=f(n);
max_pos=n;
end;
end;
disp(max_pos)
freq_max=Fs/size_data*max_pos - Fs/2 % corresponding frequency
if(abs(freq_max-2000)>100)
disp('Warning')
end;
% calculation of the signal power
Pu=sum(f(max_pos-20:max_pos+20))
ns_noise =round((band/Fs)*(size_data/2))
Pnoise=sum(f(max_pos-ns_noise:max_pos+ns_noise))-Pu
plot(10*log10(f))
I=real(signal);
Q=imag(signal);
Qcor=(sin(phase)*I+ratio*Q)/cos(phase);
comp=I+j*Qcor;
hold on
plot(20*log10(abs(fft(comp))),'g')
comp=comp(1:10000).*exp(-j*(pi/2+0.1)*(1:10000))';
figure
plot(real(comp(1:500)));
hold on
plot(imag(comp(1:500)),'g');
figure
plot(20*log10(abs(fft(comp))),'g')
%end;
\ No newline at end of file
function out=rx_post(nom)
%load data.dat signal
%fid=fopen('/tmp/store1.dat',)
fid=fopen(nom,'rb')
signal=fread(fid,20480*2,'float');
signal=signal(1:2:length(signal))+j*signal(2:2:length(signal));
disp(signal(1:10));
size_data=20480/2;
Fs=7680; %in kHz
band = 2000; %in kHz
max_pos=0;
max=0;
f=abs(fft(signal)).^2;
for n=2:size_data
if(f(n) > max)
max=f(n);
max_pos=n;
end;
end;
disp(max_pos)
freq_max=Fs/size_data*max_pos - Fs/2 % corresponding frequency
if(abs(freq_max-2000)>100)
disp("Warning")
end;
% calculation of the signal power
Pu=sum(f(max_pos-20:max_pos+20))
ns_noise =round((band/Fs)*(size_data/2))
Pnoise=sum(f(max_pos-ns_noise:max_pos+ns_noise))-Pu
plot(10*log10(f))
% plot(10*log10(f(max_pos-ns_noise:max_pos+ns_noise)))
SNR=10*log10(Pu/Pnoise)
N_in = -174 +10*log10(1000*band)
S_in = -110;
SNR_in=S_in - N_in
NF=SNR_in-SNR
end;
function [ratio,phase]=IQ_estimation(freq)
gpib_send(gpib_card,sme,'*RST;*CLS'); % reset and configure the signal generator
gpib_send(gpib_card,sme,'POW -60dBm');
gpib_send(gpib_card,sme,strcat('FREQ ',int2str(freq),'MHz'));
gpib_send(gpib_card,sme,'OUTP:STAT ON'); % activate output
cmd1='/homes/nussbaum/open_freya/arch/openair_CardBus_MIMO1/LEON3/hostpc/user/tools/scripts/set_receiver -M ';
gain1=30;
gain2=30;
cmd=strcat(cmd1,frequency,' -g1 ',int2str(gain1),' -g2 ',int2str(gain2));
system(cmd);
sleep(.1);
s=oarf_get_frame(0);
signal=s(:,1);
size_data=20480;
Fs=7680; %in kHz
band = 2000; %in kHz
max_pos=0;
max=0;
f=abs(fft(signal)).^2;
for n=2:size_data
if(f(n) > max)
max=f(n);
max_pos=n;
end;
end;
disp(max_pos)
freq_max=Fs/size_data*max_pos - Fs/2 % corresponding frequency
if(abs(freq_max-2000)>100)
disp('Warning')
end;
cumI=0;
cumQ=0;
I=real(signal(1:2000));
Q=imag(signal(1:2000));
for i=1:2000
cumI=cumI + I(i)*I(i);
cumQ=cumQ + Q(i)*Q(i);
end;
amp= sqrt(2*cumI/length(I))
I=I/amp;
Q=Q/amp;
ratio=sqrt(cumI/cumQ)
n_fft=1024;
f=abs(fft(I(1:n_fft)));
max = 0;
index=0;
for i=1:n_fft/2
if f(i)> max
max=f(i);
index=i;
end;
end;
disp(max)
disp(index)
plot(f);
freq_estim=(index-1)/n_fft;
p=Q*ratio.*I;
sinphi=2*sum(p)/length(Q);
phi_est=-asin(sinphi)
Qcor=(sin(phi_est)*I+ratio*Q)/cos(phi_est);
figure
plot(I(1:100))
hold on
plot(Qcor(1:100),'g');
comp=I+j*Qcor;
figure
plot(20*log10(abs(fft(comp))));
% per=round(1/freq_estim)
% figure;plot(I(1:per+1))
% opt_offset=-5
% min_diff=10^20;
% for offset=0:per
% diff=0;
% for k=1:n_fft
% diff=diff+abs(I(k+offset)-Q(k));
% end;
% if diff<min_diff
% min_diff=diff;
% opt_offset= offset;
% end;
% end;
% disp(opt_offset)
% % normally, as to be 3/4*per
% opt_offset=opt_offset-3*per/4;
% disp(opt_offset/per*2*pi)
openair_init;
i=5
while (i>0)
s=oarf_get_frame(0);
plot(20*log10(abs(fft(s(:,1)))))
i=i-1;
disp(i)
end
openair_init;
i=30
while (i>0)
s=oarf_get_frame(0);
figure(1)
plot(20*log10(abs(fft(s(:,1)))))
figure(2)
plot(imag(s(:,1)))
i=i-1;
disp(i)
end
frequency = input('Input freq in MHz: ', 's');
num=1;
openair_init;
for n=1:num
s=oarf_get_frame(0);
plot(20*log10(abs(fft(s(:,1)))))
signal=s(:,1);
disp(signal(1:10));
fid=fopen(['/tmp/' frequency '_' int2str(n) '.dat'],'wb')
sig=zeros(2*length(signal),1);
sig(1:2:length(sig))=real(signal);
sig(2:2:length(sig))=imag(signal);
fwrite(fid,sig,'float');
fclose(fid);
end;
%frequency = input('Input freq in MHz: ', 's');
gpib_card=0; % first GPIB PCI card in the computer
gpib_sig_gen=28; % this is configured in the signal generator Utilities->System->GPIB->Address menu (for SME)
gpib_spec_ana=20; % this is configured in the spectrum analsyer
gpib_send(gpib_card,gpib_device,'*RST;*CLS'); % reset and configure the signal generator
gpib_send(gpib_card,gpib_device,'POW -70dBm');
gpib_send(gpib_card,gpib_device,'FREQ 1.91452GHz');
cmd1='/homes/khalfall/work/openairinterface/arch/openair_CardBus_MIMO1/LEON3/hostpc/user/tools/scripts/set_receiver -M ';
frequency='900';
ALL_gain1=61:1:63;
ALL_gain2=61:1:63;
for gain1=ALL_gain1
for gain2= ALL_gain2
cmd=strcat(cmd1,frequency,' -g1 ',int2str(gain1),' -g2 ',int2str(gain2));
disp(cmd);
system(cmd);
%system('set_receiver -M ' frequency ' -g1 ' int2str(gain1) ' -g2 ' int2str(gain2));
system('sleep 1');
end;
end;
num=10;
openair_init;
%for n=1:num
%s=oarf_get_frame(0);
%plot(20*log10(abs(fft(s(:,1)))))
%signal=s(:,1);
%fid=fopen(['/tmp/' frequency '_' int2str(n) '.dat'],'wb')
%fwrite(fid,signal);
%fclose(fid);
%end;
frequency = input('Input freq in MHz: ', 's');
num=1;
openair_init;
for n=1:num
s=oarf_get_frame(0);
plot(20*log10(abs(fft(s(:,1)))))
signal=s(:,1);
disp(signal(1:10));
fid=fopen(['/tmp/' frequency '_ref' int2str(n) '.dat'],'wb')
sig=zeros(2*length(signal),1);
sig(1:2:length(sig))=real(signal);
sig(2:2:length(sig))=imag(signal);
fwrite(fid,sig,'float');
fclose(fid);
end;
%frequency = input('Input freq in MHz: ', 's');
% script to setup mxa and sign generator
gpib_card=0; % first GPIB PCI card in the computer
sme=28; % this is configured in the signal generator Utilities->System->GPIB->Address menu (for SME)
mxa=20; % this is configured in the spectrum analsyer
%gpib_send(gpib_card,sme,'*RST;*CLS'); % reset and configure the signal generator
%gpib_send(gpib_card,sme,'POW -70dBm');
%gpib_send(gpib_card,sme,'FREQ 1.91452GHz');
gpib_send(gpib_card,mxa,'*CLS');
gpib_send(gpib_card,mxa,'SENS:FREQ:CENT 642MHz');
sleep(1);
gpib_send(gpib_card,mxa,'SENS:FREQ:SPAN 50MHz');
sleep(1);
%gpib_send(gpib_card,mxa,'SENS:BAND:RES 10KHZ');
sleep(1);
gpib_send(gpib_card,mxa,'CONF:ACP');
gpib_send(gpib_card,mxa,'INIT:ACP');
gpib_send(gpib_card,mxa,'SENS:ACP:FREQ:SPAN 20MHz');
gpib_send(gpib_card,mxa,'SENS:ACP:CARR1:LIST:BAND:INT 8MHz');
gpib_send(gpib_card,mxa,'SENS:ACP:OFFS1:LIST:STAT ON');
gpib_send(gpib_card,mxa,'SENS:ACP:OFFS1:LIST:FREQ 8MHZ,8MHZ,8MHZ,8MHZ,8MHZ,8MHZ');
%frequency = input('Input freq in MHz: ', 's');
gpib_send(gpib_card,mxa,'SENS:ACP:OFFS1:LIST:BAND:INT 8MHZ,8MHZ,8MHZ,8MHZ,8MHZ,8MHZ');
gpib_send(0,20,'SENS:POW:RANG:OPT:ATT COMB')
gpib_send(0,20,'SENS:POW:RF:RANG:OPT IMM')
%gpib_send(gpib_card,mxa,'POW:ATT 40dB');
x=gpib_query(gpib_card,mxa,'SENS:ACP:CARR1:POW?',1);
cmd1='/homes/khalfall/work/openairinterface/arch/openair_CardBus_MIMO1/LEON3/hostpc/user/tools/scripts/set_transmitter -M ';
frequency='900';
ALL_gain1=0:16:63;
ALL_gain2=0:16:63;
i=0;
for gain1=ALL_gain1
for gain2= ALL_gain2
i=i+1;
end;
end;
table=zeros(i,4);
i=1;
for gain1=ALL_gain1
for gain2= ALL_gain2
cmd=strcat(cmd1,frequency,' -g1 ',int2str(gain1),' -g2 ',int2str(gain2));
%disp(cmd);
system(cmd);
%system('set_receiver -M ' frequency ' -g1 ' int2str(gain1) ' -g2 ' int2str(gain2));
%system('sleep 1');
sleep(.1);
table(i,1)=gain1;
table(i,2)=gain2;
%frequency = input('Input freq in MHz: ', 's');
x=gpib_query(gpib_card,mxa,'READ:ACP?',3);
table(i,3)=x(1);
table(i,4)=(x(2)+x(3))/2;
i=i+1;
end;
end;
disp(table);
P_num =100; %(warning, to be updated)
% Post processing of the table started here
Pmin = -40; % in dBm
Pmax = 20; % in dBm
% a Tx calibration file is calculated for a given board and frequency
%fid=fopen(['/tmp/cal_TX' frequency '_' int2str(n) '.dat'],'wb')
%fwrite(fid,signal);
%fclose(fid);
clear all
size_data = 20480; % in ech
band = 7*10^6; %in Hz
Samples = zeros(size_data,1);
prefixe_in = '/tmp/'; % c'estle repertoire des fichiers .dat
signal_1 = [prefixe_in '953_4.dat'];
fid_1 = fopen(signal_1,'rb');
signal = fread(fid_1, size_data);
fclose(fid_1);
Samples(:,1) = signal;
data = (fft(Samples))';
mes_norm = sqrt(real(data).^2+imag(data).^2);
[n,m]= size(mes_norm);
decal_freq = 180*10^3; % in Hz
decal = ceil((decal_freq*size_data)/band); % in ech
for q = 1:(m - decal);
% Parameters
mu_norm = sum(mes_norm(q:q+decal))/(decal+1);
sigma2_norm = sum((mes_norm(q:q+decal)-mu_norm).^2)./(decal+1);
sigma_ray = sqrt((1/(2*(decal+1)))*sum(mes_norm(q:q+decal).^2));
% Distributions %%%%%%%%%
rayleigh = mes_norm(q:q+decal)./(sigma_ray^2).*exp(-(mes_norm(q:q+decal).^2)./(2*(sigma_ray^2)));
aic_matrix (1,q) = sum(log10(rayleigh))+2;
nr = exp(-(1/2)*(mes_norm(q:q+decal)-mu_norm).^2./(sigma2_norm))./(sqrt(sigma2_norm*2*pi));
aic_matrix (2,q) = sum(log10(nr))+8;
end
min_vect = min(aic_matrix(:,:));
for i=1:m-decal,
D(1,i) = aic_matrix(1,i) - min_vect(i);
D(2,i) = aic_matrix(2,i) - min_vect(i);
den = sum(exp(-0.5*D(:,i)));
w_ray(i) = exp(-0.5*D(1,i))/den;
w_nr(i) = exp(-0.5*D(2,i))/den;
end
for i= 1:ceil(decal/2),
bande(i) = 0;
end
for i=ceil(decal/2) + 1:length(w_ray)+ceil(decal/2),
if w_ray(i-ceil(decal/2)) < 0.009,
bande(i) = 1;
else
bande(i) = 0;
end
end
for i= length(w_ray)+ceil(decal/2)+1:length(w_ray)+decal,
bande(i) = 0;
end
bande_1 = zeros(1,length(bande));
for i=1:decal:length(bande)-decal,
nb_zeros = 0;
for k = 1:decal,
if (bande(i+k-1)==0),
nb_zeros = nb_zeros+1;
end
end
if (nb_zeros > decal/2),
for k = 1:decal,
bande_1(i+k-1)=0;
end
else
for k = 1:decal,
bande_1(i+k-1)=1;
end
end
end
for i=1:length(bande)/2-72,
bande_1(length(bande) - i - 1) = bande_1(i + 72);
end
for i=1:length(bande),
ban(i) = 0;
end
for i=1:decal:length(bande),
ban(i) = 1;
end
if 1,
size_data = size_data - decal;
fr = -band/2:band/size_data:band/2-band/size_data;
figure(1),
subplot(2,1,1),plot(fr,w_ray,'k.'), axis([-band/2, band/2, 0, 1])
title('')
size_data = 20480;
band = 7*10^6; %in kHz
fr = -band/2:band/size_data:band/2-band/size_data;
subplot(2,1,2),plot(fr, real(data(1,:)), 'k-'), axis([-band/2, band/2, -150000, 150000])
subplot(2,1,2),hold on, plot(fr, 10^5.*ban,'k--'), plot(fr, 10^5.*bande_1,'r')
subplot(2,1,1),hold on, plot(fr, ban,'k--'),
title('')
end
\ No newline at end of file
frequency = input('Input freq in MHz: ', 's');
% script to setup mxa and sign generator
freq=str2num(frequency);
size_data=20480;
Fs=7680; %sampling freq in kHz
band = 1500; % noise band in kHz
gpib_card=0; % first GPIB PCI card in the computer
sme=28; % this is configured in the signal generator Utilities->System->GPIB->Address menu (for SME)
cd ../CBMIMO1_TOOLS;
openair_init;
cd ../AGILE_RF_TOOLS;
%freq=1200; % normally loop
S_in=-100;
loss_cable=0.5 + freq/2000;
% first, calculation of IQ missmatch
[ratio,phi_est]=IQ_estimation(freq);
gpib_send(gpib_card,sme,'*RST;*CLS'); % reset and configure the signal generator
gpib_send(gpib_card,sme,strcat('POW ',int2str(S_in),'dBm'));
%disp('FREQ ',int2str(freq),'MHz');
gpib_send(gpib_card,sme,strcat('FREQ ',int2str(freq),'MHz'));
%disp('FREQ ',int2str(freq),'MHz');
%frequency = input('Input freq in MHz: ', 's');
cmd1='/homes/nussbaum/openair1/ARCH/LEON3/hostpc/user/tools/scripts/set_receiver -M ';
frequency=int2str(freq);
ALL_gain1=63;
ALL_gain2=63;
i=0;
for gain1=ALL_gain1
for gain2= ALL_gain2
i=i+1;
end;
end;
table=zeros(i,4);
i=1;
for gain1=ALL_gain1
for gain2=ALL_gain2
S_in_debug=-73 + floor((gain1+gain2)/2);
gpib_send(gpib_card,sme,strcat('POW ',int2str(S_in_debug),'dBm')); % this is for debug without the boards
cmd=strcat(cmd1,frequency,' -g1 ',int2str(gain1),' -g2 ',int2str(gain2));
system(cmd);
%system('set_receiver -M ' frequency ' -g1 ' int2str(gain1) ' -g2 ' int2str(gain2));
%system('sleep 1');
gpib_send(gpib_card,sme,'OUTP:STAT ON'); % activate output
sleep(.1);
table(i,1)=gain1;
table(i,2)=gain2;
s=oarf_get_frame(0);
%figure
%plot(20*log10(abs(fft(s(:,1)))),'g')
signal=s(:,1);
I=real(signal);
Q=imag(signal);
disp(phi_est);
Qcor=sin(phi_est)*I;
Qcor=(sin(phi_est)*I+ratio*Q)/cos(phi_est);
figure
plot(I(1:100))
hold on
plot(Qcor(1:100),'g');
comp=I+j*Qcor;
hold off
figure
plot(20*log10(abs(fft(comp))));
max_pos=0;
max=0;
f=abs(fft(signal)).^2;
for n=size_data/2:size_data
if(f(n) > max)
max=f(n);
max_pos=n;
end;
end;
disp("max_pos")
disp(max_pos)
freq_max=Fs/size_data*max_pos - Fs/2 % corresponding frequency
disp("freq_max")
disp(freq_max)
if(abs(freq_max-2000)>400) % probably and error occurs
disp("Warning")
Pu=0.1;
Pnoise=10000;
else
% calculation of the signal power
Pu=sum(f(max_pos-20:max_pos+20))
ns_noise =round((band/Fs)*(size_data/2))
Pnoise=sum(f(max_pos-ns_noise:max_pos+ns_noise))-Pu
end;
% plot(10*log10(f))
% plot(10*log10(f(max_pos-ns_noise:max_pos+ns_noise)))
SNR=10*log10(Pu/Pnoise)
N_in = -174 +10*log10(1000*band)
S_in = S_in-loss_cable;
SNR_in=S_in - N_in
NF=SNR_in-SNR
disp("gain_total")
gain_total=10*log10(Pu) - S_in
end;
end;
%frequency = input('Input freq in MHz: ', 's');
% script to setup mxa and sign generator
gpib_card=0; % first GPIB PCI card in the computer
sme=28; % this is configured in the signal generator Utilities->System->GPIB->Address menu (for SME)
mxa=20; % this is configured in the spectrum analsyer
%gpib_send(gpib_card,sme,'*RST;*CLS'); % reset and configure the signal generator
%gpib_send(gpib_card,sme,'POW -70dBm');
%gpib_send(gpib_card,sme,'FREQ 1.91452GHz');
gpib_send(gpib_card,mxa,'*CLS');
gpib_send(gpib_card,mxa,'SENS:FREQ:CENT 642MHz');
sleep(1);
gpib_send(gpib_card,mxa,'SENS:FREQ:SPAN 50MHz');
sleep(1);
%gpib_send(gpib_card,mxa,'SENS:BAND:RES 10KHZ');
sleep(1);
gpib_send(gpib_card,mxa,'CONF:ACP');
gpib_send(gpib_card,mxa,'INIT:ACP');
gpib_send(gpib_card,mxa,'SENS:ACP:FREQ:SPAN 20MHz');
gpib_send(gpib_card,mxa,'SENS:ACP:CARR1:LIST:BAND:INT 8MHz');
gpib_send(gpib_card,mxa,'SENS:ACP:OFFS1:LIST:STAT ON');
gpib_send(gpib_card,mxa,'SENS:ACP:OFFS1:LIST:FREQ 8MHZ,8MHZ,8MHZ,8MHZ,8MHZ,8MHZ');
%frequency = input('Input freq in MHz: ', 's');
gpib_send(gpib_card,mxa,'SENS:ACP:OFFS1:LIST:BAND:INT 8MHZ,8MHZ,8MHZ,8MHZ,8MHZ,8MHZ');
gpib_send(0,20,'SENS:POW:RANG:OPT:ATT COMB')
gpib_send(0,20,'SENS:POW:RF:RANG:OPT IMM')
%gpib_send(gpib_card,mxa,'POW:ATT 40dB');
x=gpib_query(gpib_card,mxa,'SENS:ACP:CARR1:POW?',1);
cmd1='/homes/khalfall/work/openairinterface/arch/openair_CardBus_MIMO1/LEON3/hostpc/user/tools/scripts/set_transmitter -M ';
frequency='900';
ALL_gain1=0:16:63;
ALL_gain2=0:16:63;
i=0;
for gain1=ALL_gain1
for gain2= ALL_gain2
i=i+1;
end;
end;
table=zeros(i,4);
i=1;
for gain1=ALL_gain1
for gain2= ALL_gain2
cmd=strcat(cmd1,frequency,' -g1 ',int2str(gain1),' -g2 ',int2str(gain2));
%disp(cmd);
system(cmd);
%system('set_receiver -M ' frequency ' -g1 ' int2str(gain1) ' -g2 ' int2str(gain2));
%system('sleep 1');
sleep(.1);
table(i,1)=gain1;
table(i,2)=gain2;
%frequency = input('Input freq in MHz: ', 's');
x=gpib_query(gpib_card,mxa,'READ:ACP?',3);
table(i,3)=x(1);
table(i,4)=(x(2)+x(3))/2;
i=i+1;
end;
end;
disp(table);
P_num =100; %(warning, to be updated)
% Post processing of the table started here
Pmin = -40; % in dBm
Pmax = 20; % in dBm
optimal_gain=zeros(Pmax-Pmin+1,4);
% a Tx calibration file is calculated for a given board and frequency
%fid=fopen(['/tmp/cal_TX' frequency '_' int2str(n) '.dat'],'wb')
%fwrite(fid,signal);
%fclose(fid);
function retvalue=variouspowers(s)
W=25;
fftsize=2^ceil(log2(length(s)));
powspectrum=fftshift(abs(fft(s-mean(s),fftsize)/sqrt(fftsize)));
powspectrumfilt=conv(powspectrum,ones(1,2*W+1));
[sigpower carrier_idx]=max(powspectrumfilt);
if (carrier_idx<=3*W)
carrier_idx=3*W+1;
end
sigpower_dB=20*log10(sigpower);
if (carrier_idx>3*W)
noiseplusintfspectrum=powspectrum;
noiseplusintfspectrum(carrier_idx+(-W:W)-2*W)=zeros(1,2*W+1);
noiseplusintfpower_dB=10*log10(sum(noiseplusintfspectrum.^2));
noiseplusintfspectrum_dB=20*log10(noiseplusintfspectrum);
noiseplusintfspectrum_dB(carrier_idx+(-W:W)-2*W)=-20;
%plot([ 20*log10(powspectrum) noiseplusintfspectrum_dB])
%pause
retvalue=[sigpower_dB noiseplusintfpower_dB];
else
retvalue=[sigpower_dB +Inf];
end
card = input('Input card number: ', 's');
filename_h = ['gain_table_' card '.h']; % file to store the gain table to
filename_mat = ['gain_table_' card '.mat'];
save(filename_mat,'SpN0','SpN1','N0','N1','S0','S1','G0','G1','NF0','NF1','SNR0','SNR1');
fid = fopen(filename_h,'w');
fprintf(fid,'#ifndef _GAIN_TABLE_H__\n');
fprintf(fid,'#define _GAIN_TABLE_H__\n');
fprintf(fid,'#include "phy_implementation_defs.h"\n');
%fprintf(fid,'#include "phy_implementation_defs.h"\n');
fprintf(fid,'#define TCXO_OFFSET\n');
fprintf(fid,'struct gain_table_entry {\n');
fprintf(fid,' unsigned char gain0;\n');
fprintf(fid,' unsigned char gain1;\n');
fprintf(fid,'};\n');
fprintf(fid,'struct gain_table_entry gain_table[MAX_RF_GAIN-MIN_RF_GAIN+1] = {\n');
for agc_level = 1:(max_agc_level-min_agc_level)
fprintf(fid,'%d, %d,\n',gain_levels(agc_level,:));
end
fprintf(fid,'%d, %d};\n',gain_levels(end,:));
fprintf(fid,'#endif /* _GAIN_TABLE_H__ */\n');
fclose(fid);
CC = gcc
TOP_DIR = ../..
OPENAIR2_DIR = ../../../../openair2
OPENAIR2_TOP = $(OPENAIR2_DIR)
CFLAGS = -DNODE_RG -DUSER_MODE -DPC_TARGET -DPC_DSP -DMAX_MODULES=1 -DPHY_CONTEXT=1 -DDEBUG_PHY -DNB_ANTENNAS_RX=2 -DNB_ANTENNAS_TX=2 -DNB_ANTENNAS_TXRX=2 -I$(OPENAIR1_DIR) -I$(OPENAIR2_DIR)/RRC/LITE/MESSAGES
include $(OPENAIR2_DIR)/LAYER2/Makefile.inc
include $(OPENAIR2_DIR)/UTIL/Makefile.inc
CFLAGS += $(L2_incl) $(UTIL_incl)
#ifdef OPENAIR_LTE
CFLAGS += -DOPENAIR_LTE
#endif
XTRA_CFLAGS = -msse -msse2 -mssse3
GCCVERSION = $(shell gcc --version | grep ^gcc | sed 's/^.* //g')
ifeq "$(GCCVERSION)" "4.4.3"
CFLAGS += -Wno-packed-bitfield-compat
endif
ifeq "$(GCCVERSION)" "4.5.2"
CFLAGS += -Wno-packed-bitfield-compat
endif
ifeq "$(GCCVERSION)" "4.6.1"
CFLAGS += -Wno-packed-bitfield-compat
endif
OPENAIROBJS +=$(OPENAIR1_DIR)/PHY/INIT/lte_parms.o
#OPENAIROBJS = $(OPENAIR1_DIR)/PHY/CONFIG/openair_readconfigfile.o $(OPENAIR1_DIR)/PHY/CONFIG/openair_configure.o
OCTAVEOBJS = oarf_set_tcxo_dac.oct oarf_config.oct oarf_config_exmimo.oct oarf_set_calibrated_rx_gain.oct oarf_set_tx_gain.oct oarf_get_frame.oct oarf_set_rx_gain.oct oarf_set_rx_rfmode.oct oarf_stop.oct oarf_send_frame.oct
all: $(OCTAVEOBJS) gpib_send.oct
oarf: $(OCTAVEOBJS)
$(OPENAIROBJS) : %.o : %.c
gcc -c $(CFLAGS) $(XTRA_CFLAGS) -o $@ $<
test:
echo $(OPENAIROBJS)
$(OCTAVEOBJS) : %.oct : %.cc $(OPENAIROBJS)
mkoctfile -o $@ $(CFLAGS) -lm $(OPENAIROBJS) $<
gpib_send.oct: gpib_send.cc
mkoctfile -I/usr/include/gpib -I/usr/local/include/gpib -lgpib gpib_send.cc
clean:
rm -f gpib_send.oct $(OCTAVEOBJS) $(OPENAIROBJS)
function [sig,sig_length] = OFDM_TX(num_carriers,num_zeros,prefix_length,input)
% OFDM Transmitter - DC removed
% sig is the output signal
% length is the length of the output signal
% num_carriers - number of sub-carriers (power of 2)
% num_zeros - number of zeros minus 1 (DC) in output spectrum (odd)
% prefix_length - length of cyclic prefix
% input - input dimensions (length = number_carriers - num_zeros - 1)
if (length(input) + num_zeros + 1 ~= num_carriers)
fprintf('error in lengths\n');
return;
end
ext_input = [0 input(1:length(input)/2) zeros(1,num_zeros) input((1+length(input)/2) : length(input))];
output_1 = ifft(ext_input);
sig = [output_1((num_carriers - prefix_length + 1) : num_carriers) output_1];
sig_length = length(sig);
function sig = OFDM_TX_FRAME(num_carriers,num_zeros,prefix_length,num_symbols_frame,preamble_length)
% sig - output signal
% sig_length - output signal length
% num_carriers - number of sub-carriers
% num_zeros - number of zero carriers minus 1 (DC)
% prefix_length - length of cyclic prefix
% num_symbols_frame - number of symbols per OFDM frame
% preamble_length - length of 4-QAM preamble
num_useful_carriers = num_carriers - num_zeros -1;
sig = [];
for k=1:preamble_length
QAM4_preamble = QAM_MOD(4,floor(256*abs(rand(1,num_useful_carriers/4))));
sig = [sig OFDM_TX(num_carriers,num_zeros,prefix_length,QAM4_preamble)];
end
for k=1:(num_symbols_frame - preamble_length)
QAM_data = QAM_MOD(256,floor(256*abs(rand(1,num_useful_carriers))));
sig = [sig OFDM_TX(num_carriers,num_zeros,prefix_length,QAM_data)];
end
function [sig,sig_length] = QAM_MOD(size,input)
% sig - output symbols
% size - modulation size (4,16,256)
% input - vector of bytes to be modulated
AM2 = [-1 1];
AM4 = [-3 -1 1 3]; AM4 = 2*AM4/sqrt(AM4*AM4');
AM16 = [-15 -13 -11 -9 -7 -5 -3 -1 1 3 5 7 9 11 13 15]; AM16 = 4*AM16/sqrt(AM16*AM16');
sig = zeros(1,length(input)*8/log2(size));
sig_length = length(input)*8/log2(size);
for l=1:length(input)
if (size == 256)
sig(l) = (AM16(1+ floor((input(l)/16))) +sqrt(-1)*AM16(1+rem(input(l),16)))/sqrt(2);
elseif (size == 16)
sig(1 + 2*(l-1)) = (AM4(1+floor((input(l)/64))) + sqrt(-1)*AM4(1+rem(floor(input(l)/16) , 4)))/sqrt(2);
sig(2 + 2*(l-1)) = (AM4(1+rem(floor(input(l)/4) , 4)) + sqrt(-1)*AM4(1+rem(input(l) , 4)))/sqrt(2);
elseif (size == 4)
sig(1+ 4*(l-1)) = (AM2(1+(floor(input(l)/128))) + sqrt(-1)*AM2(1+rem(floor(input(l)/64) , 2)))/sqrt(2);
sig(2+ 4*(l-1)) = (AM2(1+rem(floor(input(l)/32) ,2)) + sqrt(-1)*AM2(1+rem(floor(input(l)/16) , 2)))/sqrt(2);
sig(3+ 4*(l-1)) = (AM2(1+rem(floor(input(l)/8) , 2)) + sqrt(-1)*AM2(1+rem(floor(input(l)/4) , 2)))/sqrt(2);
sig(4+ 4*(l-1)) = (AM2(1+rem(floor(input(l)/2) , 2)) + sqrt(-1)*AM2(1+rem(input(l) , 2)))/sqrt(2);
end
end
chan=1;
hold off ;
s=oarf_get_frame(0);
s2=zeros(76800*2,1);
s2(1:2:end) = s(:,chan);
s2(2:2:end) = s(:,chan);
plot(real(s2),'b',"markersize",1);
hold on; plot(imag(s2),'r',"markersize",1);
bit11_I = rem(floor(real(2048+s(:,chan))/2048),2);
bit11_Q = rem(floor(imag((2048*j)+s(:,chan))/2048),2);
bit11_IQ = zeros(1,2*length(bit11_I));
bit11_IQ(1:2:end) = bit11_I;
bit11_IQ(2:2:end) = bit11_Q;
plot(500*bit11_IQ,'k')
axis([0 76800 -1000 1000])
close all
clear all
hold off
% Maxime Guillaud - created Wed May 10 18:08:04 CEST 2006
gpib_card=0; % first GPIB PCI card in the computer
gpib_device=28; % this is configured in the signal generator Utilities->System->GPIB->Address menu
freqband=0; % frequency band used by the openair card (depricated)
cables_loss_dB = 6; % we need to account for the power loss between the signal generator and the card input (splitter, cables)
dual_tx = 0;
tdd = 1;
fc = 1902600e3+freqband*5e6; % this has to be the same as in the config file
fs = 7680e3;
%fs = 6500e3;
fref = fc+fs/4;
power_dBm=-70;
%gpib_send(gpib_card,gpib_device,'*RST;*CLS'); % reset and configure the signal generator
%gpib_send(gpib_card,gpib_device,['POW ' int2str(power_dBm+cables_loss_dB) 'dBm']);
%gpib_send(gpib_card,gpib_device,['FREQ 1.91860 Ghz']); % set the frequency
%gpib_send(gpib_card,gpib_device,['FREQ ' int2str(fref/1e3) 'khz']); % set the frequency
%gpib_send(gpib_card,gpib_device,'OUTP:STAT ON'); % activate output
%keyboard;
oarf_config(freqband,tdd,dual_tx)
oarf_set_rx_rfmode(0);
oarf_set_rx_gain(70,70,0,0);
sleep(2)
step = 128;
tcxo_freq = 128;
f_off_min = 1e6;
tcxo_freq_min = 256;
do
step = step/2;
tcxo_freq
oarf_set_tcxo_dac(tcxo_freq);
sleep(2);
s=oarf_get_frame(freqband); %oarf_get_frame
nb_rx = size(s,2);
% find the DC component
m = mean(s);
s_phase = unwrap(angle(s(10000:4:length(s),1).'));
s_phase = s_phase - s_phase(1,1);
f_off = mean(s_phase(2:length(s_phase))*fs/4./(1:(length(s_phase)-1))/2/pi)
plot(1:length(s_phase),s_phase,'r');
if (nb_rx>1)
s_phase2 = unwrap(angle(s(10000:4:length(s),2).'));
s_phase2 = s_phase2 - s_phase2(1,1);
f_off2 = mean(s_phase2(2:length(s_phase2))*fs/4./(1:(length(s_phase2)-1))/2/pi)
hold on
plot(1:length(s_phase2),s_phase2,'g');
hold off
end
if (abs(f_off) < f_off_min)
tcxo_freq_min = tcxo_freq;
f_off_min = abs((f_off));
end
if ((f_off) > 0)
tcxo_freq = tcxo_freq + step;
else
tcxo_freq = tcxo_freq - step;
endif
until (step < 1)
write_tcxo
%gpib_send(gpib_card,gpib_device,'OUTP:STAT OFF'); % deactivate output
#ifndef _GAIN_TABLE_H__
#define _GAIN_TABLE_H__
#define MAX_RF_GAIN 150
#define MIN_RF_GAIN 96
struct gain_table_entry {
unsigned char gain0;
unsigned char gain1;
};
struct gain_table_entry gain_table[MAX_RF_GAIN-MIN_RF_GAIN+1] = {
26, 17,
28, 22,
29, 25,
31, 27,
33, 29,
35, 31,
38, 33,
40, 35,
48, 38,
52, 40,
54, 43,
56, 48,
57, 52,
58, 54,
60, 56,
61, 58,
63, 60,
65, 62,
67, 65,
69, 67,
73, 69,
79, 72,
84, 74,
88, 78,
90, 82,
92, 85,
94, 88,
95, 90,
97, 92,
98, 94,
99, 96,
101, 99,
103, 101,
105, 103,
107, 106,
111, 108,
116, 111,
122, 114,
126, 118,
127, 122,
128, 125,
129, 127,
131, 130,
133, 132,
135, 134,
138, 137,
140, 139,
144, 143,
152, 148,
155, 152,
157, 155,
158, 157,
160, 160,
162, 162,
164, 166
};
#endif /* _GAIN_TABLE_H__ */
#ifndef _GAIN_TABLE_H__
#define _GAIN_TABLE_H__
#define MAX_RF_GAIN 150
#define MIN_RF_GAIN 96
struct gain_table_entry {
unsigned char gain0;
unsigned char gain1;
};
struct gain_table_entry gain_table[MAX_RF_GAIN-MIN_RF_GAIN+1] = {
#ifndef _GAIN_TABLE_H__
#define _GAIN_TABLE_H__
#define MAX_RF_GAIN 150
#define MIN_RF_GAIN 96
struct gain_table_entry {
unsigned char gain0;
unsigned char gain1;
};
struct gain_table_entry gain_table[MAX_RF_GAIN-MIN_RF_GAIN+1] = {
28, 21,
29, 28,
30, 30,
32, 31,
33, 33,
34, 34,
35, 35,
37, 37,
39, 39,
41, 41,
46, 46,
55, 52,
57, 55,
58, 57,
60, 59,
61, 61,
62, 62,
64, 64,
65, 65,
69, 68,
76, 73,
78, 76,
79, 78,
81, 80,
83, 82,
85, 83,
89, 85,
94, 90,
97, 95,
100, 98,
101, 100,
103, 101,
104, 103,
105, 104,
107, 106,
111, 108,
117, 115,
119, 118,
121, 120,
122, 122,
124, 123,
125, 124,
128, 126,
130, 128,
140, 132,
143, 141,
145, 143,
147, 145,
149, 147,
151, 150,
152, 151,
154, 153,
155, 154,
167, 167,
168, 169
};
#endif /* _GAIN_TABLE_H__ */
#ifndef _GAIN_TABLE_H__
#define _GAIN_TABLE_H__
#include "phy_implementation_defs.h"
#define TCXO_OFFSET
struct gain_table_entry {
unsigned char gain0;
unsigned char gain1;
};
struct gain_table_entry gain_table[MAX_RF_GAIN-MIN_RF_GAIN+1] = {
27, 20,
29, 23,
32, 26,
34, 28,
37, 31,
41, 34,
43, 37,
45, 39,
48, 42,
51, 45,
54, 47,
56, 50,
58, 52,
61, 55,
63, 57,
65, 60,
67, 63,
70, 65,
72, 67,
75, 70,
78, 72,
80, 75,
83, 77,
86, 80,
88, 82,
90, 85,
93, 87,
98, 90,
102, 93,
103, 95,
105, 97,
106, 100,
108, 102,
114, 105,
116, 107,
117, 110,
118, 113,
120, 115,
123, 118,
131, 121,
132, 123,
132, 126,
133, 128,
134, 131,
141, 134,
142, 136,
149, 139,
152, 142,
155, 145,
156, 148,
158, 151,
160, 154,
167, 157,
179, 160,
179, 164
};
#endif /* _GAIN_TABLE_H__ */
#ifndef _GAIN_TABLE_H__
#define _GAIN_TABLE_H__
#include "phy_implementation_defs.h"
#define TCXO_OFFSET
struct gain_table_entry {
unsigned char gain0;
unsigned char gain1;
};
struct gain_table_entry gain_table[MAX_RF_GAIN-MIN_RF_GAIN+1] = {
1, 2,
6, 7,
10, 11,
13, 15,
17, 18,
20, 21,
23, 25,
26, 28,
29, 30,
31, 33,
34, 36,
37, 39,
39, 42,
42, 44,
45, 47,
47, 50,
50, 52,
52, 55,
55, 57,
57, 58,
60, 60,
62, 61,
65, 62,
67, 63,
70, 64,
72, 65,
75, 66,
77, 67,
80, 69,
82, 70,
85, 72,
87, 75,
90, 78,
92, 81,
94, 87,
97, 93,
100, 100,
102, 106,
105, 110,
107, 112,
110, 114,
112, 116,
115, 118,
117, 120,
120, 123,
123, 125,
125, 128,
128, 130,
131, 133,
134, 136,
136, 138,
139, 141,
142, 144,
145, 147,
148, 150
};
#endif /* _GAIN_TABLE_H__ */
#ifndef _GAIN_TABLE_H__
#define _GAIN_TABLE_H__
#define MAX_RF_GAIN 150
#define MIN_RF_GAIN 130
struct gain_table_entry {
unsigned char gain0;
unsigned char gain1;
};
struct gain_table_entry gain_table[MAX_RF_GAIN-MIN_RF_GAIN+1] = {
32, 32,
35, 35,
38, 38,
40, 40,
43, 43,
46, 46,
48, 48,
51, 51,
54, 53,
56, 56,
59, 58,
61, 61,
64, 63,
67, 66,
69, 68,
72, 71,
75, 73,
77, 76,
80, 79,
82, 81,
85, 84
};
#endif /* _GAIN_TABLE_H__ */
#ifndef _GAIN_TABLE_H__
#define _GAIN_TABLE_H__
#define MAX_RF_GAIN 150
#define MIN_RF_GAIN 130
struct gain_table_entry {
unsigned char gain0;
unsigned char gain1;
};
struct gain_table_entry gain_table[MAX_RF_GAIN-MIN_RF_GAIN+1] = {
46, 56,
49, 58,
51, 61,
54, 63,
56, 66,
59, 68,
62, 71,
64, 73,
67, 76,
69, 78,
72, 81,
74, 83,
77, 85,
79, 88,
82, 90,
84, 93,
87, 95,
89, 98,
92, 100,
94, 103,
97, 106
};
#endif /* _GAIN_TABLE_H__ */
#ifndef _GAIN_TABLE_H__
#define _GAIN_TABLE_H__
#define MAX_RF_GAIN 150
#define MIN_RF_GAIN 130
struct gain_table_entry {
unsigned char gain0;
unsigned char gain1;
};
struct gain_table_entry gain_table[MAX_RF_GAIN-MIN_RF_GAIN+1] = {
25, 34,
28, 37,
31, 39,
34, 42,
36, 45,
39, 47,
42, 50,
44, 53,
47, 55,
49, 58,
52, 60,
54, 63,
57, 65,
59, 68,
62, 70,
64, 73,
67, 75,
69, 78,
72, 80,
74, 83,
77, 85
};
#endif /* _GAIN_TABLE_H__ */
#ifndef _GAIN_TABLE_H__
#define _GAIN_TABLE_H__
#define MAX_RF_GAIN 150
#define MIN_RF_GAIN 130
struct gain_table_entry {
unsigned char gain0;
unsigned char gain1;
};
struct gain_table_entry gain_table[MAX_RF_GAIN-MIN_RF_GAIN+1] = {
25, 30,
28, 33,
30, 36,
33, 38,
36, 41,
39, 44,
42, 46,
44, 49,
47, 52,
50, 54,
52, 57,
55, 59,
57, 62,
60, 64,
63, 67,
65, 69,
68, 72,
70, 75,
73, 77,
75, 80,
78, 82
};
#endif /* _GAIN_TABLE_H__ */
// Maxime Guillaud - created Wed May 10 19:23:30 CEST 2006
// see http://www.gnu.org/software/octave/doc/interpreter/Dynamically-Linked-Functions.html#Dynamically-Linked-Functions
// and http://octave.sourceforge.net/coda/c58.html
// compile with: mkoctfile -I/usr/local/include/gpib -lgpib gpib_send.cc
#include <octave/oct.h>
#include "ib.h"
static bool any_bad_argument(const octave_value_list &args)
{
if (args.length()!=3)
{
error("gpib_send: syntax: gpib_send(gpib_board,gpib_device,gpib_str).");
return true;
}
if (!args(0).is_real_scalar())
{
error("gpib_send: GPIB board number must be a positive integer.");
return true;
}
if (args(0).scalar_value() < 0.0)
{
error("gpib_send: GPIB board number must be a positive integer.");
return true;
}
if (floor(args(0).scalar_value()) != args(0).scalar_value())
{
error("gpib_send: GPIB board number must be a positive integer.");
return true;
}
if (!args(1).is_real_scalar())
{
error("gpib_send: GPIB device number must be a positive integer.");
return true;
}
if (args(1).scalar_value() < 0.0)
{
error("gpib_send: GPIB device number must be a positive integer.");
return true;
}
if (floor(args(1).scalar_value()) != args(1).scalar_value())
{
error("gpib_send: GPIB device number must be a positive integer.");
return true;
}
if (!args(2).is_string())
{
error("gpib_send: third parameter must be a char string.");
return true;
}
return false;
}
DEFUN_DLD (gpib_send, args, nargout,"sends commands to the GPIB bus")
{
if (any_bad_argument(args))
return octave_value_list();
const int gpib_board = args(0).int_value();
const int gpib_device = args(1).int_value();
const std::string gpib_string = args(2).string_value();
unsigned short addlist[2] = {gpib_device, NOADDR};
SendIFC(gpib_board);
// ENABLE all on GPIB bus
EnableRemote(gpib_board, addlist);
// If error, Bye!
if (ibsta & ERR)
{
error("gpib_send: Instrument enable failed!");
return octave_value_list();
}
Send(gpib_board, gpib_device, gpib_string.c_str(), strlen(gpib_string.c_str()), NLend);
if (ibsta & ERR)
{
error("gpib_send: Send failed!");
return octave_value_list();
}
return octave_value_list();
}
modprobe ni_usb_gpib
fxload -D /proc/bus/usb/004/003 -I /usr/local/share/linux-gpib-3.2.11/gpib_firmware-2008-08-10/ni_gpib_usb_b/niusbb_firmware.hex -s /usr/local/share/linux-gpib-3.2.11/gpib_firmware-2008-08-10/ni_gpib_usb_b/niusbb_loader.hex
gpib_config
chmod a+rw /dev/gpib0
RXEN=1;
TXEN=2;
TXLPFENMASK=4;
TXLPFEN=4;
TXLPFMASK =15*(2^3);
TXLPF14 =0;
TXLPF10 =1*(2^3);
TXLPF7 =2*(2^3);
TXLPF6 =3*(2^3);
TXLPF5 =4*(2^3);
TXLPF4375 =5*(2^3);
TXLPF35 =6*(2^3);
TXLPF3 =7*(2^3);
TXLPF275 =8*(2^3);
TXLPF25 =9*(2^3);
TXLPF192 =10*(2^3);
TXLPF15 =11*(2^3);
TXLPF1375 =12*(2^3);
TXLPF125 =13*(2^3);
TXLPF0875 =14*(2^3);
TXLPF075 =15*(2^3);
RXLPFENMASK=1*(2^7);
RXLPFEN =128;
RXLPFMASK =15*(2^8);
RXLPF14 =0;
RXLPF10 =1*(2^8);
RXLPF7 =2*(2^8);
RXLPF6 =3*(2^8);
RXLPF5 =4*(2^8);
RXLPF4375 =5*(2^8);
RXLPF35 =6*(2^8);
RXLPF3 =7*(2^8);
RXLPF275 =8*(2^8);
RXLPF25 =9*(2^8);
RXLPF192 =10*(2^8);
RXLPF15 =11*(2^8);
RXLPF1375 =12*(2^8);
RXLPF125 =13*(2^8);
RXLPF0875 =14*(2^8);
RXLPF075 =15*(2^8);
LNAMASK=3*(2^12);
LNADIS =0;
LNA1ON =1*(2^12);
LNA2ON =2*(2^12) ;
LNA3ON =3*(2^12);
LNAGAINMASK=3*(2^14);
LNAByp =1*(2^14);
LNAMed =2*(2^14);
LNAMax =3*(2^14);
RFBBMASK =7*(2^16);
RFBBNORM =0;
RFBBRXLPF =1*(2^16);
RFBBRXVGA =2*(2^16);
RFBBOUTPUT=3*(2^16);
RFBBLNA1 =4*(2^16);
RFBBLNA2 =5*(2^16);
RFBBLNA3 =6*(2^16);
TXLPFMODEMASK=1*(2^21);
TXLPFNORM =0;
TXLPFBYP =1*(2^21);
RXLPFMODEMASK=3*(2^19);
RXLPFNORM =0;
RXLPFBYP =1*(2^19);
RXLPFBPY2 =3*(2^19);
rf_local = 31 + 31*(2^6) + 31*(2^12) + 31*(2^18);
rf_rxdc = 128 + 128*(2^8)
rf_vcocal = ((0xE)*(2^6)) + (0xE);
s = oarf_get_frame(2);
sig0 = s(:,1);
sig1 = s(:,2);
#sig0 = s(5000:end,1); % first channel
#sig1 = s(5000:end,2); % 2nd channel
bw=7.68e6;
spec = abs(fft(sig1)).^2;
[a,b] = max(spec);
freq = (b-1)*bw/length(sig0);
L= 1000;
W = 1;
offset_vec = (0:L-1)*((2*W)+1);
W2 = 1+(2*W);
window_vec = (-W : W);
pn = zeros(1,(2*L) - 1);
for i = 1:L,
pn(i+L-1) = sum(spec(offset_vec(i) + b + window_vec));
end
for i = 2:L,
pn(L-i+1) = sum(spec(-offset_vec(i) + b + window_vec));
end
pn_2 = 10*log10(pn / pn(L)) - 10*log10(W2*bw/length(sig0));
f = ((-L+1):(L-1))*W2*bw/length(sig0);
ylabel('dBc/Hz')
xlabel("f_offset (Hz)")
title("Phase Noise @ IQ output for Fc = 1912.6 + Fs/4 MHz CW input at antenna")
semilogx(f(L:(2*L - 1)),pn_2(L:(2*L -1)))
sum(pn*(f(2)-f(1)))
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
function [qresult]=QueryGPIB(addr,cmdstr);
% Pass address of GPIB instrument and the command string to
% trigger the query.
% example querygpib(20, FREQ?)
A = system('/local/gpibquery ' sprintf('%i ',addr) cmdstr);
qresult = sscanf(A, "%f")
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment