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

📄 performprony.m

📁 prony matlab toolbox
💻 M
📖 第 1 页 / 共 4 页
字号:
    case 5 % All Residues
        Resplot(handles,FirstResults);
    case 6 % Energy
        Energyplot(handles,FirstResults);
    otherwise
        seerror(handles,Results);
    end
    
%---------------------------------
%---------------------------------
function [PronyResults]=getPronyResults(handles)
   PronyResults =struct('NewVal',[],'SUB_N',[],'iapp',[],'ai',[],...
		        'a_list',[],'tau_list',[],'omega_list',[],...
                'SUB_IND',[],'energy',[],'criteria_val',[],...
                'p',[],'mode_selectionid',[]);
    PronyResults.mode_selectionid=1;       
    PronyResults.criteria_val = get(handles.ppmenu_criteria,'Value');
    PronyResults.NewVal=fetch_NewVal(handles);
    PronyResults.SUB_N=fetch_SUB_N(handles,PronyResults.NewVal);
    [iapp,ai,a_list,tau_list,omega_list,SUB_IND,energy,p]=applyprony(handles.test_time,handles.test_data,PronyResults.NewVal,PronyResults.SUB_N,PronyResults.criteria_val);
    PronyResults.iapp = iapp;
    PronyResults.a_list=a_list;
    PronyResults.tau_list=tau_list;
    PronyResults.omega_list=omega_list;
    PronyResults.SUB_IND=SUB_IND;
    PronyResults.energy=energy;
    PronyResults.p=p;
    PronyResults.ai=ai;
    
  function [FinalResults]= selectedmodes_results(handles,PronyResults)
    
  FinalResults= struct('NewVal',[],'SUB_N',[],'iapp',[],'ai',[],...
		        'a_list',[],'tau_list',[],'omega_list',[],...
                'SUB_IND',[],'energy',[],'criteria_val',[],...
                'p',[],'mode_selectionid',[]);
           
    FinalResults=PronyResults;
    FinalResults.mode_selectionid=get(handles.ppmenu_modesfit,'Value');
    val_modesfit = get(handles.ppmenu_modesfit,'Value');
    switch val_modesfit
        case 1  % All Modes
             selected_SUBIND=PronyResults.SUB_IND;
             set(handles.lstbx_numeric,'Value',1);
        case 2 % Selected Modes only
             Index_Selected=get(handles.lstbx_numeric,'Value');
             % if nothing is selected
                if (isempty(Index_Selected))
                    errordlg('Please select modes','No Mode Selected !!');
                    whitebg('k'); 
                end
                if(size(Index_Selected,2) < size(PronyResults.SUB_IND,2))
                    selected_SUBIND=PronyResults.SUB_IND(Index_Selected);
                else
                    selected_SUBIND=PronyResults.SUB_IND;
                end
        case 3 % All but selected
            Index_Selected=get(handles.lstbx_numeric,'Value');
            % if nothing is selected
                if (isempty(Index_Selected))
                    errordlg('Please select modes','No Mode Selected !!');
                    whitebg('k'); 
                end
            index=1:size(PronyResults.SUB_IND,2);
            n=1;
            for m=1:size(index,2)
                if(m~=Index_Selected(:))
                    not_selected(n)=m;
                    n=n+1;
                end
            end
            selected_SUBIND=PronyResults.SUB_IND(not_selected);
    end % end the switch
    % Save the results
    FinalResults.SUB_IND=selected_SUBIND;
    ai=zeros(size(handles.test_time));
    test_t_increment=handles.test_time(2)-handles.test_time(1);
    fs=1/test_t_increment; % Sampling frequency
    spoles=log(FinalResults.p(:))*fs; 
    for index=selected_SUBIND
        ai=ai+FinalResults.a_list(index)*exp(spoles(index)*handles.test_time);
    end
    ai=real(ai);
    FinalResults.ai = ai;
    % if all the modes are selected then fit should be same
    if(get(handles.ppmenu_modesfit,'Value')==1)
        FinalResults.ai= PronyResults.ai;
    end
    
%--------------------

% --- Executes amplitude criteria for time domain
function prony_time(handles,Results);

% handles    structure with handles and user data (see GUIDATA)
axes(handles.axes_modesfit);
order=size(Results.p,1);
suborder=size(Results.SUB_IND,2);
plot(handles.test_time,Results.ai,'r',handles.test_time,handles.test_data,'b');
title(sprintf('Prony Approximation of Model Order %d, Picking %d Residues',order,suborder));
legend('Prony Sub-Approximate','Measured');
ylabel('Signal'),xlabel('Time');



%----------------------------------
% 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 doublefunction [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');

% --------------------------------------------------------------------

⌨️ 快捷键说明

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