Code covered by the BSD License  

Highlights from
Gram-schmidt orthogonalization GUI

image thumbnail
from Gram-schmidt orthogonalization GUI by kazeem Yinusa
GUIDE inplementation of the Gram-schmidt orthogonalization procedure.

gramguide(varargin)
function varargout = gramguide(varargin)
% GRAMGUIDE M-file for gramguide.fig
%      GRAMGUIDE, by itself, creates a new GRAMGUIDE or raises the existing
%      singleton*.
%
%      H = GRAMGUIDE returns the handle to a new GRAMGUIDE or the handle to
%      the existing singleton*.
%
%      GRAMGUIDE('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in GRAMGUIDE.M with the given input arguments.
%
%      GRAMGUIDE('Property','Value',...) creates a new GRAMGUIDE or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before gramguide_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to gramguide_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help gramguide

% Last Modified by GUIDE v2.5 05-Dec-2008 20:58:42

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @gramguide_OpeningFcn, ...
                   'gui_OutputFcn',  @gramguide_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before gramguide is made visible.
function gramguide_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to gramguide (see VARARGIN)

% Choose default command line output for gramguide
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes gramguide wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = gramguide_OutputFcn(hObject, eventdata, handles) 
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;



function s1_Callback(hObject, eventdata, handles)
% hObject    handle to s1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of s1 as text
%        str2double(get(hObject,'String')) returns contents of s1 as a double
S1 = get(hObject,'String');
handles.S1 = sscanf(S1,'%d');
guidata(hObject,handles)


% --- Executes during object creation, after setting all properties.
function s1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to s1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end
S1 =  [0 0 0];
handles.S1 = S1';
guidata(hObject,handles)


function s3_Callback(hObject, eventdata, handles)
% hObject    handle to s3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of s3 as text
%        str2double(get(hObject,'String')) returns contents of s3 as a double
S3 = get(hObject,'String');
handles.S3 = sscanf(S3,'%d');
guidata(hObject,handles)

% --- Executes during object creation, after setting all properties.
function s3_CreateFcn(hObject, eventdata, handles)
% hObject    handle to s3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end
S3 =  [0 0 0];
handles.S3 = S3';
guidata(hObject,handles)


function s2_Callback(hObject, eventdata, handles)
% hObject    handle to s2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of s2 as text
%        str2double(get(hObject,'String')) returns contents of s2 as a double
S2 = get(hObject,'String');
handles.S2 = sscanf(S2,'%d');
guidata(hObject,handles)


% --- Executes during object creation, after setting all properties.
function s2_CreateFcn(hObject, eventdata, handles)
% hObject    handle to s2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end
S2 =  [0 0 0];
handles.S2 = S2';
guidata(hObject,handles)


function s4_Callback(hObject, eventdata, handles)
% hObject    handle to s4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of s4 as text
%        str2double(get(hObject,'String')) returns contents of s4 as a double
S4 = get(hObject,'String');
handles.S4 = sscanf(S4,'%d');
guidata(hObject,handles)


% --- Executes during object creation, after setting all properties.
function s4_CreateFcn(hObject, eventdata, handles)
% hObject    handle to s4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end
S4 =  [0 0 0];
handles.S4 = S4';
guidata(hObject,handles)

% --- Executes on button press in button.
function button_Callback(hObject, eventdata, handles)
% hObject    handle to button (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

if norm(handles.S1) == 0
    return
end

stop = 0;
k = length(handles.S1);           %To allow for flexibility in dimensions of input 
if norm(handles.S2) == 0          %and error prevention 
    handles.S2 = (zeros(1,k))';    
else if length(handles.S2) ~= k
        stop = 1;
     end
end
if norm(handles.S3) == 0
    handles.S3 = (zeros(1,k))';
    else if length(handles.S3) ~= k
            stop = 1;
        end
end
if norm(handles.S4) == 0
    handles.S4 = (zeros(1,k))';
    else if length(handles.S4)~= k
            stop = 1;
         end
end

if stop == 1
    errordlg('Enter signals with the same dimensions.');
    return;
end



S = [(handles.S1)'; (handles.S2)'; (handles.S3)'; (handles.S4)'];
x = S; 
v(1,:) = S(1,:)/norm(S(1,:));


index1 = S(1,:);
column = length(index1);
index2 = S(:,1);
row = length(index2);

for i = 2:4
j = i-1;
while j >= 1
S(i,:) = S(i,:) - dot(x(i,:),v(j,:))*v(j,:);
j = j - 1; 
end

if norm(S(i,:)) > 0.01
    v(i,:) = S(i,:)/norm(S(i,:));    %forcing approximation
else                                 %To avoid division by a very small number
    v(i,:) = S(i,:);
end

end 

v(abs(v)<0.01) = 0;                %Thresholding


   shape = []; 
for i = 1:row
    
    for j = 1:column
        shape = [shape ones(1,250)*v(i,j)];
    end
    
end

   t = 250 * column;
   frmsz = 1 / t;
   axis = [1:250*column]*frmsz;
   axes(handles.axes1)
   plot(axis, shape(1:250*column))
   AXIS([0 1 -1.1 1.1])
   grid
   axes(handles.axes2)
   plot(axis, shape(250*column+1:250*2*column))
   AXIS([0 1 -1.1 1.1])
   grid
   axes(handles.axes3)
   plot(axis, shape(250*2*column+1:250*3*column))
   AXIS([0 1 -1.1 1.1])
   grid
   axes(handles.axes4)
   plot(axis, shape(250*3*column+1:250*4*column))
   AXIS([0 1 -1.1 1.1])
   grid
   
% axes(handles.axes1)
% plot(shape(1))

        


% --- Executes during object creation, after setting all properties.
function text6_CreateFcn(hObject, eventdata, handles)
% hObject    handle to text6 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called


Contact us at files@mathworks.com