1 | function rx_data = rx_data_from_hdf5(varargin) |
---|
2 | % Utility to extract OFDM Rx entries from HDF5 file |
---|
3 | % Two input arguments: |
---|
4 | % rx_data = rx_data_from_hdf5(hdf5_file_name, hdf5_dataset_path) |
---|
5 | % hdf5_file_name: Path (full or relative) of source HDF5 file (required) |
---|
6 | % hdf5_dataset_path: HDF5 path for dataset containing OFDM Rx entries |
---|
7 | % Defaults to '/RX_OFDM' |
---|
8 | % |
---|
9 | % The HDF5 file fed to this function should be generated by processing |
---|
10 | % raw log data from the 802.11 Reference Design with the wlan_exp_log |
---|
11 | % Python utilities. This utility expects numpy-processed log entries |
---|
12 | % *not* raw log data. Refer to the 802.11 Reference Design user guide |
---|
13 | % for more details on using the wlan_exp_log tools. |
---|
14 | |
---|
15 | if(nargin == 1) |
---|
16 | hdf5_filename = varargin{1}; |
---|
17 | dataset_name = '/RX_OFDM'; |
---|
18 | elseif(nargin == 2) |
---|
19 | hdf5_filename = varargin{1}; |
---|
20 | dataset_name = varargin{2}; |
---|
21 | else |
---|
22 | error('rx_data_from_hdf5 requires 1 or 2 input arguments: hdf5_file_name and hdf5_dataset_path') |
---|
23 | end |
---|
24 | |
---|
25 | rx_entries = h5read(hdf5_filename, dataset_name); |
---|
26 | |
---|
27 | rx_t = double(rx_entries.timestamp); |
---|
28 | rx_fcs = double((bitand(rx_entries.flags,1) == 1)); |
---|
29 | rx_h = double(rx_entries.chan_est); |
---|
30 | rx_pwr = double(rx_entries.power); |
---|
31 | |
---|
32 | % For MAX2829 RF interfaces 8-bit rx_gain_index value is: |
---|
33 | % [ 8]: 0 |
---|
34 | % [6:5]: RF gain index (0, 1, 2) |
---|
35 | % [4:0]: BB gain index (0, 1, ..., 31) |
---|
36 | rx_gain_index = uint8(rx_entries.rx_gain_index); |
---|
37 | rx_g_bb = double(mod(rx_gain_index, 32)); |
---|
38 | rx_g_rf = double(rx_gain_index/32); |
---|
39 | |
---|
40 | %Sanitze gain values |
---|
41 | rx_g_rf( rx_g_rf < 1 ) = 1; |
---|
42 | rx_g_rf( rx_g_rf > 3 ) = 3; |
---|
43 | rx_g_bb( rx_g_bb < 0 ) = 0; |
---|
44 | rx_g_bb( rx_g_bb > 31 ) = 31; |
---|
45 | |
---|
46 | %Convert chan ests from [I,Q] of Fix16_15 to complex doubles |
---|
47 | rx_h = rx_h ./2^15; |
---|
48 | rx_h = fftshift(squeeze(complex(rx_h(1,:,:), rx_h(2,:,:)))); |
---|
49 | |
---|
50 | %RF Gain: 1=0dB, 2=15dB, 3=30dB |
---|
51 | rx_g_rf_db = ((rx_g_rf - 1) * 15); |
---|
52 | |
---|
53 | %BB Gain: 2dB per step, approx [0, 63]dB total |
---|
54 | rx_g_bb_db = (rx_g_bb * 2); |
---|
55 | |
---|
56 | %Compute linear gain adjustment |
---|
57 | rx_h_g_adj = 10.^(-(rx_g_rf_db + rx_g_bb_db)/10); |
---|
58 | |
---|
59 | rx_h_g_adj = repmat(rx_h_g_adj, 1, size(rx_h, 1)).'; |
---|
60 | |
---|
61 | %Remove effect of Rx gains on each channel estimate |
---|
62 | rx_h = rx_h .* rx_h_g_adj; |
---|
63 | |
---|
64 | %Construct output struct |
---|
65 | rx_data.timestamp = rx_t; |
---|
66 | rx_data.g_bb_db = rx_g_bb_db; |
---|
67 | rx_data.g_rf_db = rx_g_rf_db; |
---|
68 | rx_data.fcs_result = rx_fcs; |
---|
69 | rx_data.pwr = rx_pwr; |
---|
70 | rx_data.chan_ests = rx_h.'; |
---|