function fig=createsignal_gui
% createsignal_gui
%
% user interface for signal creation
%

fig=createmadfig('create'); 
set(fig,'CloseRequestFcn','createsignal cancel');


figcol=get(fig,'Color');
bc=figcol;
wc=[1.0 1.0 1.0];

pwidth=0.135;
pheight=0.04; eheight=0.05;
yinc=0.07;
colsep=-0.00;
namewidth=0.13; boxwidth=0.11; unitswidth=0.04;
cols=[0.01 0.2 0.33 0.41 0.45 0.5 0.65 0.71 0.75 0.8];

ypos=0.8;
bheight=0.08;
ud.axes = axes('Parent',fig,...
  'Position',[0.1 ypos 0.35 0.15],...
		  'DrawMode','fast',...
		  'NextPlot','replacechildren',...
		  'Box','on');
       xlabel('samples')
       ylabel('amplitude')

ud.dftaxes = axes('Parent',fig,...
  'Position',[0.5 ypos 0.35 0.15],...
		  'DrawMode','fast',...
		  'NextPlot','replacechildren',...
		  'Box','on','YTick',[]);
      xlabel('frequency')
      ylabel('dB')

      uicontrol('Parent',fig, ...
	'Position',[0.87 0.8  0.08 0.05], 'Callback','createsignal clear',...
	'String','clear', 'Style','pushbutton','Tag','clearButton','Enable','off');
uicontrol('Parent',fig, ...
	'Position',[0.87 0.9  0.08 0.05], 'Callback','createsignal add',...
	'String','add', 'Style','pushbutton','Tag','addButton','Enable','off');
uicontrol('Parent',fig, ...
	'Position',[0.87 0.20  0.08 0.05], 'Callback','createsignal save',...
	'String','save', 'Style','pushbutton','Tag','saveButton','Enable','off');
uicontrol('Parent',fig, ...
	'Position',[0.87 0.12  0.08 0.05], 'Callback','createsignal cancel',...
	'String','cancel', 'Style','pushbutton','Tag','cancelButton');
uicontrol('Parent',fig, ...
	'Position',[0.87 0.05  0.08 0.05], 'Callback','createsignal done',...
	'String','done', 'Style','pushbutton','Tag','doneButton','Enable','off');
  
  
%---- signal type radios 

ypos=0.6;
% TONE
xpos=0.04;
uicontrol('Parent',fig, 'Position',[xpos-0.01 0.67-0.01 1.0 0.001],'Style','frame');
uicontrol('Parent',fig, 'Position',[0 ypos-0.01 1.0 0.001],'Style','frame');
uicontrol('Parent',fig, ...
  'Position',[xpos ypos pwidth pheight],...
  'Callback','createsignal handleradio',...
  'String','tone','Style','radio','HorizontalAlignment','left',...
  'Tag','sigradio','BackgroundColor','r');
  % FREQUENCY
xpos=xpos+pwidth;
uicontrol('Parent',fig, ...
  'Position',[xpos ypos namewidth pheight],...
  'String','frequency: ', ...
  'HorizontalAlignment','right', 'Style','text');
xpos=xpos+namewidth;
ud.freq=uicontrol('Parent',fig, ...
  'Position',[xpos ypos boxwidth eheight],...
	'String','1000', 'HorizontalAlignment','center', ...
	'Style','edit');
xpos=xpos+boxwidth;
uicontrol('Parent',fig, ...
  'Position',[xpos ypos unitswidth pheight],...
  'String',' Hz', 'HorizontalAlignment','left', 'Style','text');
  % PHASE
xpos=xpos+unitswidth+colsep;
uicontrol('Parent',fig, ...
  'Position',[xpos ypos namewidth pheight],...
  'String','phase: ', ...
  'HorizontalAlignment','right', 'Style','text');
xpos=xpos+namewidth;
ud.phase=uicontrol('Parent',fig, ...
  'Position',[xpos ypos boxwidth eheight],...
	'String','0', 'HorizontalAlignment','center', ...
	'Style','edit');
xpos=xpos+boxwidth;
uicontrol('Parent',fig, ...
  'Position',[xpos ypos unitswidth pheight],...
  'String',' o', 'HorizontalAlignment','left', 'Style','text');
  % LEVEL
% xpos=xpos+unitswidth+colsep;
% uicontrol('Parent',fig, ...
%   'Position',[xpos ypos namewidth pheight],...
%   'String','level:  ', ...
%   'HorizontalAlignment','right', 'Style','text');
xpos=xpos+namewidth;
ud.freqlevel=uicontrol('Parent',fig, ...
  'Position',[xpos ypos boxwidth eheight],...
	'String','70', 'HorizontalAlignment','center', ...
	'Style','edit');
xpos=xpos+boxwidth;
uicontrol('Parent',fig, ...
  'Position',[xpos ypos unitswidth pheight],...
  'String',' dB', 'HorizontalAlignment','left', 'Style','text');

% NOISE
ypos=ypos-yinc;
xpos=0.04;
uicontrol('Parent',fig, 'Position',[xpos-0.01 ypos-0.01 1.0 0.001],'Style','frame');
uicontrol('Parent',fig, ...
  'Position',[xpos ypos pwidth pheight],...
  'Callback','createsignal handleradio',...
  'String','noise','Style','radio','HorizontalAlignment','left',...
  'Tag','sigradio','BackgroundColor','r');
  % TYPE
xpos=xpos+pwidth;
ud.noisetype=uicontrol('Parent',fig, ...
  'Position',[xpos ypos namewidth pheight],...
  'String','spectrum: ', ...
  'HorizontalAlignment','right', 'Style','text');
xpos=xpos+namewidth;
uicontrol('Parent',fig, ...
  'Position',[xpos ypos boxwidth pheight+0.01],...
  'String','white', ...
  'Style','popupmenu', ...
  'Tag','freqsepPopup', ...
  'HorizontalAlignment','center',...
  'Value',1);
  % LEVEL
xpos=xpos+boxwidth;
xpos=xpos+unitswidth+colsep;
xpos=xpos+namewidth;
xpos=xpos+boxwidth;

% xpos=xpos+unitswidth+colsep;
% uicontrol('Parent',fig, ...
%   'Position',[xpos ypos namewidth pheight],...
%   'String','level:  ', ...
%   'HorizontalAlignment','right', 'Style','text');
xpos=xpos+namewidth;
ud.noiselevel=uicontrol('Parent',fig, ...
  'Position',[xpos ypos boxwidth eheight],...
	'String','70', 'HorizontalAlignment','center', ...
	'Style','edit');
xpos=xpos+boxwidth;
uicontrol('Parent',fig, ...
  'Position',[xpos ypos unitswidth pheight],...
  'String',' dB', 'HorizontalAlignment','left', 'Style','text');

% IMPULSES
ypos=ypos-yinc;
xpos=0.04;
uicontrol('Parent',fig, 'Position',[xpos-0.01 ypos-0.01 1.0 0.001],'Style','frame');
uicontrol('Parent',fig, ...
  'Position',[xpos ypos pwidth pheight],...
  'Callback','createsignal handleradio',...
  'String','impulses','Style','radio','HorizontalAlignment','left',...
  'Tag','sigradio','BackgroundColor','r');
  % FIRST
xpos=xpos+pwidth;
uicontrol('Parent',fig, ...
  'Position',[xpos ypos namewidth pheight],...
  'String','first: ', ...
  'HorizontalAlignment','right', 'Style','text');
xpos=xpos+namewidth;
ud.firstimpulse=uicontrol('Parent',fig, ...
  'Position',[xpos ypos boxwidth eheight],...
	'String','1', 'HorizontalAlignment','center', ...
	'Style','edit');
xpos=xpos+boxwidth;
uicontrol('Parent',fig, ...
  'Position',[xpos ypos unitswidth pheight],...
  'String',' ms', 'HorizontalAlignment','left', 'Style','text');
  % REPEAT RATE
xpos=xpos+unitswidth+colsep;
uicontrol('Parent',fig, ...
  'Position',[xpos ypos namewidth pheight],...
  'String','repeat at: ', ...
  'HorizontalAlignment','right', 'Style','text');
xpos=xpos+namewidth;
ud.repeatrate=uicontrol('Parent',fig, ...
  'Position',[xpos ypos boxwidth eheight],...
	'String','10', 'HorizontalAlignment','center', ...
	'Style','edit');
xpos=xpos+boxwidth;
uicontrol('Parent',fig, ...
  'Position',[xpos ypos unitswidth pheight],...
  'String',' ms', 'HorizontalAlignment','left', 'Style','text');
  % LEVEL
% xpos=xpos+unitswidth+colsep;
% uicontrol('Parent',fig, ...
%   'Position',[xpos ypos namewidth pheight],...
%   'String','level:  ', ...
%   'HorizontalAlignment','right', 'Style','text');
xpos=xpos+namewidth;
ud.impulseslevel=uicontrol('Parent',fig, ...
  'Position',[xpos ypos boxwidth eheight],...
	'String','70', 'HorizontalAlignment','center', ...
	'Style','edit');
xpos=xpos+boxwidth;
uicontrol('Parent',fig, ...
  'Position',[xpos ypos unitswidth pheight],...
  'String',' dB', 'HorizontalAlignment','left', 'Style','text');

  % HARMONIC SERIES
ypos=ypos-yinc;
xpos=0.04;
uicontrol('Parent',fig, 'Position',[xpos-0.01 ypos-0.01 1.0 0.001],'Style','frame');
uicontrol('Parent',fig, ...
  'Position',[xpos ypos pwidth pheight],...
  'Callback','createsignal handleradio',...
  'String','harmonics','Style','radio','HorizontalAlignment','left',...
  'Tag','sigradio','BackgroundColor','r');
  % FIRST
xpos=xpos+pwidth;
uicontrol('Parent',fig, ...
  'Position',[xpos ypos namewidth pheight],...
  'String','fundamental:  ', ...
  'HorizontalAlignment','right', 'Style','text');
xpos=xpos+namewidth;
ud.fundamental=uicontrol('Parent',fig, ...
  'Position',[xpos ypos boxwidth eheight],...
	'String','150', 'HorizontalAlignment','center', ...
	'Style','edit');
xpos=xpos+boxwidth;
uicontrol('Parent',fig, ...
  'Position',[xpos ypos unitswidth pheight],...
  'String',' Hz', 'HorizontalAlignment','left', 'Style','text');
  % NUMBER
xpos=xpos+unitswidth+colsep;
uicontrol('Parent',fig, ...
  'Position',[xpos ypos namewidth pheight],...
  'String','number: ', ...
  'HorizontalAlignment','right', 'Style','text');
xpos=xpos+namewidth;
ud.number=uicontrol('Parent',fig, ...
  'Position',[xpos ypos boxwidth pheight+0.01],...
  'String','2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20', ...
  'Style','popupmenu', ...
  'Tag','freqsepPopup', ...
  'HorizontalAlignment','center',...
  'Value',4);
  % LEVEL
xpos=xpos+boxwidth;
% xpos=xpos+unitswidth+colsep;
% uicontrol('Parent',fig, ...
%   'Position',[xpos ypos namewidth pheight],...
%   'String','level:  ', ...
%   'HorizontalAlignment','right', 'Style','text');
xpos=xpos+namewidth;
ud.harmonicslevel=uicontrol('Parent',fig, ...
  'Position',[xpos ypos boxwidth eheight],...
	'String','70', 'HorizontalAlignment','center', ...
	'Style','edit');
xpos=xpos+boxwidth;
uicontrol('Parent',fig, ...
  'Position',[xpos ypos unitswidth pheight],...
  'String',' dB', 'HorizontalAlignment','left', 'Style','text');

  % RESONANCE
ypos=ypos-yinc;
xpos=0.04;
uicontrol('Parent',fig, 'Position',[xpos-0.01 ypos-0.01 1.0 0.001],'Style','frame');
uicontrol('Parent',fig, ...
  'Position',[xpos ypos pwidth pheight],...
  'Callback','createsignal handleradio',...
  'String','resonance','Style','radio','HorizontalAlignment','left',...
  'Tag','sigradio','BackgroundColor','r');
  % FREQ
xpos=xpos+pwidth;
uicontrol('Parent',fig, ...
  'Position',[xpos ypos namewidth pheight],...
  'String','frequency:  ', ...
  'HorizontalAlignment','right', 'Style','text');
xpos=xpos+namewidth;
ud.resfreq=uicontrol('Parent',fig, ...
  'Position',[xpos ypos boxwidth eheight],...
	'String','300', 'HorizontalAlignment','center', ...
	'Style','edit');
xpos=xpos+boxwidth;
uicontrol('Parent',fig, ...
  'Position',[xpos ypos unitswidth pheight],...
  'String',' Hz', 'HorizontalAlignment','left', 'Style','text');
  % BANDWIDTH
xpos=xpos+unitswidth+colsep;
uicontrol('Parent',fig, ...
  'Position',[xpos ypos namewidth pheight],...
  'String','bandwidth:  ', ...
  'HorizontalAlignment','right', 'Style','text');
xpos=xpos+namewidth;
ud.resbw=uicontrol('Parent',fig, ...
  'Position',[xpos ypos boxwidth eheight],...
	'String','70', 'HorizontalAlignment','center', ...
	'Style','edit');
xpos=xpos+boxwidth;
uicontrol('Parent',fig, ...
  'Position',[xpos ypos unitswidth pheight],...
  'String',' Hz', 'HorizontalAlignment','left', 'Style','text');
  % LEVEL
% xpos=xpos+unitswidth+colsep;
% uicontrol('Parent',fig, ...
%   'Position',[xpos ypos namewidth pheight],...
%   'String','level:  ', ...
%   'HorizontalAlignment','right', 'Style','text');
xpos=xpos+namewidth;
ud.resonancelevel=uicontrol('Parent',fig, ...
  'Position',[xpos ypos boxwidth eheight],...
	'String','70', 'HorizontalAlignment','center', ...
	'Style','edit');
xpos=xpos+boxwidth;
uicontrol('Parent',fig, ...
  'Position',[xpos ypos unitswidth pheight],...
  'String',' dB', 'HorizontalAlignment','left', 'Style','text');

%---- common params
ypos=0.25;
xpos=0.04;
uicontrol('Parent',fig, ...
    'Position',[xpos ypos namewidth+0.05 pheight],...
    'String','global settings', ...
    'HorizontalAlignment','left', 'Style','text','BackgroundColor','g');

    ypos=0.18;

  % SAMPLING FREQ 

xpos=xpos+pwidth;
uicontrol('Parent',fig, ...
    'Position',[xpos-0.1 ypos namewidth+0.1 pheight],...
    'String','sampling rate: ', ...
    'HorizontalAlignment','right', 'Style','text');
xpos=xpos+namewidth;
ud.fs=uicontrol('Parent',fig, ...
  'Position',[xpos ypos boxwidth pheight+0.01],...
  'String','8012|8192|10000|16000|20000|44100', ...
  'Style','popupmenu', ...
  'Tag','freqsepPopup', ...
  'HorizontalAlignment','center',...
  'Value',1);
xpos=xpos+boxwidth;
uicontrol('Parent',fig, ...
  'Position',[xpos ypos unitswidth pheight],...
  'String',' Hz', 'HorizontalAlignment','left', 'Style','text');
    

  % DURATION

xpos=0.04;
ypos=ypos-yinc;    
xpos=xpos+pwidth;
uicontrol('Parent',fig, ...
    'Position',[xpos-0.1 ypos namewidth+0.1 pheight],...
    'String','duration: ', ...
    'HorizontalAlignment','right', 'Style','text');
xpos=xpos+namewidth;
ud.dur=uicontrol('Parent',fig, ...
  'Position',[xpos ypos boxwidth eheight],...
	'String','100', 'HorizontalAlignment','center', ...
	'Style','edit');
xpos=xpos+boxwidth;
uicontrol('Parent',fig, ...
  'Position',[xpos ypos unitswidth pheight],...
  'String',' ms', 'HorizontalAlignment','left', 'Style','text');

   % RAMP

xpos=0.04;
ypos=ypos-yinc;    
xpos=xpos+pwidth;
uicontrol('Parent',fig, ...
    'Position',[xpos-0.1 ypos namewidth+0.1 pheight],...
    'String','ramp: ', ...
    'HorizontalAlignment','right', 'Style','text');
xpos=xpos+namewidth;
ud.rampms=uicontrol('Parent',fig, ...
  'Position',[xpos ypos boxwidth eheight],...
	'String','0', 'HorizontalAlignment','center', ...
	'Style','edit');
xpos=xpos+boxwidth;
uicontrol('Parent',fig, ...
  'Position',[xpos ypos unitswidth pheight],...
  'String',' ms', 'HorizontalAlignment','left', 'Style','text');


set(gcf,'UserData',ud);

	
