要在SORA上实现一个收发系统,一般的做法是先做一个offline的,验证功能是否正确,然后再进行代码优化,以实现实时的通信。

因为我平时用Matlab比较多,所以这个offline的系统,我就首先用Matlab来写了。也就是说,用Matlab产生发射信号的波形文件,通过DUT发射出去,另一边用DUT接收,然后在Matlab中解调收到的这个dump文件。

下面我就贴一下Matlab产生波形文件和读dump文件的代码,供大家参考。

以下文件是产生一个随机的BPSK波形:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
symbol_num = 128;
oversample = 16; % samples in one symbol
amplitude = 127;

waveform = int8([]);
complex_waveform = [];
for ii = 1:symbol_num
data = 2*randint-1; % BPSK symbol
symbol = kron(data,ones(1,oversample))*amplitude*(1+j); % rotate 45 degrees to make it complex type
complex_waveform = [complex_waveform,symbol];
symbol_re = int8(real(symbol)); % 8-bit width waveform data
symbol_im = int8(imag(symbol));
symbol_iq = reshape([symbol_re;symbol_im],1,[]);
waveform = [waveform, symbol_iq];
end

% save waveform file
filename = sprintf('waveform_randombpsk_width%d_amp%d_totallen%d.sig',oversample,amplitude,symbol_num*oversample);
fid = fopen(filename,'wb');
fwrite(fid, waveform);
fclose(fid);
% save .mat file for the receiver side
filename = sprintf('waveform_randombpsk_width%d_amp%d_totallen%d.mat',oversample,amplitude,symbol_num*oversample);
save(filename,'complex_waveform');

下面这个函数是读dump文件的。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
function data = read_dump_file(filename)
fid = fopen(filename, 'r');
sample = fread(fid, inf, 'int16');
total_len = length(sample);
fclose(fid);
if rem(total_len,64)~=0
error('Error: The length of file is wrong!');
end
num_rx_desc = total_len/64;
% discard the rx_desc header
reshape_sample = reshape(sample,64,num_rx_desc);
reshape_sample = reshape_sample(9:end,:);
sample = reshape(reshape_sample,2,[]);

data = sample(1,:) + j*sample(2,:);
end

关于dump文件的格式在微软SORA论坛的置顶帖子中有描述。

http://social.microsoft.com/Forums/en-us/sora

我就直接贴一份在下面吧。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
Kun Tan Wednesday, December 01, 2010 1:13 PM

Dut tool or dot11config can capture a snapshot of the wireless channel and store the raw I/Q samples into a file located at c:\. The post explains the format of the dump file.

The dump file is basically a binary file that contains an array of RX descriptors. A RX descriptor (RX_DESC) is defined as follows:


typedef union ___RX_DESC

{
#pragma warning(disable: 4200 4214 4201)
struct
{
union{
struct
{
UCHAR __IsValid : 1;
UCHAR __IsScanned : 1;
UCHAR __Reserved : 6;
};
UCHAR __Flags;
} u;

UCHAR __Reserved2;
USHORT __DataSize;
UCHAR __Reserved3[12];
UCHAR __bData[0];
};

COMPLEX16 Samples[SORA_RX_SIGNAL_UNIT_COMPLEX16_NUM];
COMPLEX8 SmallSamples[SORA_RX_SIGNAL_UNIT_COMPLEX8_NUM];

#pragma warning(default: 4200 4214 4201)
}RX_DESC, *PRX_DESC;

The signal block is of 128 Bytes, with a header (RX_DESC) and 28 complex samples (COMPLEX16).

For detailed information of signal blocks, please refore _rx_manager.h.