source: ReferenceDesigns/w3_802.11/python/examples/chan_est_viewer/ofdm_chan_est_viewer.m

Last change on this file was 6320, checked in by chunter, 5 years ago

1.8.0 release wlan-exp

File size: 9.2 KB
Line 
1function varargout = ofdm_chan_est_viewer(varargin)
2% ofdm_chan_est_viewer MATLAB code for ofdm_chan_est_viewer.fig
3%      ofdm_chan_est_viewer, by itself, creates a new ofdm_chan_est_viewer or raises the existing
4%      singleton*.
5%
6%      H = ofdm_chan_est_viewer returns the handle to a new ofdm_chan_est_viewer or the handle to
7%      the existing singleton*.
8%
9%      ofdm_chan_est_viewer('CALLBACK',hObject,eventData,handles,...) calls the local
10%      function named CALLBACK in ofdm_chan_est_viewer.M with the given input arguments.
11%
12%      ofdm_chan_est_viewer('Property','Value',...) creates a new ofdm_chan_est_viewer or raises the
13%      existing singleton*.  Starting from the left, property value pairs are
14%      applied to the GUI before ofdm_chan_est_viewer_OpeningFcn gets called.  An
15%      unrecognized property name or invalid value makes property application
16%      stop.  All inputs are passed to ofdm_chan_est_viewer_OpeningFcn via varargin.
17%
18%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
19%      instance to run (singleton)".
20%
21% See also: GUIDE, GUIDATA, GUIHANDLES
22
23%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
24% Mango 802.11 Reference Design - Channel Estimate Viewer Example
25%  Copyright 2014 Mango Communications, Inc. - All Rights Reserved
26%  Distributed under the WARP License: http://warpproject.org/license
27%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
28
29% Edit the above text to modify the response to help ofdm_chan_est_viewer
30
31% Last Modified by GUIDE v2.5 18-Mar-2014 11:01:04
32
33% Begin initialization code - DO NOT EDIT
34gui_Singleton = 1;
35gui_State = struct('gui_Name',       mfilename, ...
36                   'gui_Singleton',  gui_Singleton, ...
37                   'gui_OpeningFcn', @ofdm_chan_est_viewer_OpeningFcn, ...
38                   'gui_OutputFcn',  @ofdm_chan_est_viewer_OutputFcn, ...
39                   'gui_LayoutFcn',  [] , ...
40                   'gui_Callback',   []);
41if nargin && ischar(varargin{1})
42    gui_State.gui_Callback = str2func(varargin{1});
43end
44
45if nargout
46    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
47else
48    gui_mainfcn(gui_State, varargin{:});
49end
50% End initialization code - DO NOT EDIT
51
52
53% --- Executes just before ofdm_chan_est_viewer is made visible.
54function ofdm_chan_est_viewer_OpeningFcn(hObject, eventdata, handles, varargin)
55% This function has no output args, see OutputFcn.
56% hObject    handle to figure
57% eventdata  reserved - to be defined in a future version of MATLAB
58% handles    structure with handles and user data (see GUIDATA)
59% varargin   command line arguments to ofdm_chan_est_viewer (see VARARGIN)
60
61% Choose default command line output for ofdm_chan_est_viewer
62handles.output = hObject;
63
64%%%%%%%
65%Format the axes
66
67%Formats specified here are only used until the fist plots are drawn
68% Formats must be re-applied in cell selection callback below
69
70%Format the chan est mag plot
71handles.mag_plot_lims = [-32 31 -70 -20];
72handles.phase_plot_lims = [-32 31 -3.2 +3.2];
73
74ax = handles.axes_chan_mag;
75set(ax, 'XLim', handles.mag_plot_lims(1:2));
76set(ax, 'YLim', handles.mag_plot_lims(3:4));
77xlabel(ax, 'Subcarrier Index');
78ylabel(ax, 'Magnitude (dB)');
79grid(ax, 'On');
80
81%Format the chan phase plot
82ax = handles.axes_chan_phase;
83set(ax, 'XLim', handles.phase_plot_lims(1:2));
84set(ax, 'YLim', handles.phase_plot_lims(3:4));
85xlabel(ax, 'Subcarrier Index');
86ylabel(ax, 'Phase (radians)');
87grid(ax, 'On');
88
89
90%%%%%%%%%%%%
91%Load and pre-process the data
92if(~isempty(varargin))
93    log_filename = varargin{1};
94else
95    log_filename = 'np_rx_ofdm_entries.hdf5';
96end
97
98rx_entries = rx_data_from_hdf5(log_filename);
99
100rx_t        = rx_entries.timestamp;
101rx_g_bb_db  = rx_entries.g_bb_db;
102rx_g_rf_db  = rx_entries.g_rf_db;
103rx_fcs      = logical(rx_entries.fcs_result == 1);
104rx_h        = rx_entries.chan_ests;
105rx_pwr      = rx_entries.pwr;
106
107%Convert chan ests to dB
108rx_h_db = 10*log10(abs(rx_h));
109
110%Set zero subcarrier magnitudes to sub-axis value
111rx_h_db( real(rx_h) == 0) = handles.mag_plot_lims(3) - 5;
112
113%Update the text box summary of the log contents
114num_rx = numel(rx_t);
115num_rx_good = sum(rx_fcs == 1);
116num_rx_bad = sum(rx_fcs ~= 1);
117
118info_txt = '';
119info_txt = [info_txt sprintf('Log file: %s\n', log_filename)];
120info_txt = [info_txt sprintf('Log Time Span (sec): %5.3f\n\n', 1e-6 * (max(rx_t) - min(rx_t)))];
121info_txt = [info_txt sprintf('Rx Log Entries:    %6d\n', num_rx)];
122info_txt = [info_txt sprintf(' FCS Good Entries: %6d (%2.2f%%)\n', num_rx_good, (100*num_rx_good/num_rx))];
123info_txt = [info_txt sprintf(' FCS Bad Entries:  %6d (%2.2f%%)\n', num_rx_bad, (100*num_rx_bad/num_rx))];
124
125set(handles.info_text_area, 'String', info_txt);
126
127%Save data to the GUI data structure
128handles.rx_h_db = rx_h_db;
129handles.rx_h_phase = angle(rx_h);
130handles.rx_h_phase(:, [1:6 33 58:63]) = NaN;
131
132%Populate the table of Rx entries for user selection
133idx_good = (rx_fcs == 1);
134idx_bad = (rx_fcs ~= 1);
135
136entry_table_data_all = [rx_t rx_pwr rx_g_rf_db rx_g_bb_db rx_fcs];
137entry_table_data_good = entry_table_data_all(idx_good, :);
138entry_table_data_bad = entry_table_data_all(idx_bad, :);
139
140update_entry_table(handles, entry_table_data_all)
141
142handles.entry_table_data_all  = entry_table_data_all;
143handles.entry_table_data_good = entry_table_data_good;
144handles.entry_table_data_bad  = entry_table_data_bad;
145
146% Update handles structure
147guidata(hObject, handles);
148%%%%%%%%END INIT
149
150% UIWAIT makes ofdm_chan_est_viewer wait for user response (see UIRESUME)
151% uiwait(handles.figure1);
152
153% --- Outputs from this function are returned to the command line.
154function varargout = ofdm_chan_est_viewer_OutputFcn(hObject, eventdata, handles) 
155% varargout  cell array for returning output args (see VARARGOUT);
156% hObject    handle to figure
157% eventdata  reserved - to be defined in a future version of MATLAB
158% handles    structure with handles and user data (see GUIDATA)
159
160% Get default command line output from handles structure
161varargout{1} = handles.output;
162
163
164% --- Executes when selected cell(s) is changed in entry_table.
165function entry_table_CellSelectionCallback(hObject, eventdata, handles)
166% hObject    handle to entry_table (see GCBO)
167% eventdata  structure with the following fields (see UITABLE)
168%   Indices: row and column indices of the cell(s) currently selecteds
169% handles    structure with handles and user data (see GUIDATA)
170
171% Remove duplicate row IDs
172selection = eventdata.Indices(:,1);
173selection = unique(selection);
174update_chan_plots(selection, handles)
175
176
177function update_chan_plots(sel_idx, handles)
178
179%Extract the selected channel data
180% Transpose here so dimensions of arguments to stairs() below match
181h_mag = handles.rx_h_db(sel_idx, :).';
182h_phase = handles.rx_h_phase(sel_idx, :).';
183sc = [-32:31];
184
185%Plot chan magnitude
186ax = handles.axes_chan_mag;
187
188h_p = stairs(ax, sc, h_mag);
189set(h_p, 'LineWidth', 2);
190set(ax, 'XLim', handles.mag_plot_lims(1:2));
191set(ax, 'YLim', handles.mag_plot_lims(3:4));
192xlabel(ax, 'Subcarrier Index');
193ylabel(ax, 'Magnitude (dB)');
194grid(ax, 'On');
195
196%Plot chan phase
197ax = handles.axes_chan_phase;
198
199h_p = stairs(ax, sc, h_phase);
200set(h_p, 'LineWidth', 2);
201set(ax, 'XLim', handles.phase_plot_lims(1:2));
202set(ax, 'YLim', handles.phase_plot_lims(3:4));
203xlabel(ax, 'Subcarrier Index');
204ylabel(ax, 'Phase (radians)');
205grid(ax, 'On');
206
207drawnow;
208
209% --- Executes during object creation, after setting all properties.
210function entry_table_CreateFcn(hObject, eventdata, handles)
211% hObject    handle to entry_table (see GCBO)
212% eventdata  reserved - to be defined in a future version of MATLAB
213% handles    empty - handles not created until after all CreateFcns called
214colNames{1} = 'Timestamp (usec)';   colFmts{1} = 'numeric'; colWidths{1} = 115;
215colNames{2} = 'Rx Power (dBm)';     colFmts{2} = 'numeric'; colWidths{2} = 85;
216colNames{3} = 'RF Gain (dB)';       colFmts{3} = 'numeric'; colWidths{3} = 65;
217colNames{4} = 'BB Gain (dB)';       colFmts{4} = 'numeric'; colWidths{4} = 65;
218colNames{5} = 'FCS Good';            colFmts{5} = 'numeric'; colWidths{5} = 60;
219
220set(hObject, 'ColumnName', colNames);
221set(hObject, 'ColumnWidth', colWidths);
222set(hObject, 'ColumnFormat', colFmts);
223set(hObject, 'ColumnEditable', false(1,length(colNames)));
224
225function update_entry_table(handles, data_mat)
226set(handles.entry_table, 'Data', data_mat);
227
228
229% --- Executes on button press in button_show_good.
230function button_show_good_Callback(hObject, eventdata, handles)
231% hObject    handle to button_show_good (see GCBO)
232% eventdata  reserved - to be defined in a future version of MATLAB
233% handles    structure with handles and user data (see GUIDATA)
234update_entry_table(handles, handles.entry_table_data_good)
235
236% --- Executes on button press in button_show_bad.
237function button_show_bad_Callback(hObject, eventdata, handles)
238% hObject    handle to button_show_bad (see GCBO)
239% eventdata  reserved - to be defined in a future version of MATLAB
240% handles    structure with handles and user data (see GUIDATA)
241update_entry_table(handles, handles.entry_table_data_bad)
242
243
244% --- Executes on button press in button_show_all.
245function button_show_all_Callback(hObject, eventdata, handles)
246% hObject    handle to button_show_all (see GCBO)
247% eventdata  reserved - to be defined in a future version of MATLAB
248% handles    structure with handles and user data (see GUIDATA)
249update_entry_table(handles, handles.entry_table_data_all)
Note: See TracBrowser for help on using the repository browser.