提交 59b4863e 编写于 作者: M manjaro

Add Linux Demo for XCORR info trans

上级 a5649f03
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include <iostream> #include <iostream>
#include <thread> #include <thread>
#include <vector> #include <vector>
#include <atomic>
#include <cmath> #include <cmath>
using uhd::tune_request_t; using uhd::tune_request_t;
using uhd::tx_streamer; using uhd::tx_streamer;
...@@ -46,9 +47,9 @@ struct tag_channelOptions{ ...@@ -46,9 +47,9 @@ struct tag_channelOptions{
string wirefmt; //内部类型 (sc8 or sc16),是片上处理的类型 string wirefmt; //内部类型 (sc8 or sc16),是片上处理的类型
vector<size_t> channels {0};//通道号,可以设置0,1之类的。默认subdev时,0=A:A,1=A:B,subdev被修改,则采取修改后的编号 vector<size_t> channels {0};//通道号,可以设置0,1之类的。默认subdev时,0=A:A,1=A:B,subdev被修改,则采取修改后的编号
size_t spb = 10000; //缓冲大小,太小会丢包,太大会超时 size_t spb = 10000; //缓冲大小,太小会丢包,太大会超时
double rate = 500000; //采样率,单位Hz double rate = 1e6; //采样率,单位Hz
double freq = 1.0e9; //射频频率,单位Hz double freq = 1.0e9; //射频频率,单位Hz
double gain = 55; //射频增益,单位dB double gain = 20; //射频增益,单位dB
double bw = rate; //滤波带宽,默认为采样窗口 double bw = rate; //滤波带宽,默认为采样窗口
double lo_offset = 0; //LO偏移,单位 Hz (缺省) double lo_offset = 0; //LO偏移,单位 Hz (缺省)
bool int_n_mod = false; //int-n 模式(本例不配置) bool int_n_mod = false; //int-n 模式(本例不配置)
...@@ -77,7 +78,7 @@ int UHD_SAFE_MAIN(int /*argc*/, char* /*argv*/[]) ...@@ -77,7 +78,7 @@ int UHD_SAFE_MAIN(int /*argc*/, char* /*argv*/[])
//3.配置发射 //3.配置发射
tag_channelOptions tx_op; tag_channelOptions tx_op;
tx_op.freq = 230e6; tx_op.freq = 200e6;
tx_op.bw = tx_op.rate; tx_op.bw = tx_op.rate;
tx_op.gain=70; tx_op.gain=70;
tx_op.channels[0] = 0; tx_op.channels[0] = 0;
...@@ -111,14 +112,15 @@ int UHD_SAFE_MAIN(int /*argc*/, char* /*argv*/[]) ...@@ -111,14 +112,15 @@ int UHD_SAFE_MAIN(int /*argc*/, char* /*argv*/[])
//4.配置接收 //4.配置接收
tag_channelOptions rx_op; tag_channelOptions rx_op;
rx_op.ant = "RX2";
rx_op.bw = rx_op.rate; rx_op.bw = rx_op.rate;
rx_op.freq = 230e6; rx_op.freq = 200e6;
rx_op.gain = 30; rx_op.gain = 50;
rx_op.channels[0] = 1; rx_op.channels[0] = 0;
rx_op.ant = "RX2";
//4.1 子设备 //4.1 子设备
if (rx_op.subdev.size()) if (rx_op.subdev.size())
usrp->set_rx_subdev_spec(rx_op.subdev,multi_usrp::ALL_MBOARDS); usrp->set_rx_subdev_spec(rx_op.subdev,multi_usrp::ALL_MBOARDS);
usrp->set_rx_agc(true,rx_op.channels[0]);
cerr << "RX Using Device: " << usrp->get_pp_string() << endl; cerr << "RX Using Device: " << usrp->get_pp_string() << endl;
//4.2 采样率 //4.2 采样率
cerr << "Setting RX Rate: " << (rx_op.rate / 1e6) << "Msps..." << endl; cerr << "Setting RX Rate: " << (rx_op.rate / 1e6) << "Msps..." << endl;
...@@ -169,9 +171,9 @@ int UHD_SAFE_MAIN(int /*argc*/, char* /*argv*/[]) ...@@ -169,9 +171,9 @@ int UHD_SAFE_MAIN(int /*argc*/, char* /*argv*/[])
//收发计数 //收发计数
static unsigned long long rx_count (0), tx_count (0); static std::atomic< unsigned long long> rx_count (0), tx_count (0);
//消费生产计数 //消费生产计数
static unsigned long long deal_count (0), gene_count (0); static std::atomic< unsigned long long> deal_count (0), gene_count (0);
//缓存点数(IQ) //缓存点数(IQ)
static const size_t rxbuf_points = 1000*1000*16; static const size_t rxbuf_points = 1000*1000*16;
static const size_t txbuf_points = 1000*1000*16; static const size_t txbuf_points = 1000*1000*16;
...@@ -263,7 +265,7 @@ void do_io( ...@@ -263,7 +265,7 @@ void do_io(
//主线程不断打印状态 //主线程不断打印状态
while (!stop_signal_called) while (!stop_signal_called)
{ {
cerr<<"P " << gene_count<<" TX "<< tx_count<< " RX "<< rx_count << "D "<< deal_count<< " \r"; //cerr<<"P " << gene_count<<" TX "<< tx_count<< " RX "<< rx_count << "D "<< deal_count<< " \r";
std::this_thread::sleep_for(std::chrono::milliseconds(100)); std::this_thread::sleep_for(std::chrono::milliseconds(100));
if (rx_count >= 4*1024*1024) if (rx_count >= 4*1024*1024)
...@@ -276,12 +278,12 @@ void do_io( ...@@ -276,12 +278,12 @@ void do_io(
deal_thread.join(); deal_thread.join();
} }
static const int modraten = 32; static const int modraten = 4;
static const int amp = 1000; static const int amp = 1024;
static const int spread_ratio = 16; static const int spread_ratio = 128;
static const size_t wav_size = spread_ratio*modraten; static const size_t wav_size = spread_ratio*modraten;
static short wav_spread[2][wav_size][2]; static short wav_spread[2][wav_size][2];
static short wav_xorr[2][wav_size][2]; static float wav_xorr[2][wav_size][2];
void init_wavform() void init_wavform()
{ {
const double pi = 3.14159265358979323846; const double pi = 3.14159265358979323846;
...@@ -289,12 +291,12 @@ void init_wavform() ...@@ -289,12 +291,12 @@ void init_wavform()
short wav[2][modraten][2]; short wav[2][modraten][2];
for (int i=0;i<modraten;++i) for (int i=0;i<modraten;++i)
{ {
wav[0][i][0] = amp * cos(2 * pi * i / modraten); wav[0][i][0] = amp ;
wav[0][i][1] = amp * sin(2 * pi * i / modraten); wav[0][i][1] = amp ;
wav[1][i][0] = amp * cos(2 * pi * i / modraten); wav[1][i][0] = -amp ;
wav[1][i][1] =-amp * sin(2 * pi * i / modraten); wav[1][i][1] = -amp ;
} }
//M序列扩频 //扩频
char reg [21] = {0,1,1,0,0,1,0,1,1,0,0,1,0,1,1,0,0,1,0,1,1}; char reg [21] = {0,1,1,0,0,1,0,1,1,0,0,1,0,1,1,0,0,1,0,1,1};
//seq[0]是 0的符号,1是1的符号。每个符号中的0,1又对应了wav的IQ路 //seq[0]是 0的符号,1是1的符号。每个符号中的0,1又对应了wav的IQ路
char seq[2][spread_ratio]; char seq[2][spread_ratio];
...@@ -314,11 +316,11 @@ void init_wavform() ...@@ -314,11 +316,11 @@ void init_wavform()
{ {
wav_spread[0][i*modraten+j][0] = wav[seq[0][i]][j][0]; wav_spread[0][i*modraten+j][0] = wav[seq[0][i]][j][0];
wav_spread[0][i*modraten+j][1] = wav[seq[0][i]][j][1]; wav_spread[0][i*modraten+j][1] = wav[seq[0][i]][j][1];
wav_xorr[0][i*modraten+j][0] = wav[seq[0][i]][j][0]; wav_xorr[0][i*modraten+j][0] = wav[seq[0][i]][j][0]*1.0/amp;
wav_xorr[0][i*modraten+j][1] = -wav[seq[0][i]][j][1]; wav_xorr[0][i*modraten+j][1] = -wav[seq[0][i]][j][1]*1.0/amp;
} }
} }
for (int i=0;i<spread_ratio*16;++i) for (int i=0;i<377;++i)
{ {
reg[sw % 21] = reg[(sw + 3) % 21] ^ reg[(sw+20) % 21]; reg[sw % 21] = reg[(sw + 3) % 21] ^ reg[(sw+20) % 21];
seq[0][i] = reg[sw % 21]; seq[0][i] = reg[sw % 21];
...@@ -340,8 +342,8 @@ void init_wavform() ...@@ -340,8 +342,8 @@ void init_wavform()
{ {
wav_spread[1][i*modraten+j][0] = wav[seq[1][i]][j][0]; wav_spread[1][i*modraten+j][0] = wav[seq[1][i]][j][0];
wav_spread[1][i*modraten+j][1] = wav[seq[1][i]][j][1]; wav_spread[1][i*modraten+j][1] = wav[seq[1][i]][j][1];
wav_xorr[1][i*modraten+j][0] = wav[seq[1][i]][j][0]; wav_xorr[1][i*modraten+j][0] = wav[seq[1][i]][j][0]*1.0/amp;
wav_xorr[1][i*modraten+j][1] = -wav[seq[1][i]][j][1]; wav_xorr[1][i*modraten+j][1] = -wav[seq[1][i]][j][1]*1.0/amp;
} }
} }
...@@ -359,7 +361,7 @@ void producer() ...@@ -359,7 +361,7 @@ void producer()
char idle[8] = {0,1,1,1,1,1,1,0}; char idle[8] = {0,1,1,1,1,1,1,0};
while (!stop_signal_called) while (!stop_signal_called)
{ {
if (gene_count > tx_count + txbuf_points/2) if (gene_count > tx_count + txbuf_points-16)
{ {
std::this_thread::sleep_for(std::chrono::milliseconds(10)); std::this_thread::sleep_for(std::chrono::milliseconds(10));
continue; continue;
...@@ -378,12 +380,14 @@ void producer() ...@@ -378,12 +380,14 @@ void producer()
void dealer() void dealer()
{ {
unsigned long long next_test = wav_size; unsigned long long next_test = wav_size;
const unsigned int half_sz = wav_size/2;
short (*pBufRx)[2] = rx_buf_ptr.get(); short (*pBufRx)[2] = rx_buf_ptr.get();
float (* ampwin)[2] = new float[wav_size][2];
while (!stop_signal_called) while (!stop_signal_called)
{ {
if (deal_count + wav_size >= rx_count || rx_count < wav_size ) if (deal_count + wav_size >= rx_count || rx_count < wav_size )
{ {
std::this_thread::sleep_for(std::chrono::milliseconds(10)); std::this_thread::sleep_for(std::chrono::milliseconds(1));
continue; continue;
} }
...@@ -392,38 +396,49 @@ void dealer() ...@@ -392,38 +396,49 @@ void dealer()
++deal_count; ++deal_count;
continue; continue;
} }
long long cross[2][3] = {{0,0,0},{0,0,0}}; float cross[2][2] = {{0,0},{0,0}};
unsigned long long start_x = deal_count - wav_size; unsigned long long start_x = deal_count - wav_size;
//xorr //xorr
#pragma omp simd #pragma omp simd
for (size_t i=0;i<wav_size;++i) for (size_t i=0;i<wav_size;++i)
{ {
int xb = (start_x + i) % rxbuf_points; int xb = (start_x + i) % rxbuf_points;
cross[0][0] += (long long)(pBufRx[xb][0]) * wav_xorr[0][i][0] - (long long)(pBufRx[xb][1]) * wav_xorr[0][i][1]; cross[0][0] += (pBufRx[xb][0] * wav_xorr[0][i][0] - pBufRx[xb][1] * wav_xorr[0][i][1])/32768.0;
cross[0][1] += (long long)(pBufRx[xb][0]) * wav_xorr[0][i][1] + (long long)(pBufRx[xb][1]) * wav_xorr[0][i][0]; cross[0][1] += (pBufRx[xb][0] * wav_xorr[0][i][1] + pBufRx[xb][1] * wav_xorr[0][i][0])/32768.0;
cross[1][0] += (long long)(pBufRx[xb][0]) * wav_xorr[1][i][0] - (long long)(pBufRx[xb][1]) * wav_xorr[1][i][1]; cross[1][0] += (pBufRx[xb][0] * wav_xorr[1][i][0] - pBufRx[xb][1] * wav_xorr[1][i][1])/32768.0;
cross[1][1] += (long long)(pBufRx[xb][0]) * wav_xorr[1][i][1] + (long long)(pBufRx[xb][1]) * wav_xorr[1][i][0]; cross[1][1] += (pBufRx[xb][0] * wav_xorr[1][i][1] + pBufRx[xb][1] * wav_xorr[1][i][0])/32768.0;
} }
cross[0][2] = (abs(cross[0][0]) + abs(cross[0][1])); ampwin[deal_count % wav_size][0] = cross[0][0]*cross[0][0]+ cross[0][1]*cross[0][1];
cross[1][2] = (abs(cross[1][0]) + abs(cross[1][1])) ; ampwin[deal_count % wav_size][1] = cross[1][0]*cross[1][0]+ cross[1][1]*cross[1][1];
if (cross[0][2]/5 > cross[1][2] ) bool best0 = true, best1=true;
for (size_t i=0;i<wav_size && (best0||best1);++i)
{ {
printf ("Clock %lld(%lld) > 0=%lld,1=%lld, %lf\n",deal_count,deal_count / wav_size, cross[0][2],cross[1][2] if (i!=half_sz)
,log((cross[0][2]+1.0)/(cross[1][2]+1.0))/log(10)*10 {
); if (ampwin[(deal_count +i - wav_size )% wav_size][0] >= ampwin[(deal_count +half_sz - wav_size )% wav_size][0])
next_test = deal_count + wav_size - modraten*2; best0 = false;
if (ampwin[(deal_count +i - wav_size )% wav_size][1] >= ampwin[(deal_count +half_sz - wav_size )% wav_size][1])
best1 = false;
}
if (ampwin[(deal_count +i - wav_size )% wav_size][1] >= ampwin[(deal_count +half_sz - wav_size )% wav_size][0])
best0 = false;
if (ampwin[(deal_count +i - wav_size )% wav_size][0] >= ampwin[(deal_count +half_sz - wav_size )% wav_size][1])
best1 = false;
} }
if (cross[1][2]/5 > cross[0][2] )
if (best0 )
{
putchar('0');
}
else if (best1 )
{ {
printf ("Clock %lld(%lld) > 1=%lld,0=%lld, %lf\n",deal_count,deal_count / wav_size, cross[1][2],cross[0][2] putchar('1');
,log((cross[1][2]+1.0)/(cross[0 ][2]+1.0))/log(10)*10
);
next_test = deal_count + wav_size - modraten*2;
} }
++deal_count; ++deal_count;
} }
delete [] ampwin;
} }
//-----------------------维护代码------------------------ //-----------------------维护代码------------------------
bool check_tx_status(const string & ref, multi_usrp::sptr usrp,const tag_channelOptions & op) bool check_tx_status(const string & ref, multi_usrp::sptr usrp,const tag_channelOptions & op)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册