www.gusucode.com > 声音的处理有:LPC,FFT,共振峰,频谱源码程序 > siganlandsystemusingMatlab/SSUM/sine/sinexpo.m

    function varargout = sinexpo(varargin)
% SINEXPO.m-file for sinexpo.fig
%      SINEXPO, by itself, creates a new SINEXPO or raises the existing
%      singleton*.
%
%      H = SINEXPO returns the handle to a new SINEXPO or the handle to
%      the existing singleton*.
%
%      SINEXPO('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in SINEXPO.M with the given input arguments.
%
%      SINEXPO('Property','Value',...) creates a new SINEXPO or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before sinexpo_OpeningFunction gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to sinexpo_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
% Last Modified by GUIDE v2.5 16-Mar-2004 14:30:31

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @sinexpo_OpeningFcn, ...
                   'gui_OutputFcn',  @sinexpo_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin & isstr(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 sinesumgui2 is made visible.
function sinexpo_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
guidata(hObject, handles);
set(gcf,'UserData',handles);
sinexpofn;
%if strcmp(get(hObject,'Visible'),'off')
%	update_Callback(hObject, eventdata, handles)
%end

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

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

function popupmenu1_CreateFcn(hObject, eventdata, handles)
	if ispc
		set(hObject,'BackgroundColor','white');
	else
		set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
	end

	set(hObject, 'String', {'Sum', 'Product'});

function popupmenu1_Callback(hObject, eventdata, handles)
	sinexpofn 'update';

function freq1_CreateFcn(hObject, eventdata, handles)
	if ispc
   	 set(hObject,'BackgroundColor','white');
	else
  	  set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
	end

function freq2_CreateFcn(hObject, eventdata, handles)
	if ispc
  	  set(hObject,'BackgroundColor','white');
	else
 	   set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
	end

function amp1_CreateFcn(hObject, eventdata, handles)
	if ispc
		set(hObject,'BackgroundColor','white');
	else
	  set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
	end

function amp2_CreateFcn(hObject, eventdata, handles)
	if ispc
		set(hObject,'BackgroundColor','white');
	else
		set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
	end

function phase1_CreateFcn(hObject, eventdata, handles)
if ispc
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end

function phase2_CreateFcn(hObject, eventdata, handles)
if ispc
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end

% Executes on textbox entry
function freq1_Callback(hObject, eventdata, handles)
	freq1 = str2double(get(hObject,'String'));
	if freq1 < 20.1
        freq1 = 20.1;
    elseif freq1 > 22042
        freq1 = 22042;
    end
    set(handles.freq1,'String',num2str(freq1));
	set(handles.freq1slider,'Value',log2(freq1));
	sinexpofn 'update';

function freq2_Callback(hObject, eventdata, handles)
	freq2 = str2double(get(hObject,'String'));
	if freq2 < 20.1
        freq2 = 20.1;
    elseif freq2 > 22042
        freq2 = 22042;
    end
    set(handles.freq2,'String',num2str(freq2));
	set(handles.freq2slider,'Value',log2(freq2));
	sinexpofn 'update';

function amp1_Callback(hObject, eventdata, handles)
	amp1 = str2double(get(hObject,'String'));
	if amp1 < 0
        amp1 = 0;
    elseif amp1 > 2
        amp1 = 2;
    end
    set(handles.amp1,'String',num2str(amp1));
	set(handles.amp1slider,'Value',amp1);
	sinexpofn 'update';

function amp2_Callback(hObject, eventdata, handles)
	amp2 = str2double(get(hObject,'String'));
	if amp2 < 0
        amp2 = 0;
    elseif amp2 > 2
        amp2 = 2;
    end
    set(handles.amp2,'String',num2str(amp2));
	set(handles.amp2slider,'Value',amp2);
	sinexpofn 'update';

function phase1_Callback(hObject, eventdata, handles)
	phase1 = str2double(get(hObject,'String'));
	if phase1 < -180
        while phase1 < -180
            phase1 = phase1 + 360;
        end
    elseif phase1 > 180
        while phase1 > 180
            phase1 = phase1 - 360;
        end
    end
    set(handles.phase1,'String',num2str(phase1));
	set(handles.phase1slider,'Value',phase1);
	sinexpofn 'update';

function phase2_Callback(hObject, eventdata, handles)
	phase2 = str2double(get(hObject,'String'));
	if phase2 < -180
        while phase2 < -180
            phase2 = phase2 + 360;
        end
    elseif phase2 > 180
        while phase2 > 180
            phase2 = phase2 - 360;
        end
    end
    set(handles.phase2,'String',num2str(phase2));
	set(handles.phase2slider,'Value',phase2);
	sinexpofn 'update';


% --- Executes during object creation, after setting all properties.
function freq1slider_CreateFcn(hObject, eventdata, handles)
usewhitebg = 1;
if usewhitebg
    set(hObject,'BackgroundColor',[.9 .9 .9]);
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end


% --- Executes on slider movement.
function freq1slider_Callback(hObject, eventdata, handles)
	freq1 = num2str(2^get(hObject,'Value'));
	set(handles.freq1,'String',freq1);
	sinexpofn 'update';


% --- Executes during object creation, after setting all properties.
function amp1slider_CreateFcn(hObject, eventdata, handles)
usewhitebg = 1;
if usewhitebg
    set(hObject,'BackgroundColor',[.9 .9 .9]);
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end


% --- Executes on slider movement.
function amp1slider_Callback(hObject, eventdata, handles)
	amp1 = num2str(get(hObject,'Value'));
	set(handles.amp1,'String',amp1);
	sinexpofn 'update';


% --- Executes during object creation, after setting all properties.
function phase1slider_CreateFcn(hObject, eventdata, handles)
usewhitebg = 1;
if usewhitebg
    set(hObject,'BackgroundColor',[.9 .9 .9]);
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end


% --- Executes on slider movement.
function phase1slider_Callback(hObject, eventdata, handles)
	phase1 = num2str(get(hObject,'Value'));
	set(handles.phase1,'String',phase1);
	sinexpofn 'update';


% --- Executes during object creation, after setting all properties.
function freq2slider_CreateFcn(hObject, eventdata, handles)
usewhitebg = 1;
if usewhitebg
    set(hObject,'BackgroundColor',[.9 .9 .9]);
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end


% --- Executes on slider movement.
function freq2slider_Callback(hObject, eventdata, handles)
	freq2 = num2str(2^get(hObject,'Value'));
	set(handles.freq2,'String',freq2);
	sinexpofn 'update';


% --- Executes during object creation, after setting all properties.
function amp2slider_CreateFcn(hObject, eventdata, handles)
usewhitebg = 1;
if usewhitebg
    set(hObject,'BackgroundColor',[.9 .9 .9]);
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end


% --- Executes on slider movement.
function amp2slider_Callback(hObject, eventdata, handles)
	amp2 = num2str(get(hObject,'Value'));
	set(handles.amp2,'String',amp2);
	sinexpofn 'update';


% --- Executes during object creation, after setting all properties.
function phase2slider_CreateFcn(hObject, eventdata, handles)
usewhitebg = 1;
if usewhitebg
    set(hObject,'BackgroundColor',[.9 .9 .9]);
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end


% --- Executes on slider movement.
function phase2slider_Callback(hObject, eventdata, handles)
	phase2 = num2str(get(hObject,'Value'));
	set(handles.phase2,'String',phase2);
	sinexpofn 'update';


% --- Executes during object creation, after setting all properties.
function offset_CreateFcn(hObject, eventdata, handles)
if ispc
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end


function offset_Callback(hObject, eventdata, handles)
	offset = str2double(get(hObject,'String'));
	if offset < 0
        offset = 0;
    elseif offset > 1
        offset = 1;
    end
    set(handles.offset,'String',num2str(offset));
	set(handles.offsetslider,'Value',offset);
	sinexpofn 'update';


% --- Executes during object creation, after setting all properties.
function offsetslider_CreateFcn(hObject, eventdata, handles)
usewhitebg = 1;
if usewhitebg
    set(hObject,'BackgroundColor',[.9 .9 .9]);
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end


% --- Executes on slider movement.
function offsetslider_Callback(hObject, eventdata, handles)
	offset = num2str(get(hObject,'Value'));
	set(handles.offset,'String',offset);
	sinexpofn 'update';


%% --- Executes on button press in updatebutton.
%function updatebutton_Callback(hObject, eventdata, handles)
%	update_Callback(hObject, eventdata, handles)


% --- Executes on button press in play.
function play_Callback(hObject, eventdata, handles)
	sinexpofn 'play';

% --- Executes during object creation, after setting all properties.
function plotype_CreateFcn(hObject, eventdata, handles)
if ispc
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end


% --- Executes on selection change in plotype.
function plotype_Callback(hObject, eventdata, handles)
	sinexpofn 'update';


% --- Executes during object creation, after setting all properties.
function Fstext_CreateFcn(hObject, eventdata, handles)
if ispc
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end

function Fstext_Callback(hObject, eventdata, handles)
	Fs = str2double(get(hObject,'String'));
    if (Fs > 44100)
		Fs = 44100;
	end
	if (Fs < 21)
		Fs = 21;
	end
	set(handles.Fsslider,'Value',log2(Fs));
    set(handles.Fstext,'String',num2str(Fs));
	sinexpofn 'update';


% --- Executes during object creation, after setting all properties.
function Fsslider_CreateFcn(hObject, eventdata, handles)
usewhitebg = 1;
if usewhitebg
    set(hObject,'BackgroundColor',[.9 .9 .9]);
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end


% --- Executes on slider movement.
function Fsslider_Callback(hObject, eventdata, handles)
	Fs = ceil(2^get(hObject,'Value'));
    if (Fs > 44100)
		Fs = 44100;
	end
	if (Fs < 0)
		Fs = 0;
	end
    set(handles.Fsslider,'Value',log2(Fs));
	set(handles.Fstext,'String',num2str(Fs));
	sinexpofn 'update';


% --- Executes during object creation, after setting all properties.
function durationtext_CreateFcn(hObject, eventdata, handles)
if ispc
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end

function durationtext_Callback(hObject, eventdata, handles)
	duration = str2double(get(hObject,'String'));
	if duration <= 0
		duration = 0.01;
		set(handles.durationtext,'String',num2str(duration));
	end
	set(handles.durationslider,'Value',duration);
	sinexpofn 'update';

% --- Executes during object creation, after setting all properties.
function durationslider_CreateFcn(hObject, eventdata, handles)
usewhitebg = 1;
if usewhitebg
    set(hObject,'BackgroundColor',[.9 .9 .9]);
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end

% --- Executes on slider movement.
function durationslider_Callback(hObject, eventdata, handles)
	duration = num2str(get(hObject,'Value'));
	set(handles.durationtext,'String',duration);
	sinexpofn 'update';

% --- Executes on button press in gridbox.
function gridbox_Callback(hObject, eventdata, handles)
	sinexpofn 'update';

% --- Executes on button press in plot1box.
function plot1box_Callback(hObject, eventdata, handles)
	sinexpofn 'update';

% --- Executes on button press in plot2box.
function plot2box_Callback(hObject, eventdata, handles)
	sinexpofn 'update';

% --- Executes on button press in spectrumbutton.
function spectrumbutton_Callback(hObject, eventdata, handles)
	sinexpofn 'spectrum';

% --- Executes on button press in interpbox.
function interpbox_Callback(hObject, eventdata, handles)
	sinexpofn 'update';

% --- Executes on button press in samplebox.
function samplebox_Callback(hObject, eventdata, handles)
	sinexpofn 'update';


% --- Executes when user attempts to close sinexpo_fig.
function sinexpo_fig_CloseRequestFcn(hObject, eventdata, handles)
% hObject    handle to sinexpo_fig (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: delete(hObject) closes the figure
delete(hObject);


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


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

% --------------------------------------------------------------------
function sonogram_Callback(hObject, eventdata, handles)
% hObject    handle to Untitled_3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
    sinexpofn 'sonogram';

% --------------------------------------------------------------------
function alias_Callback(hObject, eventdata, handles)
% hObject    handle to Untitled_2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
    sinexpofn 'alias';


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