source: ResearchApps/PHY/WARPLAB/ResearchExamples/LTE_Setup/LTE_MATLAB_Reference_Files/1user_mimo/LTEDemo.m

Last change on this file was 1590, checked in by mduarte, 14 years ago
File size: 13.7 KB
Line 
1function varargout = LTEDemo(varargin)
2% LTEDEMO M-file for LTEDemo.fig
3%      LTEDEMO, by itself, creates a new LTEDEMO or raises the existing
4%      singleton*.
5%
6%      H = LTEDEMO returns the handle to a new LTEDEMO or the handle to
7%      the existing singleton*.
8%
9%      LTEDEMO('CALLBACK',hObject,eventData,handles,...) calls the local
10%      function named CALLBACK in LTEDEMO.M with the given input arguments.
11%
12%      LTEDEMO('Property','Value',...) creates a new LTEDEMO or raises the
13%      existing singleton*.  Starting from the left, property value pairs are
14%      applied to the GUI before LTEDemo_OpeningFcn gets called.  An
15%      unrecognized property name or invalid value makes property application
16%      stop.  All inputs are passed to LTEDemo_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%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
25% The MIMO LTE Uplink simulation based on Warplab
26% Composed by: Guohui Wang
27% Date: October 2009
28% Configuration: GUI control
29%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
30
31
32% Last Modified by GUIDE v2.5 13-Oct-2009 23:32:55
33
34% Begin initialization code - DO NOT EDIT
35gui_Singleton = 1;
36gui_State = struct('gui_Name',       mfilename, ...
37                   'gui_Singleton',  gui_Singleton, ...
38                   'gui_OpeningFcn', @LTEDemo_OpeningFcn, ...
39                   'gui_OutputFcn',  @LTEDemo_OutputFcn, ...
40                   'gui_LayoutFcn',  [] , ...
41                   'gui_Callback',   []);
42if nargin && ischar(varargin{1})
43    gui_State.gui_Callback = str2func(varargin{1});
44end
45
46if nargout
47    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
48else
49    gui_mainfcn(gui_State, varargin{:});
50end
51% End initialization code - DO NOT EDIT
52
53% My initialization
54global bRunning;
55bRunning = 1;
56
57
58% --- Executes just before LTEDemo is made visible.
59function LTEDemo_OpeningFcn(hObject, eventdata, handles, varargin)
60% This function has no output args, see OutputFcn.
61% hObject    handle to figure
62% eventdata  reserved - to be defined in a future version of MATLAB
63% handles    structure with handles and user data (see GUIDATA)
64% varargin   command line arguments to LTEDemo (see VARARGIN)
65
66% Choose default command line output for LTEDemo
67handles.output = hObject;
68
69% Update handles structure
70guidata(hObject, handles);
71
72% UIWAIT makes LTEDemo wait for user response (see UIRESUME)
73% uiwait(handles.figure1);
74
75% --- Outputs from this function are returned to the command line.
76function varargout = LTEDemo_OutputFcn(hObject, eventdata, handles) 
77% varargout  cell array for returning output args (see VARARGOUT);
78% hObject    handle to figure
79% eventdata  reserved - to be defined in a future version of MATLAB
80% handles    structure with handles and user data (see GUIDATA)
81
82% Get default command line output from handles structure
83varargout{1} = handles.output;
84
85
86% --- Executes on button press in pushbutton_start.
87function pushbutton_start_Callback(hObject, eventdata, handles)
88% hObject    handle to pushbutton_start (see GCBO)
89% eventdata  reserved - to be defined in a future version of MATLAB
90% handles    structure with handles and user data (see GUIDATA)
91
92% bRunning is the flag that shows whether the program is running.
93global bRunning;
94bRunning = 1;
95% set the total number of images to transmit.
96number_of_image = 5;
97% set the initial index of the images
98image_index = -1;
99
100while(bRunning)
101    set(handles.text4,'String','Transmitting');
102    set(handles.text6,'String','Transmitting');
103
104    index=get(handles.popupmenu1,'Value');
105
106    T = [];
107    % sub-block size which is transmitted each time.
108    block_size = 12;
109    % the white block used to indicate the current transmitted subblock.
110    box_width = 2;
111   
112    % load the image and display it.
113    image_index = mod(image_index+1, number_of_image);
114    imagename = ['img_user1_' num2str(image_index) '.bmp'];
115    A = imread(imagename);
116    imshow(A,'Parent', handles.axes1);
117    [width height color] = size(A);
118   
119    % initialize the receive image
120    B = uint8(255.*ones(width, height, color)); 
121
122    %reset the residual error figure
123    C = ones(width, height, color).*255;
124    imshow(C,'Parent', handles.axes4);
125
126    block_index = 0;
127    MSE_total = 0;
128   
129    try
130        for (j = 1:height/block_size)
131            for (i = 1:width/block_size )
132               
133                % start the transmission
134                if(strcmp(get(handles.text4,'String'),'Stopped'))
135                    bRunning = 0;
136                    break;
137                end
138
139                block_index = block_index + 1;
140                str_edit_block = sprintf ('%d/%d', 252/block_size*(j-1)+i, 252*252/block_size/block_size);
141                set(handles.edit2,'String', str_edit_block);
142               
143                % get the subblock data
144                top1 = block_size*(i-1)+1;
145                bottom1 = block_size*i;
146                left1 = block_size*(j-1)+1;
147                right1 = block_size*j;
148                T_original = A(left1:right1, top1:bottom1, :);
149               
150                % draw the block frame in the transmitted image
151                A_box = A;
152                A_box(left1:left1+box_width , top1:bottom1, :) = 255;
153                A_box(right1-box_width:right1 , top1:bottom1, :) = 255;
154                A_box(left1:right1, top1:top1+box_width, :) = 255;
155                A_box(left1:right1, bottom1-box_width:bottom1,:) = 255;
156                imshow(A_box,'Parent', handles.axes1);
157
158                % draw the block frame in the received image
159                B_box = B;
160                B_box(left1:left1+box_width , top1:bottom1, :) = 0;
161                B_box(right1-box_width:right1 , top1:bottom1, :) = 0;
162                B_box(left1:right1, top1:top1+box_width, :) = 0;
163                B_box(left1:right1, bottom1-box_width:bottom1,:) = 0;
164                imshow(B_box, 'parent', handles.axes2);
165
166                % reshape the data block to a data stream
167                T = double(T_original);
168                T = de2bi( floor(T),'left-msb',8);
169                T_stream = reshape(T', 1,1152);
170
171                % transmit the data by the function 'demo_transmit_1user_mimo'
172                T_out = demo_transmit_1user_mimo(T_stream);
173
174                T = reshape(T_out, 8,144);
175                T = bi2de(T','left-msb');
176                T = reshape(T, 12,12);
177                T= uint8(T);
178                B(block_size*(j-1)+1:block_size*j, block_size*(i-1)+1:block_size*i, :) = T;
179
180                % draw the residual image
181                C_box = (T-T_original).^2;
182                C(block_size*(j-1)+1:block_size*j, block_size*(i-1)+1:block_size*i, :) = C_box;
183                imshow(C,'Parent', handles.axes4);
184               
185                MSE_box = sum(sum(sum(double(C_box))))/block_size/block_size;
186               
187                % calculate the PSNR of the image
188                MSE_total = (MSE_box + MSE_total*(block_index-1))/block_index;
189                R2 = 255^2*color;
190                PSNR = 10*log10(R2/MSE_total);
191                str_edit_psnr = sprintf ('%f',PSNR);
192                set(handles.edit3,'String', str_edit_psnr);
193            end
194        end
195
196        % during the transmission.
197        if(strcmp(get(handles.text4,'String'),'Transmitting'))
198            C = (B-A).^2;
199            imshow(C,'Parent', handles.axes4);
200           
201            C_float = double(C);
202           
203            % calculate the PSNR of current received image
204            MSE = sum(sum(sum(C_float)))/width/height;
205            R2 = 255^2*color;
206            PSNR = 10*log10(R2/MSE);
207            str_edit_psnr = sprintf ('%f',PSNR);
208            set(handles.edit3,'String', str_edit_psnr);
209           
210            % save the result image to local hard drive
211            clock1 = clock;
212            imageB_name = sprintf('demo_image_out_%4d%02d%02d%02d%02d.bmp', clock1(1), clock1(2), clock1(3), clock1(4), clock1(5));
213            imwrite(B, imageB_name);
214        end
215       
216        if(strcmp(get(handles.text4,'String'),'Stopped'))
217            break;
218        end
219    catch
220        rethrow(lasterror);
221    end
222
223    imshow(A,'Parent', handles.axes1);
224    imshow(B, 'Parent', handles.axes2);
225    set(handles.text6,'String','Transmission finished');
226    pause(1.5);
227end
228
229
230% --- Executes during object creation, after setting all properties.
231function figure1_CreateFcn(hObject, eventdata, handles)
232% hObject    handle to figure1 (see GCBO)
233% eventdata  reserved - to be defined in a future version of MATLAB
234% handles    empty - handles not created until after all CreateFcns called
235
236
237% --- Executes on button press in pushbutton_load.
238function pushbutton_load_Callback(hObject, eventdata, handles)
239% hObject    handle to pushbutton_load (see GCBO)
240% eventdata  reserved - to be defined in a future version of MATLAB
241% handles    structure with handles and user data (see GUIDATA)
242A=imread('img_user1_0.bmp');
243imshow(A,'Parent', handles.axes1);
244
245
246% --- Executes on selection change in popupmenu1.
247function popupmenu1_Callback(hObject, eventdata, handles)
248% hObject    handle to popupmenu1 (see GCBO)
249% eventdata  reserved - to be defined in a future version of MATLAB
250% handles    structure with handles and user data (see GUIDATA)
251
252% Hints: contents = get(hObject,'String') returns popupmenu1 contents as cell array
253%        contents{get(hObject,'Value')} returns selected item from popupmenu1
254
255
256% --- Executes during object creation, after setting all properties.
257function popupmenu1_CreateFcn(hObject, eventdata, handles)
258% hObject    handle to popupmenu1 (see GCBO)
259% eventdata  reserved - to be defined in a future version of MATLAB
260% handles    empty - handles not created until after all CreateFcns called
261
262% Hint: popupmenu controls usually have a white background on Windows.
263%       See ISPC and COMPUTER.
264if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
265    set(hObject,'BackgroundColor','white');
266end
267
268
269
270function editblock_Callback(hObject, eventdata, handles)
271% hObject    handle to editblock (see GCBO)
272% eventdata  reserved - to be defined in a future version of MATLAB
273% handles    structure with handles and user data (see GUIDATA)
274
275% Hints: get(hObject,'String') returns contents of editblock as text
276%        str2double(get(hObject,'String')) returns contents of editblock as a double
277
278
279% --- Executes during object creation, after setting all properties.
280function editblock_CreateFcn(hObject, eventdata, handles)
281% hObject    handle to editblock (see GCBO)
282% eventdata  reserved - to be defined in a future version of MATLAB
283% handles    empty - handles not created until after all CreateFcns called
284
285% Hint: edit controls usually have a white background on Windows.
286%       See ISPC and COMPUTER.
287if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
288    set(hObject,'BackgroundColor','white');
289end
290
291
292
293function edit2_Callback(hObject, eventdata, handles)
294% hObject    handle to edit2 (see GCBO)
295% eventdata  reserved - to be defined in a future version of MATLAB
296% handles    structure with handles and user data (see GUIDATA)
297
298% Hints: get(hObject,'String') returns contents of edit2 as text
299%        str2double(get(hObject,'String')) returns contents of edit2 as a double
300
301
302% --- Executes during object creation, after setting all properties.
303function edit2_CreateFcn(hObject, eventdata, handles)
304% hObject    handle to edit2 (see GCBO)
305% eventdata  reserved - to be defined in a future version of MATLAB
306% handles    empty - handles not created until after all CreateFcns called
307
308% Hint: edit controls usually have a white background on Windows.
309%       See ISPC and COMPUTER.
310if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
311    set(hObject,'BackgroundColor','white');
312end
313
314
315function edit3_Callback(hObject, eventdata, handles)
316% hObject    handle to edit3 (see GCBO)
317% eventdata  reserved - to be defined in a future version of MATLAB
318% handles    structure with handles and user data (see GUIDATA)
319
320% Hints: get(hObject,'String') returns contents of edit3 as text
321%        str2double(get(hObject,'String')) returns contents of edit3 as a double
322
323
324% --- Executes during object creation, after setting all properties.
325function edit3_CreateFcn(hObject, eventdata, handles)
326% hObject    handle to edit3 (see GCBO)
327% eventdata  reserved - to be defined in a future version of MATLAB
328% handles    empty - handles not created until after all CreateFcns called
329
330% Hint: edit controls usually have a white background on Windows.
331%       See ISPC and COMPUTER.
332if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
333    set(hObject,'BackgroundColor','white');
334end
335
336
337% --- Executes on button press in pushbutton3.
338function pushbutton3_Callback(hObject, eventdata, handles)
339% hObject    handle to pushbutton3 (see GCBO)
340% eventdata  reserved - to be defined in a future version of MATLAB
341% handles    structure with handles and user data (see GUIDATA)
342set(handles.text4,'String','Stopped');
343set(handles.text6,'String','Stopped');
344
345
346% % --- Executes during object creation, after setting all properties.
347% function text12_CreateFcn(hObject, eventdata, handles)
348% % hObject    handle to text12 (see GCBO)
349% % eventdata  reserved - to be defined in a future version of MATLAB
350% % handles    empty - handles not created until after all CreateFcns called
351% % a=imread('arrow.jpg');
352% % set(hObject,'CData',a)
353
354
355% --- Executes during object creation, after setting all properties.
356function axes16_CreateFcn(hObject, eventdata, handles)
357% hObject    handle to axes16 (see GCBO)
358% eventdata  reserved - to be defined in a future version of MATLAB
359% handles    empty - handles not created until after all CreateFcns called
360
361% Hint: place code in OpeningFcn to populate axes16
362a=imread('channel1.bmp');
363imshow('channel1.bmp');
364
Note: See TracBrowser for help on using the repository browser.