image thumbnail

Waveform Generator GUI 2

by

 

22 Feb 2012 (Updated )

Generate waveformed signal and play it. Interactive GUI with movable datapoints.

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

% Last Modified by GUIDE v2.5 27-Feb-2012 12:11:17

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

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

% Update handles structure
guidata(hObject, handles);

% initial states:
iscont=false; % not pereodic, boundary value used
mousemode=1; % move
f=440; % frequency
Fs=44100; % sampling frequency
n=10; % number of markers
nh=10; % number of harmonics
sl=0.8; % signal length
issincos=false; % if issincos=true then starts with sin/cos harmonics dispaly, amplitude dispaly otherwise

bufferSize=0.2; % sec, bufer size used in continus play
nblocks=6; % number of blocks in buffer
margin=nblocks-1; % margin that will be filled in start device

updateharm=true;

%ic=interactive_curve(handles.figure1,handles.axes1);
T=1/f; % period
XLim=[0 T];
YLim=[-1 1];
st=T/n; 
markersX=st/2:st:T-st/2;
markersY=zeros(size(markersX));
ic=interactive_curve(handles.figure1,handles.axes1,markersX,markersY,XLim,YLim);
handles.ic=ic;
handles.ic.xMargin=st/4;
handles.ic.yMargin=0.1;
handles.ic.gap=st/8;

% harmonics update function

T=1/f;
dx=1/Fs;
x=0:dx:T-dx;
y=zeros(size(x));
% precalulate cos and sin:
cs=zeros(nh,length(x));
sn=zeros(nh,length(x));
for nhc=1:nh
    cs(nhc,:)=cos(nhc*(2*pi/T)*x);
    sn(nhc,:)=sin(nhc*(2*pi/T)*x);
end
[a b]=calulate_harmonics(nh,T,x,y,cs,sn);
% a=randn(1,nh+1);
% b=randn(1,nh+1);
hb=bar((0:nh)',[a' b'],'grouped','parent',handles.axes2);
%set(hb(1),'color','r');
%set(hb(1),'visible','off');
set(handles.axes2,'NextPlot','add');
hb2=bar((0:nh)',sqrt(a.^2+b.^2)','g','parent',handles.axes2,'BarWidth',0.4);
axis(handles.axes2,'manual');
if issincos
    set(hb,'visible','on');
    set(hb2,'visible','off');
    set(handles.axes2,'YLim',[-1 1]);
    set(handles.sc,'value',true);
    set(handles.amp,'value',false);
else
    set(hb,'visible','off');
    set(hb2,'visible','on');
    set(handles.axes2,'YLim',[0 1]);
    set(handles.sc,'value',false);
    set(handles.amp,'value',true);
end
set(handles.axes2,'XLim',[-1 nh+1]);
tc=0:nh;
set(handles.axes2,'XTick',tc);
set(handles.axes2,'XTickLabel',num2str(tc'));
colormap(handles.axes2,hsv(3));
ic.motionFunctionHandle=@update_harmonics;
inp=cell(1,8); % input for motionFunction
inp{1}=ic;
inp{2}=handles.axes2;
inp{3}=hb;
inp{4}=cs;
inp{5}=sn;
inp{6}=nh;
inp{7}=Fs;
inp{8}=hb2;
ic.motionFunctionArgument=inp;

if updateharm
    set(handles.uh,'value',true);
else
    set(handles.uh,'value',false);
    ic.motionFunctionHandle=[];
end



if iscont
    handles.ic.setBoundary(2);
    set(handles.cont,'value',true);
else
    handles.ic.setBoundary(1);
    set(handles.cont,'value',false);
end

set(handles.mode,'value',mousemode);
set(handles.f,'string',num2str(f));
set(handles.harm,'string',num2str(nh));
set(handles.harm,'string',num2str(nh));
set(handles.sl,'string',num2str(sl));


handles.Fs=Fs;
handles.hb=hb;
handles.hb2=hb2;
handles.nh=nh;

handles.bufferSize=bufferSize;
handles.nblocks=nblocks;
handles.margin=margin;

handles.ic.additionalDeleteFunctionHandle=@ (x) delete(daqfind);

% Update handles structure
guidata(hObject, handles);






% --- Outputs from this function are returned to the command line.
function varargout = waveform_generator_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 on selection change in presets.
function presets_Callback(hObject, eventdata, handles)
% hObject    handle to presets (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = cellstr(get(hObject,'String')) returns presets contents as cell array
%        contents{get(hObject,'Value')} returns selected item from presets

switch get(hObject,'Value')
    case 2 % zero
        handles.ic.boundaryYLeft=0;
        set(handles.slider1,'Value',handles.ic.boundaryYLeft);
        handles.ic.boundaryYRight=0;
        set(handles.slider2,'Value',handles.ic.boundaryYRight);
        
        handles.ic.setMarkersPositions(handles.ic.x,handles.ic.y*0);
    case 3 % sine
        XLim=get(handles.ic.axesHandle,'XLim');
        T=XLim(2)-XLim(1);
        n=10;
        dx=T/n;
        markersX=XLim(1)+dx/2:dx:XLim(2)-dx/2;
        markersY=0.9*sin(2*pi*markersX/T);
        handles.ic.setMarkersPositions(markersX,markersY);
        
        handles.ic.setMethod('spline');
        set(handles.method,'value',3);
        
        handles.ic.setBoundary(2); 
        set(handles.cont,'value',true);
        
    case 4 % cosine
        XLim=get(handles.ic.axesHandle,'XLim');
        T=XLim(2)-XLim(1);
        n=10;
        dx=T/n;
        markersX=XLim(1)+dx/2:dx:XLim(2)-dx/2;
        markersY=0.9*cos(2*pi*markersX/T);
        handles.ic.setMarkersPositions(markersX,markersY);
        
        handles.ic.setMethod('spline');
        set(handles.method,'value',3);
        
        handles.ic.setBoundary(2); 
        set(handles.cont,'value',true);
        
    case 5 % square
        XLim=get(handles.ic.axesHandle,'XLim');
        T=XLim(2)-XLim(1);
        
        markersX=[0.25  0.75]*T;
        markersY=[1 -1]*0.7;
        
        handles.ic.setMarkersPositions(markersX,markersY);
        
        handles.ic.setMethod('nearest');
        set(handles.method,'value',1);
        
        handles.ic.setBoundary(2); 
        set(handles.cont,'value',true);
        
    case 6 % triangle
        XLim=get(handles.ic.axesHandle,'XLim');
        T=XLim(2)-XLim(1);
        
        markersX=[0.25  0.75]*T;
        markersY=[1 -1]*0.9;
        
        handles.ic.setMarkersPositions(markersX,markersY);
        
        handles.ic.setMethod('linear');
        set(handles.method,'value',2);
        
        handles.ic.setBoundary(2); 
        set(handles.cont,'value',true);
        
     case 7 % Sawtooth
         
        handles.ic.setBoundary(1); 
        set(handles.cont,'value',false);
        
        handles.ic.boundaryYLeft=-0.9;
        set(handles.slider1,'Value',handles.ic.boundaryYLeft);
        handles.ic.boundaryYRight=0.9;
        set(handles.slider2,'Value',handles.ic.boundaryYRight);
         
        markersX=[];
        markersY=[];
        
        handles.ic.setMarkersPositions(markersX,markersY);
        
     case 8 % back Sawtooth
         
        handles.ic.setBoundary(1); 
        set(handles.cont,'value',false);
        
        handles.ic.boundaryYLeft=0.9;
        set(handles.slider1,'Value',handles.ic.boundaryYLeft);
        handles.ic.boundaryYRight=-0.9;
        set(handles.slider2,'Value',handles.ic.boundaryYRight);
         
        markersX=[];
        markersY=[];
        
        handles.ic.setMarkersPositions(markersX,markersY);
        
     case 9 % 25% pulse
        pr=0.25; 
         
        XLim=get(handles.ic.axesHandle,'XLim');
        T=XLim(2)-XLim(1);
        
        markersX=[0.5-pr  0.5 0.5+pr]*T;
        markersY=([0 1 0]-pr)*1;
        
        handles.ic.setMarkersPositions(markersX,markersY);
        
        handles.ic.setMethod('nearest');
        set(handles.method,'value',1);
        
        handles.ic.setBoundary(2); 
        set(handles.cont,'value',true);
     case 10 % 12.5% pulse
        pr=0.125; 
         
        XLim=get(handles.ic.axesHandle,'XLim');
        T=XLim(2)-XLim(1);
        
        markersX=[0.5-pr  0.5 0.5+pr]*T;
        markersY=([0 1 0]-pr)*1;
        
        handles.ic.setMarkersPositions(markersX,markersY);
        
        handles.ic.setMethod('nearest');
        set(handles.method,'value',1);
        
        handles.ic.setBoundary(2); 
        set(handles.cont,'value',true);
        
     case 11 % 6.25% pulse
        pr=0.0625; 
         
        XLim=get(handles.ic.axesHandle,'XLim');
        T=XLim(2)-XLim(1);
        
        markersX=[0.5-pr  0.5 0.5+pr]*T;
        markersY=([0 1 0]-pr)*1;
        
        handles.ic.setMarkersPositions(markersX,markersY);
        
        handles.ic.setMethod('nearest');
        set(handles.method,'value',1);
        
        handles.ic.setBoundary(2); 
        set(handles.cont,'value',true);
         
     case 12 % abs(sin)
        XLim=get(handles.ic.axesHandle,'XLim');
        T=XLim(2)-XLim(1);
        n=19;
        dx=T/n;
        markersX=XLim(1)+dx/2:dx:XLim(2)-dx/2;
        markersY=0.7*abs(sin(2*pi*markersX/T));
        handles.ic.setMarkersPositions(markersX,markersY);
        
        handles.ic.setMethod('linear');
        set(handles.method,'value',2);
        
        handles.ic.setBoundary(1); 
        set(handles.cont,'value',false);
        
        handles.ic.boundaryYLeft=0;
        set(handles.slider1,'Value',handles.ic.boundaryYLeft);
        handles.ic.boundaryYRight=0;
        set(handles.slider2,'Value',handles.ic.boundaryYRight);
         
        
end
handles.ic.redraw();



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

% Hint: popupmenu 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 on selection change in method.
function method_Callback(hObject, eventdata, handles)
% hObject    handle to method (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = cellstr(get(hObject,'String')) returns method contents as cell array
%        contents{get(hObject,'Value')} returns selected item from method

v=get(hObject,'Value');
contents = cellstr(get(hObject,'String'));
method = contents{v};
handles.ic.setMethod(method);


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

% Hint: popupmenu 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 f_Callback(hObject, eventdata, handles)
XLim=get(handles.ic.axesHandle,'XLim');
T_old=XLim(2)-XLim(1);
f=str2double(get(hObject,'String'));
T=1/f;
handles.ic.setXLim([0 T]);


Fs=handles.Fs;
nh=handles.nh;

dx=1/Fs;
x=0:dx:T-dx;
% precalulate cos and sin:
cs=zeros(nh,length(x));
sn=zeros(nh,length(x));
for nhc=1:nh
    cs(nhc,:)=cos(nhc*(2*pi/T)*x);
    sn(nhc,:)=sin(nhc*(2*pi/T)*x);
end

% ic.motionFunctionHandle=@update_harmonics;
% inp=cell(1,7); % input for motionFunction
% inp{1}=ic;
% inp{2}=handles.axes2;
% inp{3}=hb;
% inp{4}=cs;
% inp{5}=sn;
% inp{6}=nh;
% inp{7}=Fs;
inp=handles.ic.motionFunctionArgument;
inp{4}=cs;
inp{5}=sn;
handles.ic.motionFunctionArgument=inp;




handles.ic.setMarkersPositions(handles.ic.x*T/T_old,handles.ic.y);

handles.ic.xMargin=(max(handles.ic.x)-min(handles.ic.x))/70;
handles.ic.yMargin=0.05;
handles.ic.gap=(max(handles.ic.x)-min(handles.ic.x))/70;
XLim=get(handles.ic.axesHandle,'XLim');
handles.ic.xLine=linspace(XLim(1),XLim(2),100);
handles.ic.redraw();


% --- Executes during object creation, after setting all properties.
function f_CreateFcn(hObject, eventdata, handles)
% hObject    handle to f (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 on button press in cont.
function cont_Callback(hObject, eventdata, handles)
% hObject    handle to cont (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of cont
if get(hObject,'Value')
    handles.ic.setBoundary(2);
else
    handles.ic.setBoundary(1);
end


% --- Executes on button press in mfile.
function mfile_Callback(hObject, eventdata, handles)
[file,path] = uiputfile('*.m','generate m-file');
fln=[path file];
handles.ic.generateMFile(fln,true);
edit(fln);


% --- Executes on button press in cont_play.
function cont_play_Callback(hObject, eventdata, handles)
if get(hObject,'Value')
    open_device(handles.bufferSize,handles.Fs,handles.ic,handles.nblocks,handles.margin);
else
    delete(daqfind); % delete all previus sound playing.
end


function sl_Callback(hObject, eventdata, handles)
% hObject    handle to sl (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 sl as text
%        str2double(get(hObject,'String')) returns contents of sl as a double


% --- Executes during object creation, after setting all properties.
function sl_CreateFcn(hObject, eventdata, handles)
% hObject    handle to sl (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 on button press in play.
function play_Callback(hObject, eventdata, handles)
Fs=handles.Fs;
tm=str2double(get(handles.sl,'String'));
x=0:1/Fs:tm;
y=handles.ic.interpData(x,true);
sound(y',Fs);
% figure;
% plot(x,y,'r.-');



% --- Executes on button press in wav.
function wav_Callback(hObject, eventdata, handles)
Fs=handles.Fs;
tm=str2double(get(handles.sl,'String'));
x=0:1/Fs:tm;
y=handles.ic.interpData(x,true);
[file,path] = uiputfile('*.wav','Save to wav file');
fln=[path file];
wavwrite(y',Fs,fln);



function harm_Callback(hObject, eventdata, handles)

nh=str2double(get(hObject,'String'));

Fs=handles.Fs;
XLim=get(handles.ic.axesHandle,'XLim');
T=XLim(2)-XLim(1);
% harmonics update function

dx=1/Fs;
x=0:dx:T-dx;
y=zeros(size(x));
% precalulate cos and sin:
cs=zeros(nh,length(x));
sn=zeros(nh,length(x));
for nhc=1:nh
    cs(nhc,:)=cos(nhc*(2*pi/T)*x);
    sn(nhc,:)=sin(nhc*(2*pi/T)*x);
end
[a b]=calulate_harmonics(nh,T,x,y,cs,sn);
% a=randn(1,nh+1);
% b=randn(1,nh+1);
delete(handles.hb(1));
delete(handles.hb(2));
hb=bar((0:nh)',[a' b'],'grouped','parent',handles.axes2);
colormap(handles.axes2,hsv(3));
delete(handles.hb2);
hb2=bar((0:nh)',sqrt(a.^2+b.^2)','g','parent',handles.axes2,'BarWidth',0.4);

if get(handles.sc,'value')
    set(hb,'visible','on');
    set(hb2,'visible','off');

    if  get(handles.x2,'Value')
        set(handles.axes2,'YLim',[-0.5 0.5]);
    else
        set(handles.axes2,'YLim',[-1 1]);
    end
else
    set(hb,'visible','off');
    set(hb2,'visible','on');
    if  get(handles.x2,'Value')
        set(handles.axes2,'YLim',[0 0.5]);
    else
        set(handles.axes2,'YLim',[0 1]);
    end

end
set(handles.axes2,'XLim',[-1 nh+1]);
tc=0:nh;
set(handles.axes2,'XTick',tc);
set(handles.axes2,'XTickLabel',num2str(tc'));

inp=handles.ic.motionFunctionArgument;
inp{3}=hb;
inp{4}=cs;
inp{5}=sn;
inp{6}=nh;
inp{8}=hb2;
handles.ic.motionFunctionArgument=inp;

handles.nh=nh;
handles.hb=hb;
handles.hb2=hb2;

% Update handles structure
guidata(hObject, handles);

handles.ic.redraw();



% --- Executes during object creation, after setting all properties.
function harm_CreateFcn(hObject, eventdata, handles)
% hObject    handle to harm (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 on button press in plot_harm.
function plot_harm_Callback(hObject, eventdata, handles)
inp=handles.ic.motionFunctionArgument;
cs=inp{4};
sn=inp{5};
nh=inp{6};
Fs=inp{7};
XLim=get(handles.ic.axesHandle,'XLim');
T=XLim(2)-XLim(1);
dx=1/Fs;
x=0:dx:T-dx;
y=handles.ic.interpData(x,true);
[a b]=calulate_harmonics(nh,T,x,y,cs,sn);
x3=[x x+T x+2*T];
y3=[y y y];
s=a(1)/2*ones(size(x));
for nhc=1:nh
    %a(nhc+1)=(2/T)*trapz(x,y.*cos(nhc*(2*pi/T)*x));
    %b(nhc)=(2/T)*trapz(x,y.*sin(nhc*(2*pi/T)*x));
    s=s+a(nhc+1).*cs(nhc,:);
    s=s+b(nhc+1).*sn(nhc,:);
end
s3=[s s s];
figure;
plot(x3,y3,'k-',x3,s3,'r-');
legend('original','fourier series');


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

v=get(hObject,'Value');
handles.ic.boundaryYLeft=v;
handles.ic.redraw();


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

% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor',[.9 .9 .9]);
end


% --- Executes on slider movement.
function slider2_Callback(hObject, eventdata, handles)
v=get(hObject,'Value');
handles.ic.boundaryYRight=v;
handles.ic.redraw();


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

% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor',[.9 .9 .9]);
end


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

% Hints: contents = cellstr(get(hObject,'String')) returns mode contents as cell array
%        contents{get(hObject,'Value')} returns selected item from mode

v=get(hObject,'Value');
handles.ic.mouseMode=v;


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

% Hint: popupmenu 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 on button press in x2.
function x2_Callback(hObject, eventdata, handles)
% hObject    handle to x2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of x2
% if  get(hObject,'Value')
%     set(handles.axes2,'YLim',[-0.5 0.5]);
% else
%     set(handles.axes2,'YLim',[-1 1]);
% end

if get(handles.sc,'value')
    % sin/cos
    if  get(handles.x2,'Value')
        set(handles.axes2,'YLim',[-0.5 0.5]);
    else
        set(handles.axes2,'YLim',[-1 1]);
    end
else
    % amplitude
    if  get(handles.x2,'Value')
        set(handles.axes2,'YLim',[0 0.5]);
    else
        set(handles.axes2,'YLim',[0 1]);
    end
    
end
    


% --- Executes when selected object is changed in uipanel1.
function uipanel1_SelectionChangeFcn(hObject, eventdata, handles)
% hObject    handle to the selected object in uipanel1 
% eventdata  structure with the following fields (see UIBUTTONGROUP)
%	EventName: string 'SelectionChanged' (read only)
%	OldValue: handle of the previously selected object or empty if none was selected
%	NewValue: handle of the currently selected object
% handles    structure with handles and user data (see GUIDATA)

if get(handles.sc,'value')
    % sin/cos
    set(handles.hb,'visible','on');
    set(handles.hb2,'visible','off');
    if  get(handles.x2,'Value')
        set(handles.axes2,'YLim',[-0.5 0.5]);
    else
        set(handles.axes2,'YLim',[-1 1]);
    end
else
    % amplitude
    set(handles.hb,'visible','off');
    set(handles.hb2,'visible','on');
    if  get(handles.x2,'Value')
        set(handles.axes2,'YLim',[0 0.5]);
    else
        set(handles.axes2,'YLim',[0 1]);
    end
    
end
    
    


% --- Executes on button press in uh.
function uh_Callback(hObject, eventdata, handles)
if get(hObject,'Value')
    handles.ic.motionFunctionHandle=@update_harmonics;
    if get(handles.sc,'value')
        % sin/cos
        set(handles.hb,'visible','on');
        set(handles.hb2,'visible','off');
        if  get(handles.x2,'Value')
            set(handles.axes2,'YLim',[-0.5 0.5]);
        else
            set(handles.axes2,'YLim',[-1 1]);
        end
    else
        % amplitude
        set(handles.hb,'visible','off');
        set(handles.hb2,'visible','on');
        if  get(handles.x2,'Value')
            set(handles.axes2,'YLim',[0 0.5]);
        else
            set(handles.axes2,'YLim',[0 1]);
        end

    end
    update_harmonics(handles.ic.motionFunctionArgument);
else
    handles.ic.motionFunctionHandle=[];
    set(handles.hb,'visible','off');
    set(handles.hb2,'visible','off');
end

Contact us