⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 performprony.m

📁 matlab 非平稳信号分析
💻 M
📖 第 1 页 / 共 3 页
字号:
% Function to show amplitude residue criteria in frequency domain
function prony_frequency(handles,Results)

[f,fft_data_plot,fft_iapp_plot]= fft_analysis(handles.test_time,handles.test_data,Results.ai);
axes(handles.axes_modesfit);
plot(f,fft_iapp_plot,'r',f,fft_data_plot,'b');
title(sprintf('Prony Approximation of Model Order %d, Picking %d Residues in Frequency Domain',Results.NewVal,size(Results.SUB_IND,2)));
legend('Prony Sub-Approximate','Measured');% place it at lower right corner of the axis
xlabel('Frequency');
ylabel('Magnitude (dB)');



%-----------------------------------------------------
%---------------------------------------------------
function PZplot(handles,Results)
    [inummz,idennz]=residuez(Results.a_list(Results.SUB_IND),Results.p(Results.SUB_IND),1);
    zplane(inummz,idennz,'y');axis([-1.1 1.1 -1.1 1.1]),xlabel('Real Part'), ylabel('Imaginary Part')
    title('Poles Zero Plot')

  
function seerror(handles,Results)
    seerror=(handles.test_data(:)-Results.ai(:)).^2;
    plot(handles.test_time,seerror,'b');xlabel('Time'), ylabel('Squared Error')
    title(sprintf('Squared Error for Model Order %d and Picking %d Residues',Results.NewVal,size(Results.SUB_IND,2)))
    % Compute the normalized mean squared error
    mse=sum(seerror)/size(seerror,1);
    %nmse=sum(seerror)/sum((handles.test_data).^2);
    set(handles.edit_mse,'String',sprintf('%10.1f',mse));
    
function Resplot(handles,Results)
    
    aa_list=abs(2*Results.a_list(Results.SUB_IND'));
    Index=1:size(Results.SUB_IND,2);
    semilogy(Index,aa_list,'b'); 
    axis([0 max(Index)+1 0 1.1*max(aa_list)]),xlabel('Index'), ylabel('Residue Magnitude')
    title(sprintf('Prony Residue Magnitude "Decay" for %d Modes',max(Index)))

    
function Energyplot(handles,Results)
    Index=1:Results.NewVal;
    semilogy(Index,Results.energy(Results.SUB_IND'),'b');
    axis([0 max(Index)+1 0 1.1*max(Results.energy)]),xlabel('Index'),ylabel('Energy')
    title('Energy of Prony Modes');
  
 function polesplot(handles,Results)
    
    [inummz,idennz]=residuez(Results.a_list(Results.SUB_IND),Results.p(Results.SUB_IND),1);
    inummz=0;
    zplane(inummz,idennz,'y');axis([-1.1 1.1 -1.1 1.1]);xlabel('Real Part')
    ylabel('Imaginary Part'),title('Poles Plot');
    

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

function [SUB_N]=fetch_SUB_N(handles,NewVal)
set(handles.ppmenu_pronyplots,'enable','on');
setstatus(gcbf,'Choose "Save" from "Session" Menu to Save');
SUBN=str2double(get(handles.edittxtmodes,'String'));
if(SUBN > NewVal)
    answer=inputdlg('Number of Modes has to be Less than Model Order !!                                 Please input the Number of Modes','Change Input Number of Modes',1);
    SUBN=str2double(answer);
    SUB_N=check_SUB_N(handles,SUBN,NewVal);% to make sure that complex conjugate is selected
    set(handles.edittxtmodes,'String',SUB_N);
end
SUB_N=check_SUB_N(handles,SUBN,NewVal);

% Make sure that user cannot select one mode , if the user selects
% one pole then check if the next pole is complex conjugate of it or not 
% if it is, then change SUB_N value accordingly
% fix the SUBN so that it does not exceed the NewVal
% SUBN is no. of modes inserted by user
% SUB_N is the checked and correct modes
function [SUB_N]=check_SUB_N(handles,SUBN,NewVal)
if (SUBN==NewVal)
    SUBN=SUBN-1;
end
[iapp,ai,a_list,tau_list,omega_list,SUB_IND,energy,p]=applyprony(handles.test_time,handles.test_data,NewVal,0,handles.criteria_val);
aa_list=2*abs(a_list(SUB_IND));
ttau_list=abs(tau_list(SUB_IND));
oomega_list=abs(omega_list(SUB_IND));
Acond=abs(aa_list(SUBN+1)-aa_list(SUBN));
taucond=abs((1/ttau_list(SUBN+1))-(1/ttau_list(SUBN)));
omegacond=abs(oomega_list(SUBN+1)-oomega_list(SUBN));
if((Acond<0.01) & (taucond<0.001) & (omegacond<0.0001))
    SUB_N=SUBN+1;
    set(handles.edittxtmodes,'String',SUB_N);
else
    SUB_N=SUBN;
end



function [NewVal]=fetch_NewVal(handles)

NewVal = round(str2num(get(handles.edit_morder,'String')));
if (NewVal<=0)
    answer=inputdlg('Model Order Must be a Postive Integer','Correct Model Order',1);
    NewVal=str2double(answer)
    set(handles.edit_morder,'String',NewVal);
end


% --- Executes on button press in push_modeselection.
function push_modeselection_Callback(hObject, eventdata, handles)
% hObject    handle to push_modeselection (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
     PronyResults=getPronyResults(handles);
    FinalResults=selectedmodes_results(handles,PronyResults);
    perform_plotcriteria(handles,FinalResults);


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

    PronyResults=getPronyResults(handles);
    FinalResults=selectedmodes_results(handles,PronyResults);
    perform_plotcriteria(handles,FinalResults);
    
    
% --- Executes on button press in ppmenu_modesfit.
function ppmenu_modesfit_Callback(hObject,eventdata,handles)
% hObject    handle to ppmenu_modesfit (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 ppmenu_modesfit
 
% --------------------------------------------------------------------
function menu_saveworkspace_Callback(hObject, eventdata, handles)
% hObject    handle to menu_saveworkspace (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% Flag to say that user has saved atleast one session
     handles.menu_saveflag=1;
     handles.menu_saveasflag=0; % saveas flag as 
    guidata(hObject,handles); % store the changes
set(handles.push_sessionscompare,'enable','on');
%Run=handles.RunNum;
% Retrieve old results data structure
setstatus(gcbf,'Press "Compare Sessions" To compare');
PronyResults=getPronyResults(handles);
FinalResults= selectedmodes_results(handles,PronyResults);
[SaveData,maxNum]= prepare_savedata(FinalResults,handles,hObject);
% Assign the data to Base Workspace
assignin('base','SaveData',SaveData);
assignin('base','maxNum',maxNum);
% Message to the user that data is saved
h_msg=msgbox('The Session is Successfully Saved','Save Session','replace');
whitebg('white');

% --------------------------------------------------------------------
function menu_saveinfile_Callback(hObject, eventdata, handles)
% hObject    handle to menu_saveinfile (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% Flag to say that user has saved atleast one session
% Flag to say that user has saved atleast one session
     
[cmpfile, cmppath] = uiputfile( ...
    {'*.cmp', 'All CMP-Files (*.cmp)'},...
    'Save as a file');
if isequal(cmpfile,0) | isequal(cmppath,0)
         return
end
if ~ismember('.',cmpfile)
         cmpfile = [cmpfile '.cmp'];
end
set(handles.push_sessionscompare,'enable','on');
handles.menu_saveflag=1;
handles.menu_saveasflag=1;% flag to check option of save  Is it save as ??
guidata(hObject,handles); % store the changes
PronyResults=getPronyResults(handles);
FinalResults= selectedmodes_results(handles,PronyResults);
[SaveData,maxNum]= prepare_savedata(FinalResults,handles,hObject);
 cmpfullname=fullfile(cmppath,cmpfile);
 save(cmpfullname,'SaveData','maxNum','-mat');
guidata(hObject,handles); % store the changes
% Message to the user that data is saved
h_msg=msgbox('The Sessions are saved in Successfully in the file','Save Session','replace');
whitebg('white');
  

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

close(gcf);

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

if (handles.menu_saveflag==1)
    comparesessions;
    IIGuiData = prepare_guidata(handles);
    assignin('base','IIGuiData',IIGuiData);
else
    % Message to the user that data is saved
    warndlg('Please Save the Session to Use the Compare Sessions Tool !!',' Warning Save Session');
    whitebg('white');    
end


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


% --------------------------------------------------------------------
function menu_pronytool_Callback(hObject, eventdata, handles)
% hObject    handle to menu_pronytool (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
HelpPath = which ('pronytoolhelp.html');
web(HelpPath,'-browser');

% --------------------------------------------------------------------
function menu_about_Callback(hObject, eventdata, handles)
% hObject    handle to menu_about (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
HelpPath = which ('about.html');
web(HelpPath,'-browser'); 


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

HelpPath = which ('demos.html');
web(HelpPath,'-browser');

function [IIGuiData]= prepare_guidata(handles)
IIGuiData= struct('NewVal',[],'SUB_N',[],'iapp',[],'ai',[],...
		        'a_list',[],'tau_list',[],'omega_list',[],...
                'SUB_IND',[],'energy',[],'criteria_val',[],...
                'p',[],'mode_selectionid',[],'test_time',[],'test_data',[],...
                'f1',[],'fft_iapp1',[],'fft_data1',[],...
                'f2',[],'fft_iapp2',[],'fft_data2',[],...
                'inummz',[],'idennz',[],'seerror',[],'aa_list',[],...
                'all_res',[],'res_SUBIND',[]);
                
PronyResults=getPronyResults(handles);
FinalResults=selectedmodes_results(handles,PronyResults);  
IIGuiData=FinalResults;
FirstResults=save_FirstResults(handles);
IIGuiData.iapp=FirstResults.iapp;
IIGuiData.test_time=handles.test_time;
IIGuiData.test_data=handles.test_data;
[f1,fft_data1,fft_iapp1]= fft_analysis(handles.test_time,handles.test_data,FirstResults.iapp);
IIGuiData.f1=f1;
IIGuiData.fft_iapp1=fft_iapp1;
IIGuiData.fft_data1=fft_data1;
[f2,fft_data2,fft_iapp2]= fft_analysis(handles.test_time,handles.test_data,FinalResults.ai);
IIGuiData.f2=f2;
IIGuiData.fft_iapp2=fft_iapp2;
IIGuiData.fft_data2=fft_data2;
[IIGuiData.inummz,IIGuiData.idennz]=residuez(FinalResults.a_list(FinalResults.SUB_IND),FinalResults.p(FinalResults.SUB_IND),1);
IIGuiData.seerror=(handles.test_data(:)-FinalResults.ai(:)).^2;
IIGuiData.aa_list=abs(2*FinalResults.a_list(FinalResults.SUB_IND'));
IIGuiData.all_res= abs(2*FirstResults.a_list(FirstResults.SUB_IND'));
IIGuiData.res_SUBIND=FirstResults.SUB_IND;
IIGuiData.energy=FirstResults.energy;


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


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


% --------------------------------------------------------------------
function plotnew_time_pronyfit_Callback(hObject, eventdata, handles)
% hObject    handle to plotnew_time_pronyfit (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
IIGuiData = prepare_guidata(handles);
figure('Color','White');
plot(IIGuiData.test_time,IIGuiData.iapp,'r',IIGuiData.test_time,IIGuiData.test_data,'b');
xlabel('Time'),ylabel('Signal');
title(sprintf('Prony Analysis of Model Order %d in Time Domain',IIGuiData.NewVal))
legend('Prony Approximate', 'Measured')
        
    
% --------------------------------------------------------------------
function plotnew_frequency_pronyfit_Callback(hObject, eventdata, handles)
% hObject    handle to plotnew_frequency_pronyfit (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
 % implement frequency domain prony
IIGuiData = prepare_guidata(handles);
figure('Color','White');
plot(IIGuiData.f1,IIGuiData.fft_iapp1,'r',IIGuiData.f1,IIGuiData.fft_data1,'b');
xlabel('Frequency'),ylabel('  Magnitude (dB)  ');
title(sprintf('Prony Analysis of Model Order %d in Frequency Domain',IIGuiData.NewVal))
legend('Prony Approximate', 'Measured')



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


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


% --------------------------------------------------------------------
function plotnew_time_modesfit_Callback(hObject, eventdata, handles)
% hObject    handle to plotnew_time_modesfit (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
IIGuiData = prepare_guidata(handles);
figure('Color','White');
plot(IIGuiData.test_time,IIGuiData.ai,'r',IIGuiData.test_time,IIGuiData.test_data,'b');
title(sprintf('Prony Approximation of Model Order %d, Picking %d Residues',IIGuiData.NewVal,IIGuiData.SUB_N));

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -