[6320] | 1 | function 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 |
---|
| 34 | gui_Singleton = 1; |
---|
| 35 | gui_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', []); |
---|
| 41 | if nargin && ischar(varargin{1}) |
---|
| 42 | gui_State.gui_Callback = str2func(varargin{1}); |
---|
| 43 | end |
---|
| 44 | |
---|
| 45 | if nargout |
---|
| 46 | [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); |
---|
| 47 | else |
---|
| 48 | gui_mainfcn(gui_State, varargin{:}); |
---|
| 49 | end |
---|
| 50 | % End initialization code - DO NOT EDIT |
---|
| 51 | |
---|
| 52 | |
---|
| 53 | % --- Executes just before ofdm_chan_est_viewer is made visible. |
---|
| 54 | function 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 |
---|
| 62 | handles.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 |
---|
| 71 | handles.mag_plot_lims = [-32 31 -70 -20]; |
---|
| 72 | handles.phase_plot_lims = [-32 31 -3.2 +3.2]; |
---|
| 73 | |
---|
| 74 | ax = handles.axes_chan_mag; |
---|
| 75 | set(ax, 'XLim', handles.mag_plot_lims(1:2)); |
---|
| 76 | set(ax, 'YLim', handles.mag_plot_lims(3:4)); |
---|
| 77 | xlabel(ax, 'Subcarrier Index'); |
---|
| 78 | ylabel(ax, 'Magnitude (dB)'); |
---|
| 79 | grid(ax, 'On'); |
---|
| 80 | |
---|
| 81 | %Format the chan phase plot |
---|
| 82 | ax = handles.axes_chan_phase; |
---|
| 83 | set(ax, 'XLim', handles.phase_plot_lims(1:2)); |
---|
| 84 | set(ax, 'YLim', handles.phase_plot_lims(3:4)); |
---|
| 85 | xlabel(ax, 'Subcarrier Index'); |
---|
| 86 | ylabel(ax, 'Phase (radians)'); |
---|
| 87 | grid(ax, 'On'); |
---|
| 88 | |
---|
| 89 | |
---|
| 90 | %%%%%%%%%%%% |
---|
| 91 | %Load and pre-process the data |
---|
| 92 | if(~isempty(varargin)) |
---|
| 93 | log_filename = varargin{1}; |
---|
| 94 | else |
---|
| 95 | log_filename = 'np_rx_ofdm_entries.hdf5'; |
---|
| 96 | end |
---|
| 97 | |
---|
| 98 | rx_entries = rx_data_from_hdf5(log_filename); |
---|
| 99 | |
---|
| 100 | rx_t = rx_entries.timestamp; |
---|
| 101 | rx_g_bb_db = rx_entries.g_bb_db; |
---|
| 102 | rx_g_rf_db = rx_entries.g_rf_db; |
---|
| 103 | rx_fcs = logical(rx_entries.fcs_result == 1); |
---|
| 104 | rx_h = rx_entries.chan_ests; |
---|
| 105 | rx_pwr = rx_entries.pwr; |
---|
| 106 | |
---|
| 107 | %Convert chan ests to dB |
---|
| 108 | rx_h_db = 10*log10(abs(rx_h)); |
---|
| 109 | |
---|
| 110 | %Set zero subcarrier magnitudes to sub-axis value |
---|
| 111 | rx_h_db( real(rx_h) == 0) = handles.mag_plot_lims(3) - 5; |
---|
| 112 | |
---|
| 113 | %Update the text box summary of the log contents |
---|
| 114 | num_rx = numel(rx_t); |
---|
| 115 | num_rx_good = sum(rx_fcs == 1); |
---|
| 116 | num_rx_bad = sum(rx_fcs ~= 1); |
---|
| 117 | |
---|
| 118 | info_txt = ''; |
---|
| 119 | info_txt = [info_txt sprintf('Log file: %s\n', log_filename)]; |
---|
| 120 | info_txt = [info_txt sprintf('Log Time Span (sec): %5.3f\n\n', 1e-6 * (max(rx_t) - min(rx_t)))]; |
---|
| 121 | info_txt = [info_txt sprintf('Rx Log Entries: %6d\n', num_rx)]; |
---|
| 122 | info_txt = [info_txt sprintf(' FCS Good Entries: %6d (%2.2f%%)\n', num_rx_good, (100*num_rx_good/num_rx))]; |
---|
| 123 | info_txt = [info_txt sprintf(' FCS Bad Entries: %6d (%2.2f%%)\n', num_rx_bad, (100*num_rx_bad/num_rx))]; |
---|
| 124 | |
---|
| 125 | set(handles.info_text_area, 'String', info_txt); |
---|
| 126 | |
---|
| 127 | %Save data to the GUI data structure |
---|
| 128 | handles.rx_h_db = rx_h_db; |
---|
| 129 | handles.rx_h_phase = angle(rx_h); |
---|
| 130 | handles.rx_h_phase(:, [1:6 33 58:63]) = NaN; |
---|
| 131 | |
---|
| 132 | %Populate the table of Rx entries for user selection |
---|
| 133 | idx_good = (rx_fcs == 1); |
---|
| 134 | idx_bad = (rx_fcs ~= 1); |
---|
| 135 | |
---|
| 136 | entry_table_data_all = [rx_t rx_pwr rx_g_rf_db rx_g_bb_db rx_fcs]; |
---|
| 137 | entry_table_data_good = entry_table_data_all(idx_good, :); |
---|
| 138 | entry_table_data_bad = entry_table_data_all(idx_bad, :); |
---|
| 139 | |
---|
| 140 | update_entry_table(handles, entry_table_data_all) |
---|
| 141 | |
---|
| 142 | handles.entry_table_data_all = entry_table_data_all; |
---|
| 143 | handles.entry_table_data_good = entry_table_data_good; |
---|
| 144 | handles.entry_table_data_bad = entry_table_data_bad; |
---|
| 145 | |
---|
| 146 | % Update handles structure |
---|
| 147 | guidata(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. |
---|
| 154 | function 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 |
---|
| 161 | varargout{1} = handles.output; |
---|
| 162 | |
---|
| 163 | |
---|
| 164 | % --- Executes when selected cell(s) is changed in entry_table. |
---|
| 165 | function 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 |
---|
| 172 | selection = eventdata.Indices(:,1); |
---|
| 173 | selection = unique(selection); |
---|
| 174 | update_chan_plots(selection, handles) |
---|
| 175 | |
---|
| 176 | |
---|
| 177 | function update_chan_plots(sel_idx, handles) |
---|
| 178 | |
---|
| 179 | %Extract the selected channel data |
---|
| 180 | % Transpose here so dimensions of arguments to stairs() below match |
---|
| 181 | h_mag = handles.rx_h_db(sel_idx, :).'; |
---|
| 182 | h_phase = handles.rx_h_phase(sel_idx, :).'; |
---|
| 183 | sc = [-32:31]; |
---|
| 184 | |
---|
| 185 | %Plot chan magnitude |
---|
| 186 | ax = handles.axes_chan_mag; |
---|
| 187 | |
---|
| 188 | h_p = stairs(ax, sc, h_mag); |
---|
| 189 | set(h_p, 'LineWidth', 2); |
---|
| 190 | set(ax, 'XLim', handles.mag_plot_lims(1:2)); |
---|
| 191 | set(ax, 'YLim', handles.mag_plot_lims(3:4)); |
---|
| 192 | xlabel(ax, 'Subcarrier Index'); |
---|
| 193 | ylabel(ax, 'Magnitude (dB)'); |
---|
| 194 | grid(ax, 'On'); |
---|
| 195 | |
---|
| 196 | %Plot chan phase |
---|
| 197 | ax = handles.axes_chan_phase; |
---|
| 198 | |
---|
| 199 | h_p = stairs(ax, sc, h_phase); |
---|
| 200 | set(h_p, 'LineWidth', 2); |
---|
| 201 | set(ax, 'XLim', handles.phase_plot_lims(1:2)); |
---|
| 202 | set(ax, 'YLim', handles.phase_plot_lims(3:4)); |
---|
| 203 | xlabel(ax, 'Subcarrier Index'); |
---|
| 204 | ylabel(ax, 'Phase (radians)'); |
---|
| 205 | grid(ax, 'On'); |
---|
| 206 | |
---|
| 207 | drawnow; |
---|
| 208 | |
---|
| 209 | % --- Executes during object creation, after setting all properties. |
---|
| 210 | function 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 |
---|
| 214 | colNames{1} = 'Timestamp (usec)'; colFmts{1} = 'numeric'; colWidths{1} = 115; |
---|
| 215 | colNames{2} = 'Rx Power (dBm)'; colFmts{2} = 'numeric'; colWidths{2} = 85; |
---|
| 216 | colNames{3} = 'RF Gain (dB)'; colFmts{3} = 'numeric'; colWidths{3} = 65; |
---|
| 217 | colNames{4} = 'BB Gain (dB)'; colFmts{4} = 'numeric'; colWidths{4} = 65; |
---|
| 218 | colNames{5} = 'FCS Good'; colFmts{5} = 'numeric'; colWidths{5} = 60; |
---|
| 219 | |
---|
| 220 | set(hObject, 'ColumnName', colNames); |
---|
| 221 | set(hObject, 'ColumnWidth', colWidths); |
---|
| 222 | set(hObject, 'ColumnFormat', colFmts); |
---|
| 223 | set(hObject, 'ColumnEditable', false(1,length(colNames))); |
---|
| 224 | |
---|
| 225 | function update_entry_table(handles, data_mat) |
---|
| 226 | set(handles.entry_table, 'Data', data_mat); |
---|
| 227 | |
---|
| 228 | |
---|
| 229 | % --- Executes on button press in button_show_good. |
---|
| 230 | function 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) |
---|
| 234 | update_entry_table(handles, handles.entry_table_data_good) |
---|
| 235 | |
---|
| 236 | % --- Executes on button press in button_show_bad. |
---|
| 237 | function 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) |
---|
| 241 | update_entry_table(handles, handles.entry_table_data_bad) |
---|
| 242 | |
---|
| 243 | |
---|
| 244 | % --- Executes on button press in button_show_all. |
---|
| 245 | function 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) |
---|
| 249 | update_entry_table(handles, handles.entry_table_data_all) |
---|