您好,欢迎来到独旅网。
搜索
您的当前位置:首页基于matlab的电路仿真-例子

基于matlab的电路仿真-例子

来源:独旅网
基于matlab的电路仿真 2007-10-23 10:03

关键词: RC电路仿真, matlab, GUI设计

出处: 萝卜驿站

% 基于matlab的电路仿真 % 萝卜驿站

close all;clear;clc;

figure('position',[1 714 485]);

Na=['输入波形[请选择]|输入波形:正弦波|',... '输入波形:方形波|输入波形:脉冲波']; Ns={'sin','square','pulse'};

R=2; % default parameters: resistance C=2; % default parameters: capacitance f=10; % default parameters: frequency TAU=R*C;;

tff=10; % length of time ts=1/f; % sampling length

sys1=tf([1],[1,1]); % systems for integral circuit sys2=tf([1,0],[1,1]); % systems for differential circuit

a1=axes('position',[0.1,0.6,0.3,0.3]); po1=uicontrol(gcf,'style','popupmenu',...

'unit','normalized','position',[0.15,0.9,0.2,0.08],... 'string',Na,'fontsize',12,'callback',[]);

set(po1,'callback',['KK=get(po1,''Value'');if KK>1;',...

'st=char(Ns(KK-1));[U,T]=gensig(st,R*C,tff,1/f);',... 'axes(a1);plot(T,U);ylim([min(U)-0.5,max(U)+0.5]);',... 'end;']);

Ma=['电路类型[请选择]|电路类型:积分型|电路类型:微分型']; a2=axes('position',[0.5,0.6,0.3,0.3]);box on; set(gca,'xtick',[]);set(gca,'ytick',[]); po2=uicontrol(gcf,'style','popupmenu',...

'unit','normalized','position',[0.55,0.9,0.2,0.08],... 'string',Ma,'fontsize',12,'callback',[]);

set(po2,'callback',['KQ=get(po2,''Value'');axes(a2);',... 'if KQ==1;cla;elseif KQ==2;',...

'plot(0.14+0.8i+0.02*exp(i*[0:.02:8]),''k'');hold on;',... 'plot(0.14+0.2i+0.02*exp(i*[0:.02:8]),''k'');',... 'plot(0.84+0.2i+0.02*exp(i*[0:.02:8]),''k'');',... 'plot(0.84+0.8i+0.02*exp(i*[0:.02:8]),''k'');',...

'plot([0.16,0.82],[0.2,0.2],''k'');',... 'plot([0.16,0.3],[0.8,0.8],''k'');',...

'plot([3,4,4,3,3]/10,[76,76,84,84,76]/100,''k'');',... 'plot([0.4,0.82],[0.8,0.8],''k'');',... 'plot([0.6,0.6],[0.8,0.53],''k'');',... 'plot([0.6,0.6],[0.2,0.48],''k'');',... 'plot([0.55,0.65],[0.53,0.53],''k'');',... 'plot([0.55,0.65],[0.48,0.48],''k'');',... 'text(0.33,0.7,''R'');',... 'text(0.63,0.42,''C'');',...

'text(0.8,0.5,''U_o'');text(0.1,0.5,''U_i'');hold off;',... 'set(gca,''xtick'',[]);set(gca,''ytick'',[]);',... 'else;',...

'plot(0.14+0.8i+0.02*exp(i*[0:.02:8]),''k'');hold on;',... 'plot(0.14+0.2i+0.02*exp(i*[0:.02:8]),''k'');',... 'plot(0.84+0.2i+0.02*exp(i*[0:.02:8]),''k'');',... 'plot(0.84+0.8i+0.02*exp(i*[0:.02:8]),''k'');',... 'plot([0.16,0.82],[0.2,0.2],''k'');',... 'plot([0.16,0.33],[0.8,0.8],''k'');',... 'plot([0.33,0.33],[0.74,0.86],''k'');',... 'plot([0.36,0.36],[0.74,0.86],''k'');',... 'plot([0.36,0.82],[0.8,0.8],''k'');',... 'plot([0.6,0.6],[0.8,0.58],''k'');',... 'plot([0.6,0.6],[0.2,0.42],''k'');',...

'plot([58,62,62,58,58]/100,[42,42,58,58,42]/100,''k'');',... 'text(0.33,0.68,''C'');',... 'text(0.63,0.42,''R'');',...

'text(0.8,0.5,''U_o'');text(0.1,0.5,''U_i'');hold off;',... 'set(gca,''xtick'',[]);set(gca,''ytick'',[]);',... 'end;axis([0,1,0,1]);']);

a3=axes('position',[0.1,0.1,0.3,0.3]); pu3=uicontrol(gcf,'style','push',...

'unit','normalized','position',[0.15,0.43,0.2,0.04],... 'string','显示输出波形','fontsize',12,...

'callback',['axes(a3);if KQ==2;lsim(sys1,U,T);',... 'elseif KQ==3;lsim(sys2,U,T);else,cla;end;']); uicontrol(gcf,'style','frame',...

'unit','normalized','position',[0.47,0.13,0.5,0.32],... 'string','10','BackgroundColor',[0.8,0.8,0.8],... 'fontsize',16,'fontname','times new roman'); s1=uicontrol(gcf,'style','slider',...

'unit','normalized','position',[0.55,0.38,0.3,0.03],... 'Value',0.5,'SliderStep',[0.01 0.01],... 'callback',['R=1+get(s1,''Value'')*2;',... '[U,T]=gensig(st,R*C,tff,1/f);',... 'set(t1,''string'',num2str(R));']);

uicontrol(gcf,'style','text',...

'unit','normalized','position',[0.5,0.37,0.05,0.05],... 'string','R','BackgroundColor',[0.8,0.8,0.8],... 'fontsize',16,'fontname','times new roman'); t1=uicontrol(gcf,'style','text',...

'unit','normalized','position',[0.86,0.37,0.1,0.05],... 'string','2','BackgroundColor',[0.8,0.8,0.8],... 'fontsize',16,'fontname','times new roman');

s2=uicontrol(gcf,'style','slider',...

'unit','normalized','position',[0.55,0.28,0.3,0.03],... 'Value',0.5,'SliderStep',[0.01 0.01],... 'callback',['C=1+get(s2,''Value'')*2;',... '[U,T]=gensig(st,R*C,tff,1/f);',... 'set(t2,''string'',num2str(C));']); uicontrol(gcf,'style','text',...

'unit','normalized','position',[0.5,0.27,0.05,0.05],... 'string','C','BackgroundColor',[0.8,0.8,0.8],... 'fontsize',16,'fontname','times new roman'); t2=uicontrol(gcf,'style','text',...

'unit','normalized','position',[0.86,0.27,0.1,0.05],... 'string','2','BackgroundColor',[0.8,0.8,0.8],... 'fontsize',16,'fontname','times new roman'); set(gcf,'NumberTitle','off','MenuBar','none'); set(gcf,'name','基于matlab的电路仿真'); uu=uimenu(gcf,'label','About'); uimenu(uu,'label','Author:Zjliu'); ku=uimenu(gcf,'label','Readme'); kw1=uimenu(gcf,'label','执行顺序:');

kw2=uimenu(gcf,'label','设定参数-->确定波形-->选择电路类型-->输出波形');

set(kw1,'ForegroundColor','r');set(kw2,'ForegroundColor','b'); uicontrol(gcf,'style','text',...

'unit','normalized','position',[0.5,0.47,0.46,0.05],... 'string','请选择波形之前改变下面的参数',... 'BackgroundColor',[0.8,0.8,0.8],...

'fontsize',16,'fontname','times new roman'); % readme

s3=uicontrol(gcf,'style','slider',...

'unit','normalized','position',[0.55,0.18,0.3,0.03],... 'Value',0.5,'SliderStep',[0.01 0.01],... 'callback',['f=5+get(s3,''Value'')*10;',... '[U,T]=gensig(st,R*C,tff,1/f);',... 'set(t3,''string'',num2str(f));']); uicontrol(gcf,'style','text',...

'unit','normalized','position',[0.5,0.17,0.05,0.05],... 'string','f','BackgroundColor',[0.8,0.8,0.8],... 'fontsize',16,'fontname','times new roman'); t3=uicontrol(gcf,'style','text',...

'unit','normalized','position',[0.86,0.17,0.1,0.05],... 'string','10','BackgroundColor',[0.8,0.8,0.8],... 'fontsize',16,'fontname','times new roman');

http://hi.baidu.com/nailson/blog/item/d1f20a6c76ce3db0351d4f.html

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- dcrkj.com 版权所有 赣ICP备2024042791号-2

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务