function varargout = respfreq(varargin) % RESPFREQ M-file for respfreq.fig % RESPFREQ, by itself, creates a new RESPFREQ or raises the existing % singleton*. % % H = RESPFREQ returns the handle to a new RESPFREQ or the handle to % the existing singleton*. % % RESPFREQ('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in RESPFREQ.M with the given input arguments. % % RESPFREQ('Property','Value',...) creates a new RESPFREQ or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before respfreq_OpeningFcn gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to respfreq_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 respfreq % Last Modified by GUIDE v2.5 11-Jul-2016 20:42:30 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @respfreq_OpeningFcn, ... 'gui_OutputFcn', @respfreq_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 respfreq is made visible. function respfreq_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 respfreq (see VARARGIN) % Acompanhamento % Função de transferência de referência KKtref = handles.KKtref; Tref = handles.Tref; % Diagrama de Bode [Gref,Fref,Wref]=bode(tf(KKtref,[Tref 1])); Gref = squeeze(Gref); Fref = squeeze(Fref); Gref = 20*log10(Gref); % Carrega o arquivo de dados (se houver) if exist('./respfreq_data.mat')==2 load('./respfreq_data.mat'); else wdata=NaN; Gdata=NaN; Fdata=NaN; end % Seleciona o último ponto isel = length(wdata); handles.wdata = wdata; handles.Gdata = Gdata; handles.Fdata = Fdata; handles.Wref = Wref; handles.Gref = Gref; handles.Fref = Fref; handles.wcand = NaN; handles.Gcand = NaN; handles.Fcand = NaN; handles.isel = isel; set(handles.axes3,'FontSize',6); hh=semilogx(handles.axes3,Wref,Gref,'-',wdata,Gdata,'ko',wdata(isel),Gdata(isel),'ko'); set(hh(1),'Color',0.7*[1 1 1],'LineWidth',2); set(hh(2),'MarkerSize',4,'MarkerFaceColor',0*[1 1 1]); set(hh(3),'MarkerSize',8,'Color',0*[1 1 1]); set(handles.axes6,'FontSize',6); hh=semilogx(handles.axes6,Wref,Fref,'-',wdata,Fdata,'ko',wdata(isel),Fdata(isel),'ro'); set(hh(1),'Color',0.7*[1 1 1],'LineWidth',2); set(hh(2),'MarkerSize',4,'MarkerFaceColor',0*[1 1 1]); set(hh(3),'MarkerSize',8,'Color',0*[1 1 1]); % Ajustar controles % 1. entrada % 2. coletar (desabilitar) set(handles.pushbutton6,'Enable','off'); set(handles.pushbutton6,'ForegroundColor',0.5*[1 1 1]); % 3. aceitar (desabilitar) set(handles.pushbutton9,'Enable','off'); set(handles.pushbutton9,'ForegroundColor',0.5*[1 1 1]); set(handles.text56,'String','y(t) = A*sen(w*t+phi)'); handles.GdB = NaN; set(handles.edit19,'String',''); set(handles.edit19,'Enable','off'); handles.Fgr = NaN; set(handles.edit20,'String',''); set(handles.edit20,'Enable','off'); % Eixo simulação (desabilitar) set(handles.axes5,'Visible','off'); set(handles.text66,'Visible','off'); % Acompanhamento (habilitar) set(handles.edit21,'Enable','on'); set(handles.edit23,'Enable','on'); set(handles.pushbutton11,'Enable','on'); set(handles.pushbutton11,'ForegroundColor',0*[1 1 1]); set(handles.pushbutton12,'Enable','on'); set(handles.pushbutton12,'ForegroundColor',0*[1 1 1]); % Choose default command line output for respfreq handles.output = hObject; % Update handles structure guidata(hObject, handles); % UIWAIT makes respfreq wait for user response (see UIRESUME) % uiwait(handles.figure1); % --- Outputs from this function are returned to the command line. function varargout = respfreq_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 pushbutton6. function pushbutton6_Callback(hObject, eventdata, handles) % hObject handle to pushbutton6 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Coletar os dados tsim = handles.tsim; Ai = handles.Ai; w = handles.w; Wref = handles.Wref; Gref = handles.Gref; Fref = handles.Fref; wdata = handles.wdata; Gdata = handles.Gdata; Fdata = handles.Fdata; isel = handles.isel; % Desabilitar todos os controles para não atrapalhar a coleta de dados % 1. entrada set(handles.edit11,'Enable','off'); set(handles.edit12,'Enable','off'); % 2. coletar set(handles.pushbutton6,'Enable','off'); set(handles.pushbutton6,'ForegroundColor',0.5*[1 1 1]); % 3. aceitar set(handles.pushbutton9,'Enable','off'); set(handles.pushbutton9,'ForegroundColor',0.5*[1 1 1]); set(handles.text56,'String','y(t) = A*sen(w*t+phi)'); handles.GdB = NaN; set(handles.edit19,'String',''); set(handles.edit19,'Enable','off'); handles.Fgr = NaN; set(handles.edit20,'String',''); set(handles.edit20,'Enable','off'); % Eixo simulação cla(handles.axes5); set(handles.axes5,'Visible','off'); set(handles.text66,'Visible','on'); % Acompanhamento set(handles.edit21,'Enable','off'); set(handles.edit23,'Enable','off'); set(handles.pushbutton11,'Enable','off'); set(handles.pushbutton11,'ForegroundColor',0.5*[1 1 1]); set(handles.pushbutton12,'Enable','off'); set(handles.pushbutton12,'ForegroundColor',0.5*[1 1 1]); % Atualizar o acompanhamento sem o ponto candidato set(handles.axes3,'FontSize',6); hh=semilogx(handles.axes3,Wref,Gref,'-',wdata,Gdata,'ko',wdata(isel),Gdata(isel),'ko',[w w],get(handles.axes3,'Ylim'),'g-'); set(hh(1),'Color',0.7*[1 1 1],'LineWidth',2); set(hh(2),'MarkerSize',4,'MarkerFaceColor',0*[1 1 1]); set(hh(3),'MarkerSize',8,'Color',0*[1 1 1]); set(hh(4),'Color',0.5*[0 1 0],'LineWidth',1.5); set(handles.axes6,'FontSize',6); hh=semilogx(handles.axes6,Wref,Fref,'-',wdata,Fdata,'ko',wdata(isel),Fdata(isel),'ro',[w w],get(handles.axes6,'Ylim'),'g-'); set(hh(1),'Color',0.7*[1 1 1],'LineWidth',2); set(hh(2),'MarkerSize',4,'MarkerFaceColor',0*[1 1 1]); set(hh(3),'MarkerSize',8,'Color',0*[1 1 1]); set(hh(4),'Color',0.5*[0 1 0],'LineWidth',1.5); % Preparar a simulação options = simset('SrcWorkspace','current','DstWorkspace','current'); % a simulação precisa de tsim, Ai, w if tsim>0 sim('respfreq_sim.mdl',tsim,options); else tdata = NaN; udata = NaN; ydata = NaN; end % devem ter sido geradas tdata,udata,ydata T = handles.T; NT = handles.NT; DT = handles.DT; itrans = find(tdata < DT); irps = find(tdata >= DT); % Ajustar a senoide por regressão. t = tdata(irps); t=t(:); x = ydata(irps); x=x(:); A = [sin(w*t) cos(w*t)]; v = A\x; % solução do problema linear de mínimos quadrados por decomposição QR Ao = sqrt(v'*v); phi = atan2(v(2),v(1))*180/pi; yopt = Ao*sin(w*tdata(irps)+phi*pi/180); % Ganho e fase na frequência w GdB = 20*log10(Ao/Ai); Fgr = phi; % O ponto calculado é o candidato atual wcand = w; Gcand = GdB; Fcand = Fgr; % Armazenar valores handles.GdB = GdB; handles.Fgr = Fgr; handles.Ao = Ao; handles.phi = phi; handles.irps = irps; handles.itrans = itrans; handles.tdata = tdata; handles.udata = udata; handles.ydata = ydata; handles.wcand = wcand; handles.Gcand = Gcand; handles.Fcand = Fcand; % Mostrar os gráficos coletados com o ajuste set(handles.axes5,'Visible','on'); set(handles.text66,'Visible','off'); set(handles.axes5,'FontSize',8); h = plot(handles.axes5,tdata(itrans),ydata(itrans),'k-',tdata(irps),ydata(irps),'r-',tdata,udata,'k-',tdata(irps),yopt,'r-'); set(h(1),'Color',0.7*[1 1 1],'LineWidth',1.5); set(h(2),'Color',0.5*[0 1 0],'LineWidth',1.5); set(h(4),'Color',1*[1 0 0],'LineWidth',1.5); xlabel(handles.axes5,'t (s)'); ylabel(handles.axes5,'u(t), y(t) (V)'); set(handles.axes5,'Xlim',[tdata(1) tdata(end)]); % Atualizar o acompanhamento com o ponto candidato set(handles.axes3,'FontSize',6); hh=semilogx(handles.axes3,Wref,Gref,'-',wdata,Gdata,'ko',wdata(isel),Gdata(isel),'ko',wcand,Gcand,'ro',[w w],get(handles.axes3,'Ylim'),'g-'); set(hh(1),'Color',0.7*[1 1 1],'LineWidth',2); set(hh(2),'MarkerSize',4,'MarkerFaceColor',0*[1 1 1]); set(hh(3),'MarkerSize',8,'Color',0*[1 1 1]); set(hh(4),'MarkerSize',8,'MarkerFaceColor',[1 0 0]); set(hh(5),'Color',0.5*[0 1 0],'LineWidth',1.5); set(handles.axes6,'FontSize',6); hh=semilogx(handles.axes6,Wref,Fref,'-',wdata,Fdata,'ko',wdata(isel),Fdata(isel),'ro',wcand,Fcand,'ro',[w w],get(handles.axes6,'Ylim'),'g-'); set(hh(1),'Color',0.7*[1 1 1],'LineWidth',2); set(hh(2),'MarkerSize',4,'MarkerFaceColor',0*[1 1 1]); set(hh(3),'MarkerSize',8,'Color',0*[1 1 1]); set(hh(4),'MarkerSize',8,'MarkerFaceColor',[1 0 0]); set(hh(5),'Color',0.5*[0 1 0],'LineWidth',1.5); % Ajuste dos controles ao final da coleta e ajuste % 1. entrada set(handles.edit11,'Enable','on'); set(handles.edit12,'Enable','on'); % 2. coletar set(handles.pushbutton6,'Enable','on'); set(handles.pushbutton6,'ForegroundColor',0*[1 1 1]); % 4. aceitar set(handles.pushbutton9,'Enable','on'); set(handles.pushbutton9,'ForegroundColor',0*[1 1 1]); if phi<0 ystr = sprintf('y(t) = %0.2f*sen(%0.2f*t - %0.0f)',Ao,w,abs(phi)); else ystr = sprintf('y(t) = %0.2f*sen(%0.2f*t + %0.0f)',Ao,w,abs(phi)); end set(handles.text56,'string',ystr); set(handles.edit19,'String',num2str(GdB)); set(handles.edit19,'Enable','inactive'); set(handles.edit19,'BackgroundColor',[1 1 0.8]); set(handles.edit20,'String',num2str(Fgr)); set(handles.edit20,'Enable','inactive'); set(handles.edit20,'BackgroundColor',[1 1 0.8]); % Acompanhamento set(handles.edit21,'Enable','on'); set(handles.edit23,'Enable','on'); set(handles.pushbutton11,'Enable','on'); set(handles.pushbutton11,'ForegroundColor',0*[1 1 1]); set(handles.pushbutton12,'Enable','on'); set(handles.pushbutton12,'ForegroundColor',0*[1 1 1]); % Update handles structure guidata(hObject, handles); function edit11_Callback(hObject, eventdata, handles) % hObject handle to edit11 (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 edit11 as text % str2double(get(hObject,'String')) returns contents of edit11 as a double % Lê o campo w w = str2double(get(hObject,'String')); if isnan(w), w = 0; elseif w<0, w = 0; elseif w>50, w = 50; end set(hObject,'String',num2str(w)); % Calcula o tempo de coleta if w>0, T = 2*pi/w; if T > 30, NT = 1; DT = 3; elseif T > 10 NT = 2; DT = T; elseif T > 3, NT = 4; DT = T*ceil(3/T); else NT = 10; DT = T*ceil(3/T); end tsim = NT*T + DT; else T = NaN; NT = NaN; DT = NaN; tsim = NaN; end % Dados que não queremos aqui wcand = NaN; Gcand = NaN; Fcand = NaN; % Atualiza dados handles.w = w; handles.T = T; handles.NT = NT; handles.DT = DT; handles.tsim = tsim; handles.wcand = wcand; handles.Gcand = Gcand; handles.Fcand = Fcand; % Recupera dados necessários Ai = handles.Ai; Gdata = handles.Gdata; Fdata = handles.Fdata; wdata = handles.wdata; Gref = handles.Gref; Fref = handles.Fref; Wref = handles.Wref; isel = handles.isel; % ajusta os controles % 1. entrada % atualiza mensagem u(t) if (Ai>0 && w>0) ustr = sprintf('u(t) = %0.2f*sen(%0.2f*t)',Ai,w); elseif Ai>0 ustr = sprintf('u(t) = %0.2f*sen(w*t)',Ai); elseif w>0 ustr = sprintf('u(t) = %Ai*sen(%0.2f*t)',w); else ustr = sprintf('u(t) = Ai*sen(w*t)'); end set(handles.text29,'string',ustr); % 2. coletar dados if (handles.w>0 && handles.Ai>0) set(handles.pushbutton6,'Enable','on'); set(handles.pushbutton6,'ForegroundColor',0*[1 1 1]); % atualiza mensagem tsim tstr = sprintf('%0.0f s',handles.tsim); set(handles.text40,'string',tstr); else set(handles.pushbutton6,'Enable','off'); set(handles.pushbutton6,'ForegroundColor',0.5*[1 1 1]); % atualiza mensagem tsim set(handles.text40,'string','(a calcular)'); end % 3. aceitar (desabilitar) set(handles.pushbutton9,'Enable','off'); set(handles.pushbutton9,'ForegroundColor',0.5*[1 1 1]); set(handles.text56,'String','y(t) = A*sen(w*t+phi)'); handles.GdB = NaN; set(handles.edit19,'String',''); set(handles.edit19,'Enable','off'); handles.Fgr = NaN; set(handles.edit20,'String',''); set(handles.edit20,'Enable','off'); % Eixo simulação (desabilitar) cla(handles.axes5);set(handles.axes5,'Visible','off'); set(handles.text66,'Visible','off'); % Eixo acompanhamento set(handles.axes3,'FontSize',6); hh=semilogx(handles.axes3,Wref,Gref,'-',wdata,Gdata,'ko',wdata(isel),Gdata(isel),'ko',[w w],get(handles.axes3,'Ylim'),'g-'); set(hh(1),'Color',0.7*[1 1 1],'LineWidth',2); set(hh(2),'MarkerSize',4,'MarkerFaceColor',0*[1 1 1]); set(hh(3),'MarkerSize',8,'Color',0*[1 1 1]); set(hh(4),'Color',0.5*[0 1 0],'LineWidth',1.5); set(handles.axes6,'FontSize',6); hh=semilogx(handles.axes6,Wref,Fref,'-',wdata,Fdata,'ko',wdata(isel),Fdata(isel),'ko',[w w],get(handles.axes6,'Ylim'),'g-'); set(hh(1),'Color',0.7*[1 1 1],'LineWidth',2); set(hh(2),'MarkerSize',4,'MarkerFaceColor',0*[1 1 1]); set(hh(3),'MarkerSize',8,'Color',0*[1 1 1]); set(hh(4),'Color',0.5*[0 1 0],'LineWidth',1.5); % Update handles structure guidata(hObject, handles); % --- Executes during object creation, after setting all properties. function edit11_CreateFcn(hObject, eventdata, handles) % hObject handle to edit11 (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 handles.w = NaN; % Update handles structure guidata(hObject, handles); function edit12_Callback(hObject, eventdata, handles) % hObject handle to edit12 (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 edit12 as text % str2double(get(hObject,'String')) returns contents of edit12 as a double Ai = str2double(get(hObject,'String')); if isnan(Ai), Ai = 0; elseif Ai<0, Ai = 0; elseif Ai>5, Ai = 5; end set(hObject,'String',num2str(Ai)); % Atualiza dados handles.Ai = Ai; % Recupera dados necessários w = handles.w; Gdata = handles.Gdata; Fdata = handles.Fdata; wdata = handles.wdata; Gref = handles.Gref; Fref = handles.Fref; Wref = handles.Wref; isel = handles.isel; % Dados que não queremos aqui wcand = NaN; Gcand = NaN; Fcand = NaN; handles.wcand = wcand; handles.Gcand = Gcand; handles.Fcand = Fcand; % ajusta os controles % 1. entrada % atualiza mensagem u(t) if Ai>0 && w>0 ustr = sprintf('u(t) = %0.2f*sen(%0.2f*t)',Ai,w); elseif Ai>0 ustr = sprintf('u(t) = %0.2f*sen(w*t)',Ai); elseif w>0 ustr = sprintf('u(t) = %Ai*sen(%0.2f*t)',w); else ustr = sprintf('u(t) = Ai*sen(w*t)'); end set(handles.text29,'string',ustr); % 2. coletar dados if (handles.w>0 && handles.Ai>0) set(handles.pushbutton6,'Enable','on'); set(handles.pushbutton6,'ForegroundColor',0*[1 1 1]); % atualiza mensagem tsim tstr = sprintf('%0.0f s',handles.tsim); set(handles.text40,'string',tstr); else set(handles.pushbutton6,'Enable','off'); set(handles.pushbutton6,'ForegroundColor',0.5*[1 1 1]); % atualiza mensagem tsim set(handles.text40,'string','(a calcular)'); end % 3. aceitar (desabilitar) set(handles.pushbutton9,'Enable','off'); set(handles.pushbutton9,'ForegroundColor',0.5*[1 1 1]); set(handles.text56,'String','y(t) = A*sen(w*t+phi)'); handles.GdB = NaN; set(handles.edit19,'String',''); set(handles.edit19,'Enable','off'); handles.Fgr = NaN; set(handles.edit20,'String',''); set(handles.edit20,'Enable','off'); % Eixo simulação (desabilitar) cla(handles.axes5);set(handles.axes5,'Visible','off'); set(handles.text66,'Visible','off'); % Eixo acompanhamento set(handles.axes3,'FontSize',6); hh=semilogx(handles.axes3,Wref,Gref,'-',wdata,Gdata,'ko',wdata(isel),Gdata(isel),'ko',[w w],get(handles.axes3,'Ylim'),'g-'); set(hh(1),'Color',0.7*[1 1 1],'LineWidth',2); set(hh(2),'MarkerSize',4,'MarkerFaceColor',0*[1 1 1]); set(hh(3),'MarkerSize',8,'Color',0*[1 1 1]); set(hh(4),'Color',0.5*[0 1 0],'LineWidth',1.5); set(handles.axes6,'FontSize',6); hh=semilogx(handles.axes6,Wref,Fref,'-',wdata,Fdata,'ko',wdata(isel),Fdata(isel),'ko',[w w],get(handles.axes6,'Ylim'),'g-'); set(hh(1),'Color',0.7*[1 1 1],'LineWidth',2); set(hh(2),'MarkerSize',4,'MarkerFaceColor',0*[1 1 1]); set(hh(3),'MarkerSize',8,'Color',0*[1 1 1]); set(hh(4),'Color',0.5*[0 1 0],'LineWidth',1.5); % Update handles structure guidata(hObject, handles); % --- Executes during object creation, after setting all properties. function edit12_CreateFcn(hObject, eventdata, handles) % hObject handle to edit12 (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 handles.Ai = str2double(get(hObject,'String')); % Update handles structure guidata(hObject, handles); function edit17_Callback(hObject, eventdata, handles) % hObject handle to edit17 (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 edit17 as text % str2double(get(hObject,'String')) returns contents of edit17 as a double % Lê o campo Ao Aoest = str2double(get(hObject,'String')); if isnan(Aoest), Aoest = 0; elseif Aoest<0, Aoest = 0; elseif Aoest>10, Aoest = 10; end set(hObject,'String',num2str(Aoest)); handles.Aoest = Aoest; irps = handles.irps; itrans = handles.itrans; tdata = handles.tdata; udata = handles.udata; ydata = handles.ydata; w = handles.w; phiest = handles.phiest; yest = Aoest*sin(w*tdata(irps)+phiest*pi/180); % Atualizar o gráfico de simulação com a estimativa set(handles.axes5,'Visible','on'); set(handles.text66,'Visible','off'); set(handles.axes5,'FontSize',8); h = plot(handles.axes5,tdata(itrans),ydata(itrans),'k-',tdata(irps),ydata(irps),'r-',tdata,udata,'k-',tdata(irps),yest,'r-'); set(h(1),'Color',0.7*[1 1 1],'LineWidth',1.5); set(h(2),'Color',0.5*[0 1 0],'LineWidth',1.5); set(h(4),'Color',1*[1 0 0],'LineWidth',1.5); xlabel(handles.axes5,'t (s)'); ylabel(handles.axes5,'u(t), y(t) (V)'); set(handles.axes5,'Xlim',[tdata(1) tdata(end)]); % Atualizar os controles % 1. entrada set(handles.edit11,'Enable','off'); set(handles.edit12,'Enable','off'); % 2. coletar set(handles.pushbutton6,'Enable','on'); set(handles.pushbutton6,'ForegroundColor',0*[1 1 1]); % 3. ajustar % 4. aceitar set(handles.pushbutton9,'Enable','off'); set(handles.pushbutton9,'ForegroundColor',0.5*[1 1 1]); set(handles.text56,'String','y(t) = A*sen(w*t+phi)'); handles.GdB = NaN; set(handles.edit19,'String',''); handles.Fgr = NaN; set(handles.edit20,'String',''); % 4. reiniciar set(handles.pushbutton10,'Enable','off'); set(handles.pushbutton10,'ForegroundColor',0.5*[1 1 1]); % Eixo simulação set(handles.axes5,'Visible','on'); set(handles.text66,'Visible','off'); % Acompanhamento set(handles.edit21,'Enable','on'); set(handles.edit23,'Enable','on'); set(handles.pushbutton11,'Enable','on'); set(handles.pushbutton11,'ForegroundColor',0*[1 1 1]); set(handles.pushbutton12,'Enable','on'); set(handles.pushbutton12,'ForegroundColor',0*[1 1 1]); % Update handles structure guidata(hObject, handles); % --- Executes during object creation, after setting all properties. function edit17_CreateFcn(hObject, eventdata, handles) % hObject handle to edit17 (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 pushbutton11. function pushbutton11_Callback(hObject, eventdata, handles) % hObject handle to pushbutton11 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Pega os dados Gcand = handles.Gcand; Fcand = handles.Fcand; wcand = handles.wcand; Gdata = handles.Gdata; Fdata = handles.Fdata; wdata = handles.wdata; Gref = handles.Gref; Fref = handles.Fref; Wref = handles.Wref; isel = handles.isel; w = handles.w; if isel>1 isel = isel-1; else isel = length(wdata); end handles.isel = isel; % Eixo acompanhamento set(handles.axes3,'FontSize',6); hh=semilogx(handles.axes3,Wref,Gref,'-',wdata,Gdata,'ko',wdata(isel),Gdata(isel),'ko',wcand,Gcand,'ro',[w w],get(handles.axes3,'Ylim'),'g-'); set(hh(1),'Color',0.7*[1 1 1],'LineWidth',2); set(hh(2),'MarkerSize',4,'MarkerFaceColor',0*[1 1 1]); set(hh(3),'MarkerSize',8,'Color',0*[1 1 1]); set(hh(4),'MarkerSize',8,'MarkerFaceColor',[1 0 0]); set(hh(5),'Color',0.5*[0 1 0],'LineWidth',1.5); set(handles.axes6,'FontSize',6); hh=semilogx(handles.axes6,Wref,Fref,'-',wdata,Fdata,'ko',wdata(isel),Fdata(isel),'ro',wcand,Fcand,'ro',[w w],get(handles.axes6,'Ylim'),'g-'); set(hh(1),'Color',0.7*[1 1 1],'LineWidth',2); set(hh(2),'MarkerSize',4,'MarkerFaceColor',0*[1 1 1]); set(hh(3),'MarkerSize',8,'Color',0*[1 1 1]); set(hh(4),'MarkerSize',8,'MarkerFaceColor',[1 0 0]); set(hh(5),'Color',0.5*[0 1 0],'LineWidth',1.5); % display do ponto selecionado if isnan(wdata(isel)) set(handles.text69,'String','(G)'); set(handles.text70,'String','(F)'); else gstr = sprintf('(%0.2f)',Gdata(isel)); set(handles.text69,'String',gstr); fstr = sprintf('(%0.0f)',Fdata(isel)); set(handles.text70,'String',fstr); end % Update handles structure guidata(hObject, handles); % --- Executes on button press in pushbutton12. function pushbutton12_Callback(hObject, eventdata, handles) % hObject handle to pushbutton12 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Pega os dados Gcand = handles.Gcand; Fcand = handles.Fcand; wcand = handles.wcand; Gdata = handles.Gdata; Fdata = handles.Fdata; wdata = handles.wdata; Gref = handles.Gref; Fref = handles.Fref; Wref = handles.Wref; isel = handles.isel; w = handles.w; % Elimina o ponto selecionado (sem dó nem confirmação) if length(wdata)==1 Gdata = NaN; Fdata = NaN; wdata = NaN; else Gdata(isel)=[]; Fdata(isel)=[]; wdata(isel)=[]; end isel = length(wdata); % salva o arquivo (é o único ponto vulnerável para a segurança do arquivo) save('./respfreq_data.mat','wdata','Gdata','Fdata'); % copia também para o workspace do Matlab assignin('base', 'wdata', wdata); assignin('base', 'Gdata', Gdata); assignin('base', 'Fdata', Fdata); handles.isel = isel; handles.Gdata = Gdata; handles.Fdata = Fdata; handles.wdata = wdata; % Eixo acompanhamento set(handles.axes3,'FontSize',6); hh=semilogx(handles.axes3,Wref,Gref,'-',wdata,Gdata,'ko',wdata(isel),Gdata(isel),'ko',wcand,Gcand,'ro',[w w],get(handles.axes3,'Ylim'),'g-'); set(hh(1),'Color',0.7*[1 1 1],'LineWidth',2); set(hh(2),'MarkerSize',4,'MarkerFaceColor',0*[1 1 1]); set(hh(3),'MarkerSize',8,'Color',0*[1 1 1]); set(hh(4),'MarkerSize',8,'MarkerFaceColor',[1 0 0]); set(hh(5),'Color',0.5*[0 1 0],'LineWidth',1.5); set(handles.axes6,'FontSize',6); hh=semilogx(handles.axes6,Wref,Fref,'-',wdata,Fdata,'ko',wdata(isel),Fdata(isel),'ro',wcand,Fcand,'ro',[w w],get(handles.axes6,'Ylim'),'g-'); set(hh(1),'Color',0.7*[1 1 1],'LineWidth',2); set(hh(2),'MarkerSize',4,'MarkerFaceColor',0*[1 1 1]); set(hh(3),'MarkerSize',8,'Color',0*[1 1 1]); set(hh(4),'MarkerSize',8,'MarkerFaceColor',[1 0 0]); set(hh(5),'Color',0.5*[0 1 0],'LineWidth',1.5); % display do ponto selecionado if isnan(wdata(isel)) set(handles.text69,'String','(G)'); set(handles.text70,'String','(F)'); else gstr = sprintf('(%0.2f)',Gdata(isel)); set(handles.text69,'String',gstr); fstr = sprintf('(%0.0f)',Fdata(isel)); set(handles.text70,'String',fstr); end % Update handles structure guidata(hObject, handles); function edit20_Callback(hObject, eventdata, handles) % hObject handle to edit20 (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 edit20 as text % str2double(get(hObject,'String')) returns contents of edit20 as a double % --- Executes during object creation, after setting all properties. function edit20_CreateFcn(hObject, eventdata, handles) % hObject handle to edit20 (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 function edit19_Callback(hObject, eventdata, handles) % hObject handle to edit19 (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 edit19 as text % str2double(get(hObject,'String')) returns contents of edit19 as a double % --- Executes during object creation, after setting all properties. function edit19_CreateFcn(hObject, eventdata, handles) % hObject handle to edit19 (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 pushbutton9. function pushbutton9_Callback(hObject, eventdata, handles) % hObject handle to pushbutton9 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) Gcand = handles.Gcand; Fcand = handles.Fcand; wcand = handles.wcand; Gdata = handles.Gdata; Fdata = handles.Fdata; wdata = handles.wdata; Gref = handles.Gref; Fref = handles.Fref; Wref = handles.Wref; isel = handles.isel; Ai = handles.Ai; w = handles.w; if isnan(wdata) Gdata = [Gcand]; Fdata = [Fcand]; wdata = [wcand]; else Gdata = [Gdata ; Gcand]; Fdata = [Fdata ; Fcand]; wdata = [wdata ; wcand]; end % ordena o vetor em w [wdata,iw]=sort(wdata); Gdata = Gdata(iw); Fdata = Fdata(iw); % o ponto aceito é selecionado [m,im]=max(iw); isel = im; % salva o arquivo (é o único ponto vulnerável para a segurança do arquivo) save('./respfreq_data.mat','wdata','Gdata','Fdata'); assignin('base', 'wdata', wdata); assignin('base', 'Gdata', Gdata); assignin('base', 'Fdata', Fdata); % atualiza mensagem u(t) if (Ai>0 && w>0) ustr = sprintf('u(t) = %0.2f*sen(%0.2f*t)',Ai,w); elseif Ai>0 ustr = sprintf('u(t) = %0.2f*sen(w*t)',Ai); elseif w>0 ustr = sprintf('u(t) = %Ai*sen(%0.2f*t)',w); else ustr = sprintf('u(t) = Ai*sen(w*t)'); end % cancela os valores temporários wcand = NaN; Gcand = NaN; Fcand = NaN; w = NaN; % Armazena os dados handles.wcand = wcand; handles.Gcand = Gcand; handles.Fcand = Fcand; handles.wdata = wdata; handles.Gdata = Gdata; handles.Fdata = Fdata; handles.isel = isel; handles.w = w; % ajusta os controles % 1. entrada set(handles.text29,'string',ustr); set(handles.edit11,'String',''); % 2. coletar dados if (handles.w>0 && handles.Ai>0) set(handles.pushbutton6,'Enable','on'); set(handles.pushbutton6,'ForegroundColor',0*[1 1 1]); % atualiza mensagem tsim tstr = sprintf('%0.0f s',handles.tsim); set(handles.text40,'string',tstr); else set(handles.pushbutton6,'Enable','off'); set(handles.pushbutton6,'ForegroundColor',0.5*[1 1 1]); % atualiza mensagem tsim set(handles.text40,'string','(a calcular)'); end % 3. aceitar (desabilitar) set(handles.pushbutton9,'Enable','off'); set(handles.pushbutton9,'ForegroundColor',0.5*[1 1 1]); set(handles.text56,'String','y(t) = A*sen(w*t+phi)'); set(handles.edit19,'String',''); set(handles.edit19,'Enable','off'); set(handles.edit20,'String',''); set(handles.edit20,'Enable','off'); % Eixo simulação (desabilitar) cla(handles.axes5);set(handles.axes5,'Visible','off'); set(handles.text66,'Visible','off'); % Eixo acompanhamento set(handles.axes3,'FontSize',6); hh=semilogx(handles.axes3,Wref,Gref,'-',wdata,Gdata,'ko',wdata(isel),Gdata(isel),'ko',wcand,Gcand,'ro'); set(hh(1),'Color',0.7*[1 1 1],'LineWidth',2); set(hh(2),'MarkerSize',4,'MarkerFaceColor',0*[1 1 1]); set(hh(3),'MarkerSize',8,'Color',0*[1 1 1]); set(hh(4),'MarkerSize',8,'MarkerFaceColor',[1 0 0]); set(handles.axes6,'FontSize',6); hh=semilogx(handles.axes6,Wref,Fref,'-',wdata,Fdata,'ko',wdata(isel),Fdata(isel),'ro',wcand,Fcand,'ro'); set(hh(1),'Color',0.7*[1 1 1],'LineWidth',2); set(hh(2),'MarkerSize',4,'MarkerFaceColor',0*[1 1 1]); set(hh(3),'MarkerSize',8,'Color',0*[1 1 1]); set(hh(4),'MarkerSize',8,'MarkerFaceColor',[1 0 0]); % display do ponto selecionado if isnan(wdata(isel)) set(handles.text69,'String','(G)'); set(handles.text70,'String','(F)'); else gstr = sprintf('(%0.2f)',Gdata(isel)); set(handles.text69,'String',gstr); fstr = sprintf('(%0.0f)',Fdata(isel)); set(handles.text70,'String',fstr); end % Update handles structure guidata(hObject, handles); % --- Executes on button press in pushbutton10. function pushbutton10_Callback(hObject, eventdata, handles) % hObject handle to pushbutton10 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) function edit21_Callback(hObject, eventdata, handles) % hObject handle to edit21 (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 edit21 as text % str2double(get(hObject,'String')) returns contents of edit21 as a double KKtref = str2double(get(hObject,'String')); if isnan(KKtref), KKtref = 0.1; elseif KKtref<0, KKtref = 0.1; elseif KKtref>10, KKtref = 10; end set(hObject,'String',num2str(KKtref)); % Pega os dados Gcand = handles.Gcand; Fcand = handles.Fcand; wcand = handles.wcand; Gdata = handles.Gdata; Fdata = handles.Fdata; wdata = handles.wdata; Gref = handles.Gref; Fref = handles.Fref; Wref = handles.Wref; isel = handles.isel; w = handles.w; Tref = handles.Tref; % Diagrama de Bode [Gref,Fref,Wref]=bode(tf(KKtref,[Tref 1])); Gref = squeeze(Gref); Fref = squeeze(Fref); Gref = 20*log10(Gref); handles.KKtref = KKtref; handles.Gref = Gref; handles.Fref = Fref; handles.Wref = Wref; % Eixo acompanhamento set(handles.axes3,'FontSize',6); hh=semilogx(handles.axes3,Wref,Gref,'-',wdata,Gdata,'ko',wdata(isel),Gdata(isel),'ko',wcand,Gcand,'ro',[w w],get(handles.axes3,'Ylim'),'g-'); set(hh(1),'Color',0.7*[1 1 1],'LineWidth',2); set(hh(2),'MarkerSize',4,'MarkerFaceColor',0*[1 1 1]); set(hh(3),'MarkerSize',8,'Color',0*[1 1 1]); set(hh(4),'MarkerSize',8,'MarkerFaceColor',[1 0 0]); set(hh(5),'Color',0.5*[0 1 0],'LineWidth',1.5); set(handles.axes6,'FontSize',6); hh=semilogx(handles.axes6,Wref,Fref,'-',wdata,Fdata,'ko',wdata(isel),Fdata(isel),'ro',wcand,Fcand,'ro',[w w],get(handles.axes6,'Ylim'),'g-'); set(hh(1),'Color',0.7*[1 1 1],'LineWidth',2); set(hh(2),'MarkerSize',4,'MarkerFaceColor',0*[1 1 1]); set(hh(3),'MarkerSize',8,'Color',0*[1 1 1]); set(hh(4),'MarkerSize',8,'MarkerFaceColor',[1 0 0]); set(hh(5),'Color',0.5*[0 1 0],'LineWidth',1.5); % display do ponto selecionado if isnan(wdata(isel)) set(handles.text69,'String','(G)'); set(handles.text70,'String','(F)'); else gstr = sprintf('(%0.2f)',Gdata(isel)); set(handles.text69,'String',gstr); fstr = sprintf('(%0.0f)',Fdata(isel)); set(handles.text70,'String',fstr); end % Update handles structure guidata(hObject, handles); % --- Executes during object creation, after setting all properties. function edit21_CreateFcn(hObject, eventdata, handles) % hObject handle to edit21 (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 handles.KKtref = str2double(get(hObject,'String')); % Update handles structure guidata(hObject, handles); function edit23_Callback(hObject, eventdata, handles) % hObject handle to edit23 (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 edit23 as text % str2double(get(hObject,'String')) returns contents of edit23 as a double Tref = str2double(get(hObject,'String')); if isnan(Tref), Tref = 0.1; elseif Tref<0, Tref = 0.1; elseif Tref>1, Tref = 1; end set(hObject,'String',num2str(Tref)); % Pega os dados Gcand = handles.Gcand; Fcand = handles.Fcand; wcand = handles.wcand; Gdata = handles.Gdata; Fdata = handles.Fdata; wdata = handles.wdata; Gref = handles.Gref; Fref = handles.Fref; Wref = handles.Wref; isel = handles.isel; w = handles.w; KKtref = handles.KKtref; % Diagrama de Bode [Gref,Fref,Wref]=bode(tf(KKtref,[Tref 1])); Gref = squeeze(Gref); Fref = squeeze(Fref); Gref = 20*log10(Gref); handles.Tref = Tref; handles.Gref = Gref; handles.Fref = Fref; handles.Wref = Wref; % Eixo acompanhamento set(handles.axes3,'FontSize',6); hh=semilogx(handles.axes3,Wref,Gref,'-',wdata,Gdata,'ko',wdata(isel),Gdata(isel),'ko',wcand,Gcand,'ro',[w w],get(handles.axes3,'Ylim'),'g-'); set(hh(1),'Color',0.7*[1 1 1],'LineWidth',2); set(hh(2),'MarkerSize',4,'MarkerFaceColor',0*[1 1 1]); set(hh(3),'MarkerSize',8,'Color',0*[1 1 1]); set(hh(4),'MarkerSize',8,'MarkerFaceColor',[1 0 0]); set(hh(5),'Color',0.5*[0 1 0],'LineWidth',1.5); set(handles.axes6,'FontSize',6); hh=semilogx(handles.axes6,Wref,Fref,'-',wdata,Fdata,'ko',wdata(isel),Fdata(isel),'ro',wcand,Fcand,'ro',[w w],get(handles.axes6,'Ylim'),'g-'); set(hh(1),'Color',0.7*[1 1 1],'LineWidth',2); set(hh(2),'MarkerSize',4,'MarkerFaceColor',0*[1 1 1]); set(hh(3),'MarkerSize',8,'Color',0*[1 1 1]); set(hh(4),'MarkerSize',8,'MarkerFaceColor',[1 0 0]); set(hh(5),'Color',0.5*[0 1 0],'LineWidth',1.5); % display do ponto selecionado if isnan(wdata(isel)) set(handles.text69,'String','(G)'); set(handles.text70,'String','(F)'); else gstr = sprintf('(%0.2f)',Gdata(isel)); set(handles.text69,'String',gstr); fstr = sprintf('(%0.0f)',Fdata(isel)); set(handles.text70,'String',fstr); end % Update handles structure guidata(hObject, handles); % --- Executes during object creation, after setting all properties. function edit23_CreateFcn(hObject, eventdata, handles) % hObject handle to edit23 (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 handles.Tref = str2double(get(hObject,'String')); % Update handles structure guidata(hObject, handles); % --- Executes during object creation, after setting all properties. function text29_CreateFcn(hObject, eventdata, handles) % hObject handle to text29 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called