gusucode.com > matlab编程基于声学特性的鸡蛋蛋壳裂纹检测GUI界面设计系统源码程序 > code4/matlab编程基于声学特性的鸡蛋蛋壳裂纹检测GUI界面设计系统源码程序/code/siganyb.m
function varargout = sigany(varargin) % SIGANY M-file for sigany.fig % SIGANY, by itself, creates a new SIGANY or raises the existing % singleton*. % % H = SIGANY returns the handle to a new SIGANY or the handle to % the existing singleton*. % % SIGANY('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in SIGANY.M with the given input arguments. % % SIGANY('Property','Value',...) creates a new SIGANY or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before sigany_OpeningFunction gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to sigany_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 % Copyright 2002-2003 The MathWorks, Inc. % Edit the above text to modify the response to help sigany % Last Modified by GUIDE v2.5 12-May-2008 18:33:04 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @sigany_OpeningFcn, ... 'gui_OutputFcn', @sigany_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 sigany is made visible. function sigany_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 sigany (see VARARGIN) hstartshow=figure; imshow('start.jpg'); pause(3); % Choose default command line output for sigany handles.output = hObject; handles.time=str2double(get(handles.time,'String')); % ù± handles.sample=str2double(get(handles.sample,'String')); % ù handles.filename=get(handles.name,'String'); % ± axes(handles.axes1); % set(gcf,'doublebuffer','on') %Reduce plot flicker P = plot(zeros(1000,1)); % ú xlabel('Samples'), axis([0 1000 -1 1]), grid on title('采样数据实时波形'); handles.P=P; % ±±ú handles.data=[]; % ó AI = analoginput('winsound'); % ù¨è± addchannel(AI,1); % íù handles.AI=AI; % ±ù¨è± % Update handles structure guidata(hObject, handles); % UIWAIT makes sigany wait for user response (see UIRESUME) % uiwait(handles.figure1); close(hstartshow); % --- Outputs from this function are returned to the command line. function varargout = sigany_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 button press in start. function start_Callback(hObject, eventdata, handles) % hObject handle to start (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % AI = analoginput('winsound'); % addchannel(AI,1); AI=handles.AI; duration = handles.time; % èù± AI.SampleRate=handles.sample; % èù ActualRate = get(AI,'SampleRate'); % ù set(AI,'SamplesPerTrigger',duration*ActualRate) % è·ù handles.AI=AI; % ±ù¨è±è guidata(hObject, handles); P=handles.P; % ±ú start(AI) % i = 1; while AI.SamplesAcquired < AI.SamplesPerTrigger % 1000ùü if strcmp(AI.Running, 'On') % ÷stopò· while AI.SamplesAcquired < 1000*i end data = peekdata(AI,1000); set(P,'ydata',data); drawnow i = i + 1; else break; end end [handles.data handles.t] = getdata(AI,AI.SamplesAcquired); %±ùà± % handles.AI=AI; % length(handles.data) guidata(hObject, handles); stop(AI); % ù function time_Callback(hObject, eventdata, handles) % hObject handle to time (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 time as text % str2double(get(hObject,'String')) returns contents of time as a double handles.time=str2double(get(hObject,'String')); % ù± guidata(hObject, handles); % --- Executes during object creation, after setting all properties. function time_CreateFcn(hObject, eventdata, handles) % hObject handle to time (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 set(hObject,'BackgroundColor','white'); else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor')); end function sample_Callback(hObject, eventdata, handles) % hObject handle to sample (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 sample as text % str2double(get(hObject,'String')) returns contents of sample as a double handles.sample=str2double(get(hObject,'String')); % ù guidata(hObject, handles); % --- Executes during object creation, after setting all properties. function sample_CreateFcn(hObject, eventdata, handles) % hObject handle to sample (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 set(hObject,'BackgroundColor','white'); else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor')); end % --- Executes on button press in stop. function stop_Callback(hObject, eventdata, handles) % hObject handle to stop (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % wavwrite(handles.data,'mywav.wav'); AI=handles.AI; stop(AI); % ù % handles.AI=AI; guidata(hObject, handles); % --- Executes on button press in save. function save_Callback(hObject, eventdata, handles) % hObject handle to save (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) d=handles.data; name=handles.filename; % ± wavwrite(d,name); % ± function name_Callback(hObject, eventdata, handles) % hObject handle to name (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 name as text % str2double(get(hObject,'String')) returns contents of name as a double handles.filename=get(hObject,'String'); % ± guidata(hObject, handles); % --- Executes during object creation, after setting all properties. function name_CreateFcn(hObject, eventdata, handles) % hObject handle to name (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 set(hObject,'BackgroundColor','white'); else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor')); end % --- Executes on button press in wavepos. function wavepos_Callback(hObject, eventdata, handles) % hObject handle to wavepos (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) y=handles.data; % ù axes(handles.axes2); % èúò plot(handles.t,y); % ±ò¨ ylabel('signal Magnitude '); xlabel('time(s)'); title('时域波形'); % --- Executes on button press in fftplot. function fftplot_Callback(hObject, eventdata, handles) % hObject handle to fftplot (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) Fs=handles.sample; % ù data=handles.data; % ù blockSize=length(data); xFFT = fft(data); % ± xfft = abs(xFFT); % ·ù %% % Avoid taking the log of 0. index = find(xfft == 0); xfft(index) = 1e-17; mag = 20*log10(xfft); % ·ù·± mag = mag(1:blockSize/2); f = (0:length(mag)-1)*Fs/blockSize; f = f(:); axes(handles.axes2); plot(f(:,1),mag(:,1)); ylabel('Magnitude (dB)'); xlabel('Frequency (Hz)'); title('频谱图'); % --- Executes on button press in daopu. function daopu_Callback(hObject, eventdata, handles) % hObject handle to daopu (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) c=fft(log(abs(handles.data)+eps)); % × ms1=handles.sample/1000; ms20=handles.sample/50; q=(ms1:ms20)/handles.sample; axes(handles.axes2); plot(q,abs(c(ms1:ms20))); xlabel('倒角'); ylabel('倒谱幅度'); title('倒谱图'); % -------------------------------------------------------------------- function datagetsve_Callback(hObject, eventdata, handles) % hObject handle to datagetsve (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % -------------------------------------------------------------------- function init_Callback(hObject, eventdata, handles) % hObject handle to init (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) clear all; clc; % -------------------------------------------------------------------- function openexistdata_Callback(hObject, eventdata, handles) % hObject handle to openexistdata (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) [FileName,PathName]= uigetfile('*.wav'); if ~isequal(FileName, 0) % open(file); [y fs]=wavread([PathName FileName]); end handles.data=y; handles.sample=fs; t=length(handles.data)/fs; tt=0:t/length(handles.data):t; handles.t=tt(1:length(tt)-1); guidata(hObject, handles); axes(handles.axes2); plot(handles.t,y); % ±ò¨ ylabel('signal Magnitude '); xlabel('time(s)'); title('时域波形'); % -------------------------------------------------------------------- function getdata_Callback(hObject, eventdata, handles) % hObject handle to getdata (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) AI=handles.AI; duration = handles.time; % èù± AI.SampleRate=handles.sample; % èù ActualRate = get(AI,'SampleRate'); % ù set(AI,'SamplesPerTrigger',duration*ActualRate) % è·ù handles.AI=AI; % ±ù¨è±è guidata(hObject, handles); P=handles.P; % ±ú start(AI) % i = 1; while AI.SamplesAcquired < AI.SamplesPerTrigger % 1000ùü if strcmp(AI.Running, 'On') % ÷stopò· while AI.SamplesAcquired < 1000*i end data = peekdata(AI,1000); set(P,'ydata',data); drawnow i = i + 1; else break; end end [handles.data handles.t] = getdata(AI,AI.SamplesAcquired); %±ùà± % handles.AI=AI; % length(handles.data) guidata(hObject, handles); stop(AI); % -------------------------------------------------------------------- function datasave_Callback(hObject, eventdata, handles) % hObject handle to datasave (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) [file,path] = uiputfile('mynewwav.wav','Save file name'); if file==0 else if length(handles.data)>0 wavwrite(handles.data,[path file]); end end % -------------------------------------------------------------------- function analysis_Callback(hObject, eventdata, handles) % hObject handle to analysis (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % -------------------------------------------------------------------- function Untitled_7_Callback(hObject, eventdata, handles) % hObject handle to Untitled_7 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % -------------------------------------------------------------------- function fftmenu_Callback(hObject, eventdata, handles) % hObject handle to fftmenu (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) fftplot_Callback(hObject, eventdata, handles); % -------------------------------------------------------------------- function recps_Callback(hObject, eventdata, handles) % hObject handle to recps (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) daopu_Callback(hObject, eventdata, handles); % -------------------------------------------------------------------- function filter_Callback(hObject, eventdata, handles) % hObject handle to filter (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % -------------------------------------------------------------------- function window_Callback(hObject, eventdata, handles) % hObject handle to window (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) Winsiz=256;Shift=128;Base=0; signal=handles.data; fs=handles.sample; nseg=floor((length(signal)-Winsiz)/Shift)+1; A=zeros(Winsiz/2+1,nseg); for i=1:nseg n1=(i-1)*Shift+1;n2=n1+(Winsiz-1); xx=signal(n1:n2);xx=xx.*hamming(Winsiz); y=fft(xx);y=y(1:Winsiz/2+1); y=y.*conj(y);y=10*log10(y);A(:,i)=y; end L1=(A>Base);L0=(A<Base);B=A.*L1+Base*L0; C=(B-Base)./(max(max(B))-Base); y=[0:Winsiz/2]*fs/Winsiz;x=[0:nseg-1]*Shift; % if Coltype==1 colormap(hot); % else % my axes(handles.axes2); imagesc(x,y,C);axis xy; % -------------------------------------------------------------------- function picsave_Callback(hObject, eventdata, handles) % hObject handle to picsave (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % end % -------------------------------------------------------------------- function wavsave_Callback(hObject, eventdata, handles) % hObject handle to wavsave (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) [file,path] = uiputfile('wave.jpg','Save file name'); if file==0 else if length(handles.data)>0 h=figure; plot(handles.t,handles.data); saveas(h,[path file]); close(h); else h=figure; saveas(h,[path file]); close(h); end end % -------------------------------------------------------------------- function savefftpic_Callback(hObject, eventdata, handles) % hObject handle to savefftpic (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) Fs=handles.sample; % ù data=handles.data; % ù blockSize=length(data); xFFT = fft(data); % ± xfft = abs(xFFT); % ·ù %% % Avoid taking the log of 0. index = find(xfft == 0); xfft(index) = 1e-17; mag = 20*log10(xfft); % ·ù·± mag = mag(1:blockSize/2); f = (0:length(mag)-1)*Fs/blockSize; f = f(:); [file,path] = uiputfile('fft.jpg','Save file name'); if file==0 else h=figure; plot(f(:,1),mag(:,1)); ylabel('Magnitude (dB)'); xlabel('Frequency (Hz)'); title('频谱图'); saveas(h,[path file]); close(h); end % -------------------------------------------------------------------- function picdaopusave_Callback(hObject, eventdata, handles) % hObject handle to picdaopusave (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) c=fft(log(abs(handles.data)+eps)); % × ms1=handles.sample/1000; ms20=handles.sample/50; q=(ms1:ms20)/handles.sample; [file,path] = uiputfile('daopu.jpg','Save file name'); if file==0 else h=figure; plot(q,abs(c(ms1:ms20))); xlabel('倒角'); ylabel('倒谱幅度'); title('倒谱图'); saveas(h,[path file]); close(h); end % -------------------------------------------------------------------- function picyupusave_Callback(hObject, eventdata, handles) % hObject handle to picyupusave (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) Winsiz=256;Shift=128;Base=0; signal=handles.data; fs=handles.sample; nseg=floor((length(signal)-Winsiz)/Shift)+1; A=zeros(Winsiz/2+1,nseg); for i=1:nseg n1=(i-1)*Shift+1;n2=n1+(Winsiz-1); xx=signal(n1:n2);xx=xx.*hamming(Winsiz); y=fft(xx);y=y(1:Winsiz/2+1); y=y.*conj(y);y=10*log10(y);A(:,i)=y; end L1=(A>Base);L0=(A<Base);B=A.*L1+Base*L0; C=(B-Base)./(max(max(B))-Base); y=[0:Winsiz/2]*fs/Winsiz;x=[0:nseg-1]*Shift; % if Coltype==1 colormap(hot); % else % my [file,path] = uiputfile('yuputu.jpg','Save file name'); if file==0 else h=figure; imagesc(x,y,C);axis xy; saveas(h,[path file]); close(h); end % -------------------------------------------------------------------- function gonglvpu_Callback(hObject, eventdata, handles) % hObject handle to gonglvpu (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % -------------------------------------------------------------------- function ggp_Callback(hObject, eventdata, handles) % hObject handle to ggp (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) Fs=handles.sample; %ù xn=handles.data; window=boxcar(length(xn)); %° nfft=1024; [Pxx,f]=periodogram(xn,window,nfft,Fs); %±·¨ plot(f,10*log10(Pxx)); title('功率谱'); % --- Executes on button press in radiobutton2. function radiobutton2_Callback(hObject, eventdata, handles) % hObject handle to radiobutton2 (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 radiobutton2 % --- Executes on button press in radiobutton3. function radiobutton3_Callback(hObject, eventdata, handles) % hObject handle to radiobutton3 (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 radiobutton3 % --- Executes on button press in radiobutton4. function radiobutton4_Callback(hObject, eventdata, handles) % hObject handle to radiobutton4 (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 radiobutton4 % --- Executes on button press in radiobutton5. function radiobutton5_Callback(hObject, eventdata, handles) % hObject handle to radiobutton5 (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 radiobutton5 % --- Executes on selection change in popupmenu1. function popupmenu1_Callback(hObject, eventdata, handles) % hObject handle to popupmenu1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: contents = get(hObject,'String') returns popupmenu1 contents as cell array % contents{get(hObject,'Value')} returns selected item from popupmenu1 % --- Executes during object creation, after setting all properties. function popupmenu1_CreateFcn(hObject, eventdata, handles) % hObject handle to popupmenu1 (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 set(hObject,'BackgroundColor','white'); else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor')); end % --- Executes on selection change in popupmenu2. function popupmenu2_Callback(hObject, eventdata, handles) % hObject handle to popupmenu2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: contents = get(hObject,'String') returns popupmenu2 contents as cell array % contents{get(hObject,'Value')} returns selected item from popupmenu2 % --- Executes during object creation, after setting all properties. function popupmenu2_CreateFcn(hObject, eventdata, handles) % hObject handle to popupmenu2 (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 set(hObject,'BackgroundColor','white'); else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor')); end % --- Executes on button press in radiobutton6. function radiobutton6_Callback(hObject, eventdata, handles) % hObject handle to radiobutton6 (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 radiobutton6 % --- Executes on button press in radiobutton7. function radiobutton7_Callback(hObject, eventdata, handles) % hObject handle to radiobutton7 (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 radiobutton7 % --- Executes on button press in radiobutton8. function radiobutton8_Callback(hObject, eventdata, handles) % hObject handle to radiobutton8 (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 radiobutton8 % --- Executes on button press in radiobutton9. function radiobutton9_Callback(hObject, eventdata, handles) % hObject handle to radiobutton9 (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 radiobutton9 % --- Executes on button press in radiobutton10. function radiobutton10_Callback(hObject, eventdata, handles) % hObject handle to radiobutton10 (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 radiobutton10 % --- Executes on button press in radiobutton11. function radiobutton11_Callback(hObject, eventdata, handles) % hObject handle to radiobutton11 (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 radiobutton11