function varargout = FFT2_GUI(varargin)
% FFT2_GUI M-file for FFT2_GUI.fig
%      FFT2_GUI, by itself, creates a new FFT2_GUI or raises the existing
%      singleton*.
%
%      H = FFT2_GUI returns the handle to a new FFT2_GUI or the handle to
%      the existing singleton*.
%
%      FFT2_GUI('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in FFT2_GUI.M with the given input arguments.
%
%      FFT2_GUI('Property','Value',...) creates a new FFT2_GUI or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before FFT2_GUI_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to FFT2_GUI_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 FFT2_GUI

% Last Modified by GUIDE v2.5 21-Aug-2012 10:36:22

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @FFT2_GUI_OpeningFcn, ...
                   'gui_OutputFcn',  @FFT2_GUI_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 FFT2_GUI is made visible.
function FFT2_GUI_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 FFT2_GUI (see VARARGIN)

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

% Update handles structure
guidata(hObject, handles);

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

global check_reset
check_reset = 1;

global v 
v = 1:8;

global M
M = computefft();




% --- Outputs from this function are returned to the command line.
function varargout = FFT2_GUI_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;


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

% Hint: place code in OpeningFcn to populate axes1
cla
draw


function draw
row1x = [-7:2:7];
row1y = 6.5*ones(length(row1x));
cla
hold on
axis([-8,8,0,7])
axis off

row2x1 = [-6.5:4:5.5];
row2x2 = [-5.5:4:6.5];
row2y = 4.5*ones(length(row2x1));
row3x1 = [-5.5:1:-2.5];
row3x2 = [ 2.5:1: 5.5];
row3y = 2.5*ones(length(row2x1));
row4x = [-3.5:1:3.5];
row4y = 0.5*ones(length(row1x));

%Plot lines
for i = 1:2:7;
    plot([row1x(i) row2x1((i+1)/2)],[row1y(1)-0.5 row2y(1)],'color',[0.85,0.85,0.85])
    plot([row1x(i+1) row2x1((i+1)/2)],[row1y(1)-0.5 row2y(1)],'color',[0.85,0.85,0.85])
    plot([row1x(i) row2x2((i+1)/2)],[row1y(1)-0.5 row2y(1)],'color',[0.85,0.85,0.85])
    plot([row1x(i+1) row2x2((i+1)/2)],[row1y(1)-0.5 row2y(1)],'color',[0.85,0.85,0.85])
end

for i = 1:2;
    plot([row2x1(i) row3x1(1)],[row2y(1)-0.5 row3y(1)],'color',[0.85,0.85,0.85])
    plot([row2x1(i) row3x1(3)],[row2y(1)-0.5 row3y(1)],'color',[0.85,0.85,0.85])
    plot([row2x2(i) row3x1(2)],[row2y(1)-0.5 row3y(1)],'color',[0.85,0.85,0.85])
    plot([row2x2(i) row3x1(4)],[row2y(1)-0.5 row3y(1)],'color',[0.85,0.85,0.85])
    
    plot([row2x1(i+2) row3x2(1)],[row2y(1)-0.5 row3y(1)],'color',[0.85,0.85,0.85])
    plot([row2x1(i+2) row3x2(3)],[row2y(1)-0.5 row3y(1)],'color',[0.85,0.85,0.85])
    plot([row2x2(i+2) row3x2(2)],[row2y(1)-0.5 row3y(1)],'color',[0.85,0.85,0.85])
    plot([row2x2(i+2) row3x2(4)],[row2y(1)-0.5 row3y(1)],'color',[0.85,0.85,0.85])
end

for i = 1:4;
    plot([row3x1(i) row4x(i)],[row3y(1)-0.5 row4y(1)],'color',[0.85,0.85,0.85])
    plot([row3x1(i) row4x(i)],[row3y(1)-0.5 row4y(1)],'color',[0.85,0.85,0.85])
    plot([row3x2(i) row4x(i)],[row3y(1)-0.5 row4y(1)],'color',[0.85,0.85,0.85])
    plot([row3x2(i) row4x(i)],[row3y(1)-0.5 row4y(1)],'color',[0.85,0.85,0.85])
    plot([row3x1(i) row4x(i+4)],[row3y(1)-0.5 row4y(1)],'color',[0.85,0.85,0.85])
    plot([row3x1(i) row4x(i+4)],[row3y(1)-0.5 row4y(1)],'color',[0.85,0.85,0.85])
    plot([row3x2(i) row4x(i+4)],[row3y(1)-0.5 row4y(1)],'color',[0.85,0.85,0.85])
    plot([row3x2(i) row4x(i+4)],[row3y(1)-0.5 row4y(1)],'color',[0.85,0.85,0.85])
    
end


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


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



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


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

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

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


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

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

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

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

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

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

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

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

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

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

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


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

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

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

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

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

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

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

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


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

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

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

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

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

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

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

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



% --- Executes on button press in Reset.
function Reset_Callback(hObject, eventdata, handles)
% hObject    handle to Reset (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
 global check_reset; 
 check_reset = 0; 
 push01row1_fun(handles)
 push02row1_fun(handles)
 push03row1_fun(handles)
 push04row1_fun(handles)
 push05row1_fun(handles)
 push06row1_fun(handles)
 push07row1_fun(handles)
 push08row1_fun(handles)
 axes1_CreateFcn(hObject, eventdata, handles)
 check_reset = 1;





function edit1_Callback(hObject, eventdata, handles)
% hObject    handle to edit1 (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 edit1 as text
%        str2double(get(hObject,'String')) returns contents of edit1 as a double
global v
v(1) = str2double(get(hObject,'String'));
global M
M = computefft();


% --- Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit1 (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



function edit2_Callback(hObject, eventdata, handles)
% hObject    handle to edit2 (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 edit2 as text
%        str2double(get(hObject,'String')) returns contents of edit2 as a double
global v
v(2) = str2double(get(hObject,'String'));
global M
M = computefft();

% --- Executes during object creation, after setting all properties.
function edit2_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit2 (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



function edit3_Callback(hObject, eventdata, handles)
% hObject    handle to edit3 (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 edit3 as text
%        str2double(get(hObject,'String')) returns contents of edit3 as a double
global v
v(3) = str2double(get(hObject,'String'));
global M
M = computefft();


% --- Executes during object creation, after setting all properties.
function edit3_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit3 (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



function edit4_Callback(hObject, eventdata, handles)
% hObject    handle to edit4 (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 edit4 as text
%        str2double(get(hObject,'String')) returns contents of edit4 as a double
global v
v(4) = str2double(get(hObject,'String'));
global M
M = computefft();


% --- Executes during object creation, after setting all properties.
function edit4_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit4 (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



function edit5_Callback(hObject, eventdata, handles)
% hObject    handle to edit5 (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 edit5 as text
%        str2double(get(hObject,'String')) returns contents of edit5 as a double
global v
v(5) = str2double(get(hObject,'String'));
global M
M = computefft();


% --- Executes during object creation, after setting all properties.
function edit5_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit5 (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



function edit6_Callback(hObject, eventdata, handles)
% hObject    handle to edit6 (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 edit6 as text
%        str2double(get(hObject,'String')) returns contents of edit6 as a double
global v
v(6) = str2double(get(hObject,'String'));
global M
M = computefft();


% --- Executes during object creation, after setting all properties.
function edit6_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit6 (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



function edit7_Callback(hObject, eventdata, handles)
% hObject    handle to edit7 (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 edit7 as text
%        str2double(get(hObject,'String')) returns contents of edit7 as a double
global v
v(7) = str2double(get(hObject,'String'));
global M
M = computefft();

% --- Executes during object creation, after setting all properties.
function edit7_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit7 (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



function edit8_Callback(hObject, eventdata, handles)
% hObject    handle to edit8 (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 edit8 as text
%        str2double(get(hObject,'String')) returns contents of edit8 as a double
global v
v(8) = str2double(get(hObject,'String'));
global M
M = computefft();


% --- Executes during object creation, after setting all properties.
function edit8_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit8 (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


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

% Hint: place code in OpeningFcn to populate axes3
chooserootsof1(1);


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

% Hint: place code in OpeningFcn to populate axes4
chooserootsof1(2);

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

% Hint: place code in OpeningFcn to populate axes5
chooserootsof1(3);

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

% Hint: place code in OpeningFcn to populate axes6
chooserootsof1(4);

function[M] = computefft()
global v
M = zeros(4,8);
M(1,:) = v;

for k = 1:4;
    M(2,2*k-1) = M(1,2*k-1) + M(1,2*k);
    M(2,2*k) =  M(1,2*k-1) - M(1,2*k);
end

for k = 1:2;
    M(3,2*k-1) = M(2, 1) + (-1)^(k-1)*M(2,3);
    M(3,2*k) = M(2, 2) + (-1)^(k-1)*i*M(2,4);
    M(3,2*k-1+4) = M(2, 5) + (-1)^(k-1)*M(2,7);
    M(3,2*k+4) = M(2, 6) + (-1)^(k-1)*i*M(2,8);
end

M(4,1) = M(3,1)+ M(3,5);
M(4,2) = M(3,2)+ ((1+i)/sqrt(2))*M(3,6);
M(4,3) = M(3,3)+ i*M(3,7);
M(4,4) = M(3,4)+ ((-1+i)/sqrt(2))*M(3,8);
M(4,5) = M(3,1)- M(3,5);
M(4,6) = M(3,2)- ((1+i)/sqrt(2))*M(3,6);
M(4,7) = M(3,3)- i*M(3,7);
M(4,8) = M(3,4)- ((-1+i)/sqrt(2))*M(3,8);

%Round matrix entries to 2 d.p.
t = 10^2;
M = round(M*t)/t;

function[] = highlight(handles,row,col);
c = [0 0 0.6];

global check_reset
if check_reset ~= 0;
row1x = [-7:2:7];
row1y = 6.5*ones(length(row1x));
row2x1 = [-6.5:4:5.5];
row2x2 = [-5.5:4:6.5];
row2y = 4.5*ones(length(row2x1));
row3x1 = [-5.5:1:-2.5];
row3x2 = [ 2.5:1: 5.5];
row3y = 2.5*ones(length(row2x1));
row4x = [-3.5:1:3.5];
row4y = 0.5*ones(length(row1x));

hold on
i = col;
if row == 2
    if mod(col-1,2) == 0;
        plot(handles.axes1,[row1x(i) row2x1((i+1)/2)],[row1y(1)-0.5 row2y(1)],'color',c) 
        plot(handles.axes1,[row1x(i+1) row2x1((i+1)/2)],[row1y(1)-0.5 row2y(1)],'color',c) 
    else
        plot(handles.axes1,[row1x(i) row2x2((i)/2)],[row1y(1)-0.5 row2y(1)],'color',c)  
        plot(handles.axes1,[row1x(i-1) row2x2((i)/2)],[row1y(1)-0.5 row2y(1)],'color',c)  
    end
end

if row == 3;
    switch mod(col,4)
        case 1
            if col < 5
               plot(handles.axes1,[row2x1(1) row3x1(1)],[row2y(1)-0.5 row3y(1)],'color',c)
               plot(handles.axes1,[row2x1(2) row3x1(1)],[row2y(1)-0.5 row3y(1)],'color',c)
            else
               plot(handles.axes1,[row2x1(3) row3x2(1)],[row2y(1)-0.5 row3y(1)],'color',c)
               plot(handles.axes1,[row2x1(4) row3x2(1)],[row2y(1)-0.5 row3y(1)],'color',c) 
            end
            highlight(handles,2,col);
            highlight(handles,2,col+2);
        case 2
            if col < 5
                plot(handles.axes1,[row2x2(1) row3x1(2)],[row2y(1)-0.5 row3y(1)],'color',c)
                plot(handles.axes1,[row2x2(2) row3x1(2)],[row2y(1)-0.5 row3y(1)],'color',c)
            else
                plot(handles.axes1,[row2x2(3) row3x2(2)],[row2y(1)-0.5 row3y(1)],'color',c)
                plot(handles.axes1,[row2x2(4) row3x2(2)],[row2y(1)-0.5 row3y(1)],'color',c)
            end
            highlight(handles,2,col);
            highlight(handles,2,col+2);
        case 3
            if col < 5
                plot(handles.axes1,[row2x1(1) row3x1(3)],[row2y(1)-0.5 row3y(1)],'color',c)
                plot(handles.axes1,[row2x1(2) row3x1(3)],[row2y(1)-0.5 row3y(1)],'color',c)
            else
                plot(handles.axes1,[row2x1(3) row3x2(3)],[row2y(1)-0.5 row3y(1)],'color',c)
                plot(handles.axes1,[row2x1(4) row3x2(3)],[row2y(1)-0.5 row3y(1)],'color',c)
            end
            highlight(handles,2,col);
            highlight(handles,2,col-2);   
        case 0
            if col < 5
                plot(handles.axes1,[row2x2(1) row3x1(4)],[row2y(1)-0.5 row3y(1)],'color',c)
                plot(handles.axes1,[row2x2(2) row3x1(4)],[row2y(1)-0.5 row3y(1)],'color',c)
            else
                plot(handles.axes1,[row2x2(3) row3x2(4)],[row2y(1)-0.5 row3y(1)],'color',c)
                plot(handles.axes1,[row2x2(4) row3x2(4)],[row2y(1)-0.5 row3y(1)],'color',c)
            end
            highlight(handles,2,col);
            highlight(handles,2,col-2);
            
            
    end
end

if row == 4;
    switch mod(col,4)
        case 1
            if col < 5
               plot(handles.axes1,[row3x1(1) row4x(1)],[row3y(1)-0.5 row4y(1)],'color',c)
               plot(handles.axes1,[row3x2(1) row4x(1)],[row3y(1)-0.5 row4y(1)],'color',c)
               highlight(handles,3,col);
               highlight(handles,3,col+4);
            else
               plot(handles.axes1,[row3x1(1) row4x(5)],[row3y(1)-0.5 row4y(1)],'color',c)
               plot(handles.axes1,[row3x2(1) row4x(5)],[row3y(1)-0.5 row4y(1)],'color',c)
               highlight(handles,3,col);
               highlight(handles,3,col-4);
            end
        case 2
            if col < 5
               plot(handles.axes1,[row3x1(2) row4x(2)],[row3y(1)-0.5 row4y(1)],'color',c)
               plot(handles.axes1,[row3x2(2) row4x(2)],[row3y(1)-0.5 row4y(1)],'color',c)
               highlight(handles,3,col);
               highlight(handles,3,col+4);
            else
               plot(handles.axes1,[row3x1(2) row4x(6)],[row3y(1)-0.5 row4y(1)],'color',c)
               plot(handles.axes1,[row3x2(2) row4x(6)],[row3y(1)-0.5 row4y(1)],'color',c)
               highlight(handles,3,col);
               highlight(handles,3,col-4);
            end
        case 3
            if col < 5
               plot(handles.axes1,[row3x1(3) row4x(3)],[row3y(1)-0.5 row4y(1)],'color',c)
               plot(handles.axes1,[row3x2(3) row4x(3)],[row3y(1)-0.5 row4y(1)],'color',c)
               highlight(handles,3,col);
               highlight(handles,3,col+4);
            else
               plot(handles.axes1,[row3x1(3) row4x(7)],[row3y(1)-0.5 row4y(1)],'color',c)
               plot(handles.axes1,[row3x2(3) row4x(7)],[row3y(1)-0.5 row4y(1)],'color',c)
               highlight(handles,3,col);
               highlight(handles,3,col-4);
            end
        case 0
            if col < 5
               plot(handles.axes1,[row3x1(4) row4x(4)],[row3y(1)-0.5 row4y(1)],'color',c)
               plot(handles.axes1,[row3x2(4) row4x(4)],[row3y(1)-0.5 row4y(1)],'color',c)
               highlight(handles,3,col);
               highlight(handles,3,col+4);
            else
               plot(handles.axes1,[row3x1(4) row4x(8)],[row3y(1)-0.5 row4y(1)],'color',c)
               plot(handles.axes1,[row3x2(4) row4x(8)],[row3y(1)-0.5 row4y(1)],'color',c)
               highlight(handles,3,col);
               highlight(handles,3,col-4);
            end            
    end
end
else
    %do nothing!
end
    
  


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








% --- Executes on button press in push01row1.
function push01row1_fun(handles)
% hObject    handle to push01row1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global check_reset; 
global M;
set(handles.push01row1,'string', num2str(M(4,1)))
if check_reset == 1;
    set(handles.push01row1,'BackgroundColor', [0.1111    0.5556    0.4000] )
else
    set(handles.push01row1,'BackgroundColor', [0.941,0.941,0.941],'string','')
end
highlight(handles,4,1)
push01row2_fun(handles)
push05row2_fun(handles)



% --- Executes on button press in push02row1.
function push02row1_fun(handles)
% hObject    handle to push02row1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global check_reset; 
global M;
set(handles.push02row1,'string', num2str(M(4,2)))
if check_reset == 1;
    set(handles.push02row1,'BackgroundColor', [0.2381    0.6190    0.4000] )
else
    set(handles.push02row1,'BackgroundColor', [0.941,0.941,0.941],'string','')
end
highlight(handles,4,2)
push02row2_fun(handles)
push06row2_fun(handles)


% --- Executes on button press in push03row1.
function push03row1_fun(handles)
% hObject    handle to push03row1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global check_reset; 
global M;
set(handles.push03row1,'string', num2str(M(4,3)))
if check_reset == 1;
    set(handles.push03row1,'BackgroundColor', [0.3651    0.6825    0.4000] )
else
    set(handles.push03row1,'BackgroundColor', [0.941,0.941,0.941],'string','')
end
highlight(handles,4,3)
push03row2_fun(handles)
push07row2_fun(handles)


% --- Executes on button press in push04row1.
function push04row1_fun(handles)
% hObject    handle to push04row1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global check_reset; 
global M;
set(handles.push04row1,'string', num2str(M(4,4)))
if check_reset == 1;
    set(handles.push04row1,'BackgroundColor', [0.4921    0.7460    0.4000] )
else
    set(handles.push04row1,'BackgroundColor', [0.941,0.941,0.941],'string','')
end
highlight(handles,4,4)
push04row2_fun(handles)
push08row2_fun(handles)


% --- Executes on button press in push05row1.
function push05row1_fun(handles)
% hObject    handle to push05row1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global check_reset; 
global M;
set(handles.push05row1,'string', num2str(M(4,5)))
if check_reset == 1;
    set(handles.push05row1,'BackgroundColor', [0.6190    0.8095    0.4000] )
else
    set(handles.push05row1,'BackgroundColor', [0.941,0.941,0.941],'string','')
end
highlight(handles,4,5)
push01row2_fun(handles)
push05row2_fun(handles)


% --- Executes on button press in push06row1.
function push06row1_fun(handles)
% hObject    handle to push06row1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global check_reset
global M;
set(handles.push06row1,'string', num2str(M(4,6))) 
if check_reset == 1;
    set(handles.push06row1,'BackgroundColor', [0.7460    0.8730    0.4000] )
else
    set(handles.push06row1,'BackgroundColor', [0.941,0.941,0.941],'string','')
end
highlight(handles,4,6)
push02row2_fun(handles)
push06row2_fun(handles)

% --- Executes on button press in push07row1.
function push07row1_fun(handles)
% hObject    handle to push07row1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global check_reset; 
global M;
set(handles.push07row1,'string', num2str(M(4,7)))
if check_reset == 1;
    set(handles.push07row1,'BackgroundColor', [0.8730    0.9365    0.4000] )
else
    set(handles.push07row1,'BackgroundColor', [0.941,0.941,0.941],'string','')
end
highlight(handles,4,7)
push03row2_fun(handles)
push07row2_fun(handles)

% --- Executes on button press in push08row1.
function push08row1_fun(handles)
% hObject    handle to push08row1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global check_reset; 
global M;
set(handles.push08row1,'string', num2str(M(4,8)))

if check_reset == 1;
    set(handles.push08row1,'BackgroundColor', [1.0000    1.0000    0.4000] )
else
    set(handles.push08row1,'BackgroundColor', [0.941,0.941,0.941],'string','')
end
highlight(handles,4,8)
push04row2_fun(handles)
push08row2_fun(handles)


% --- Executes on button press in push01row2.
function push01row2_fun(handles)
% hObject    handle to push01row2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global check_reset; 
global M;
set(handles.push01row2,'string', num2str(M(3,1)))
if check_reset == 1;
    set(handles.push01row2,'BackgroundColor', [0.1111    0.5556    0.4000] )
else
    set(handles.push01row2,'BackgroundColor', [0.941,0.941,0.941],'string','')
end
highlight(handles,3,1)
push01row3_fun(handles)
push03row3_fun(handles)

% --- Executes on button press in push02row2.
function push02row2_fun(handles)
% hObject    handle to push02row2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global check_reset; 
global M;
set(handles.push02row2,'string', num2str(M(3,2)))
if check_reset == 1;
    set(handles.push02row2,'BackgroundColor', [0.3651    0.6825    0.4000] )
else
    set(handles.push02row2,'BackgroundColor', [0.941,0.941,0.941],'string','')
end
highlight(handles,3,2)
push02row3_fun(handles)
push04row3_fun(handles)

% --- Executes on button press in push03row2.
function push03row2_fun(handles)
% hObject    handle to push03row2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global check_reset; 
global M;
set(handles.push03row2,'string', num2str(M(3,3)))
if check_reset == 1;
    set(handles.push03row2,'BackgroundColor', [0.6190    0.8095    0.4000] )
else
    set(handles.push03row2,'BackgroundColor', [0.941,0.941,0.941],'string','')
end
highlight(handles,3,3)
push01row3_fun(handles)
push03row3_fun(handles)

% --- Executes on button press in push04row2.
function push04row2_fun(handles)
% hObject    handle to push04row2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global check_reset; 
global M;
set(handles.push04row2,'string', num2str(M(3,4)))
if check_reset == 1;
    set(handles.push04row2,'BackgroundColor', [0.8730    0.9365    0.4000] )
else
    set(handles.push04row2,'BackgroundColor', [0.941,0.941,0.941],'string','')
end
highlight(handles,3,4)
push02row3_fun(handles)
push04row3_fun(handles)

% --- Executes on button press in push05row2.
function push05row2_fun(handles)
% hObject    handle to push05row2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global check_reset; 
global M;
set(handles.push05row2,'string', num2str(M(3,5)))
if check_reset == 1;
    set(handles.push05row2,'BackgroundColor', [0.1111    0.5556    0.4000] )
else
    set(handles.push05row2,'BackgroundColor', [0.941,0.941,0.941],'string','')
end
highlight(handles,3,5)
push05row3_fun(handles)
push07row3_fun(handles)

% --- Executes on button press in push06row2.
function push06row2_fun(handles)
% hObject    handle to push06row2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global check_reset; 
global M;
set(handles.push06row2,'string', num2str(M(3,6)))
if check_reset == 1;
    set(handles.push06row2,'BackgroundColor', [0.3651    0.6825    0.4000] )
else
    set(handles.push06row2,'BackgroundColor', [0.941,0.941,0.941],'string','')
end
highlight(handles,3,6)
push06row3_fun(handles)
push08row3_fun(handles)


% --- Executes on button press in push07row2.
function push07row2_fun(handles)
% hObject    handle to push07row2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global check_reset; 
global M;
set(handles.push07row2,'string', num2str(M(3,7)))
if check_reset == 1;
    set(handles.push07row2,'BackgroundColor', [0.6190    0.8095    0.4000] )
else
    set(handles.push07row2,'BackgroundColor', [0.941,0.941,0.941],'string','')
end
highlight(handles,3,7)
push05row3_fun(handles)
push07row3_fun(handles)

% --- Executes on button press in push08row2.
function push08row2_fun(handles)
% hObject    handle to push08row2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global check_reset; 
global M;
set(handles.push08row2,'string', num2str(M(3,8)))
if check_reset == 1;
    set(handles.push08row2,'BackgroundColor', [0.8730    0.9365    0.4000] )
else
    set(handles.push08row2,'BackgroundColor', [0.941,0.941,0.941],'string','')
end
highlight(handles,3,8)
push06row3_fun(handles)
push08row3_fun(handles)


% --- Executes on button press in push01row3.
function push01row3_fun(handles)
% hObject    handle to push01row3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global check_reset; 
global M;
set(handles.push01row3,'string', num2str(M(2,1)))
if check_reset == 1;
    set(handles.push01row3,'BackgroundColor', [0.1111    0.5556    0.4000] )
else
    set(handles.push01row3,'BackgroundColor', [0.941,0.941,0.941],'string','')
end
highlight(handles,2,1)
push01row4_fun(handles)
push02row4_fun(handles)

% --- Executes on button press in push02row3.
function push02row3_fun(handles)
% hObject    handle to push02row3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global check_reset; 
global M;
set(handles.push02row3,'string', num2str(M(2,2)))
if check_reset == 1;
    set(handles.push02row3,'BackgroundColor', [0.6190    0.8095    0.4000] )
else
    set(handles.push02row3,'BackgroundColor', [0.941,0.941,0.941],'string','')
end
highlight(handles,2,2)
push01row4_fun(handles)
push02row4_fun(handles)

% --- Executes on button press in push03row3.
function push03row3_fun(handles)
% hObject    handle to push03row3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global check_reset; 
global M;
set(handles.push03row3,'string', num2str(M(2,3)))
if check_reset == 1;
    set(handles.push03row3,'BackgroundColor', [0.1111    0.5556    0.4000] )
else
    set(handles.push03row3,'BackgroundColor', [0.941,0.941,0.941],'string','')
end
highlight(handles,2,3)
push03row4_fun(handles)
push04row4_fun(handles)

% --- Executes on button press in push04row3.
function push04row3_fun(handles)
% hObject    handle to push04row3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global check_reset; 
global M;
set(handles.push04row3,'string', num2str(M(2,4)))
if check_reset == 1;
    set(handles.push04row3,'BackgroundColor', [0.6190    0.8095    0.4000] )
else
    set(handles.push04row3,'BackgroundColor', [0.941,0.941,0.941],'string','')
end
highlight(handles,2,4)
push03row4_fun(handles)
push04row4_fun(handles)

% --- Executes on button press in push05row3.
function push05row3_fun(handles)
% hObject    handle to push05row3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global check_reset; 
global M;
set(handles.push05row3,'string', num2str(M(2,5)))
if check_reset == 1;
    set(handles.push05row3,'BackgroundColor', [0.1111    0.5556    0.4000] )
else
    set(handles.push05row3,'BackgroundColor', [0.941,0.941,0.941],'string','')
end
highlight(handles,2,5)
push05row4_fun(handles)
push06row4_fun(handles)

% --- Executes on button press in push06row3.
function push06row3_fun(handles)
% hObject    handle to push06row3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global check_reset; 
global M;
set(handles.push06row3,'string', num2str(M(2,6)))
if check_reset == 1;
    set(handles.push06row3,'BackgroundColor', [0.6190    0.8095    0.4000] )
else
    set(handles.push06row3,'BackgroundColor', [0.941,0.941,0.941],'string','')
end
highlight(handles,2,6)
push05row4_fun(handles)
push06row4_fun(handles)

% --- Executes on button press in push07row3.
function push07row3_fun(handles)
% hObject    handle to push07row3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global check_reset; 
global M;
set(handles.push07row3,'string', num2str(M(2,7)))
if check_reset == 1;
    set(handles.push07row3,'BackgroundColor', [0.1111    0.5556    0.4000] )
else
    set(handles.push07row3,'BackgroundColor', [0.941,0.941,0.941],'string','')
end
highlight(handles,2,7)
push07row4_fun(handles)
push08row4_fun(handles)

% --- Executes on button press in push08row3.
function push08row3_fun(handles)
% hObject    handle to push08row3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global check_reset; 
global M;
set(handles.push08row3,'string', num2str(M(2,8)))
if check_reset == 1;
    set(handles.push08row3,'BackgroundColor', [0.6190    0.8095    0.4000] )
else
    set(handles.push08row3,'BackgroundColor', [0.941,0.941,0.941],'string','')
end
highlight(handles,2,8)
push07row4_fun(handles)
push08row4_fun(handles)


% --- Executes on button press in push01row4.
function push01row4_fun(handles)
% hObject    handle to push01row4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global check_reset; 
global M;
set(handles.push01row4,'string', num2str(M(1,1)))
if check_reset == 1;
    set(handles.push01row4,'BackgroundColor', [0.1111    0.5556    0.4000] )
else
    set(handles.push01row4,'BackgroundColor', [0.941,0.941,0.941],'string','')
end

% --- Executes on button press in push02row4.
function push02row4_fun(handles)
% hObject    handle to push02row4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global check_reset; 
global M;
set(handles.push02row4,'string', num2str(M(1,2)))
if check_reset == 1;
    set(handles.push02row4,'BackgroundColor', [0.1111    0.5556    0.4000] )
else
    set(handles.push02row4,'BackgroundColor', [0.941,0.941,0.941],'string','')
end

% --- Executes on button press in push03row4.
function push03row4_fun(handles)
% hObject    handle to push03row4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global check_reset; 
global M;
set(handles.push03row4,'string', num2str(M(1,3)))
if check_reset == 1;
    set(handles.push03row4,'BackgroundColor', [0.1111    0.5556    0.4000] )
else
    set(handles.push03row4,'BackgroundColor', [0.941,0.941,0.941],'string','')
end

% --- Executes on button press in push04row4.
function push04row4_fun(handles)
% hObject    handle to push04row4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global check_reset; 
global M;
set(handles.push04row4,'string', num2str(M(1,4)))
if check_reset == 1;
    set(handles.push04row4,'BackgroundColor', [0.1111    0.5556    0.4000] )
else
    set(handles.push04row4,'BackgroundColor', [0.941,0.941,0.941],'string','')
end

% --- Executes on button press in push05row4.
function push05row4_fun(handles)
% hObject    handle to push05row4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global check_reset; 
global M;
set(handles.push05row4,'string', num2str(M(1,5)))
if check_reset == 1;
    set(handles.push05row4,'BackgroundColor', [0.1111    0.5556    0.4000] )
else
    set(handles.push05row4,'BackgroundColor', [0.941,0.941,0.941],'string','')
end

% --- Executes on button press in push06row4.
function push06row4_fun(handles)
% hObject    handle to push06row4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global check_reset; 
global M;
set(handles.push06row4,'string', num2str(M(1,6)))
if check_reset == 1;
    set(handles.push06row4,'BackgroundColor', [0.1111    0.5556    0.4000] )
else
    set(handles.push06row4,'BackgroundColor', [0.941,0.941,0.941],'string','')
end

% --- Executes on button press in push07row4.
function push07row4_fun(handles)
% hObject    handle to push07row4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global check_reset; 
global M;
set(handles.push07row4,'string', num2str(M(1,7)))
if check_reset == 1;
    set(handles.push07row4,'BackgroundColor', [0.1111    0.5556    0.4000] )
else
    set(handles.push07row4,'BackgroundColor', [0.941,0.941,0.941],'string','')
end

% --- Executes on button press in push08row4.
function push08row4_fun(handles)
% hObject    handle to push08row4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global check_reset; 
global M;
set(handles.push08row4,'string', num2str(M(1,8)))
if check_reset == 1;
    set(handles.push08row4,'BackgroundColor', [0.1111    0.5556    0.4000] )
else
    set(handles.push08row4,'BackgroundColor', [0.941,0.941,0.941],'string','')
end

function[] = chooserootsof1(level)
% Level = 1 : 1th roots of 1
% Level = 2 : 2th roots of 1
% Level = 3 : 4th roots of 1
% Level = 4 : 8th roots of 1

v = [0.1111    0.5556    0.4000;
    0.2381    0.6190    0.4000;
    0.3651    0.6825    0.4000;
    0.4921    0.7460    0.4000;
    0.6190    0.8095    0.4000;
    0.7460    0.8730    0.4000;
    0.8730    0.9365    0.4000;
    1.0000    1.0000    0.4000;];


t = [0:0.00001:2*pi];
plot(cos(t), sin(t),'color',[0.7,0.7,0.7],'linewidth',1)
hold on

for k = 0:7;
    plot(real(exp(i*k*2*pi/8)),imag(exp(i*k*2*pi/8)),'o','MarkerEdgeColor','k', 'MarkerFaceColor', [0.6,0.6,0.6] , 'MarkerSize',12);
end

if level >= 1;
   p1 = plot(1, 0,'o','MarkerEdgeColor','k', 'MarkerFaceColor', v(1,:,:) , 'MarkerSize',12);
end
if level >= 2;
    x = [real(exp(i*0*2*pi/8)),real(exp(i*4*2*pi/8))];
    y = [imag(exp(i*0*2*pi/8)),imag(exp(i*4*2*pi/8))];
    plot(x,y,'-','color',[0.6,0.6,0.6])
    p1 = plot(1, 0,'o','MarkerEdgeColor','k', 'MarkerFaceColor', v(1,:,:) , 'MarkerSize',12);
    p5 = plot(-1, 0,'o','MarkerEdgeColor','k', 'MarkerFaceColor',v(5,:,:), 'MarkerSize',12);
end
if level >= 3;
    x = [real(exp(i*0*2*pi/8)),real(exp(i*2*2*pi/8)),real(exp(i*4*2*pi/8)),real(exp(i*6*2*pi/8)),real(exp(i*0*2*pi/8))];
    y = [imag(exp(i*0*2*pi/8)),imag(exp(i*2*2*pi/8)),imag(exp(i*4*2*pi/8)),imag(exp(i*6*2*pi/8)),imag(exp(i*0*2*pi/8))];
    plot(x,y,'-','color',[0.6,0.6,0.6])
    p3 = plot(0, 1,'o','MarkerEdgeColor','k', 'MarkerFaceColor',v(3,:,:), 'MarkerSize',12);
    p7 = plot(0, -1,'o','MarkerEdgeColor','k', 'MarkerFaceColor',v(7,:,:), 'MarkerSize',12);
    p1 = plot(1, 0,'o','MarkerEdgeColor','k', 'MarkerFaceColor', v(1,:,:) , 'MarkerSize',12);
    p5 = plot(-1, 0,'o','MarkerEdgeColor','k', 'MarkerFaceColor',v(5,:,:), 'MarkerSize',12);
end
if level >= 4
    for k = 0:7;
        x(k+1) = real(exp(i*k*2*pi/8));
        y(k+1) = imag(exp(i*k*2*pi/8));
    end
    x = [x, x(1)];
    y = [y, y(1)];
    plot(x,y,'-','color',[0.6,0.6,0.6])
    p3 = plot(0, 1,'o','MarkerEdgeColor','k', 'MarkerFaceColor',v(3,:,:), 'MarkerSize',12);
    p7 = plot(0, -1,'o','MarkerEdgeColor','k', 'MarkerFaceColor',v(7,:,:), 'MarkerSize',12);
    p1 = plot(1, 0,'o','MarkerEdgeColor','k', 'MarkerFaceColor', v(1,:,:) , 'MarkerSize',12);
    p5 = plot(-1, 0,'o','MarkerEdgeColor','k', 'MarkerFaceColor',v(5,:,:), 'MarkerSize',12);
    p2 = plot(cos(pi/4), sin(pi/4),'o','MarkerEdgeColor','k', 'MarkerFaceColor',v(2,:,:), 'MarkerSize',12);
    p4 = plot(cos(3*pi/4), sin(3*pi/4),'o','MarkerEdgeColor','k', 'MarkerFaceColor',v(4,:,:), 'MarkerSize',12);
    p6 = plot(cos(5*pi/4), sin(5*pi/4),'o','MarkerEdgeColor','k', 'MarkerFaceColor',v(6,:,:), 'MarkerSize',12);
    p8 = plot(cos(7*pi/4), sin(7*pi/4),'o','MarkerEdgeColor','k', 'MarkerFaceColor',v(8,:,:), 'MarkerSize',12);
end
axis square
axis off


function[ff] = fourier(v)
% Computes the values of the every step of fft for n = 8. Values are stored
% in a matrix where rows correspond to rows in GUI, and entries do as well.
% v is the row with the 8 entries from top row in GUI.


omega1 = cos(pi/4)+i*sin(pi/4);
omega2 = 3*omega1;
% Top row (4th row)
ff(1,:) = v;

% 3rd row
for j = 1:2:7;
    ff(2,j) = ff(1,j) + ff(1,j+1);
    ff(2,j+1) = ff(1,j) - ff(1,j+1);
end

% 2nd row
for j = 1:4:5
    ff(3,j) = ff(2,j) + ff(2,j+2);
    ff(3,j+1) = ff(2,j+1) + i*ff(2,j+3);
    ff(3,j+2) = ff(2,j) - ff(2,j+2);
    ff(3,j+3) = ff(2,j+1) - i*ff(2,j+3);
end

% 1nd row
j = 1;
ff(4,j) = ff(3,j) + ff(3,j+4);
ff(4,j+4) = ff(3,j) - ff(3,j+4);
ff(4,j+1) = ff(3,j+1) + omega1*ff(3,j+5);
ff(4,j+5) = ff(3,j+1) - omega1*ff(3,j+5);
ff(4,j+2) = ff(3,j+2) + i*ff(3,j+6);
ff(4,j+6) = ff(3,j+2) - i*ff(3,j+6);
ff(4,j+3) = ff(3,j+3) + omega2*ff(3,j+7);
ff(4,j+7) = ff(3,j+3) - omega2*ff(3,j+7);
