资源描述:
《Matlab建模实例》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、第8章MATLAB/SIMULINK建模实例比较器半加器全加器建模实例上海理工陈国平比较器0.25ConstantIn1Out1In2SineWaveSubsystemScope11In1Constant12Out10In2AddSwitchConstant1上海理工陈国平比较器0.25ConstantMATLABFunctionMATLABFcnSineWaveScopefunctionsys=compfun1(u)ifu(2)=u(1)sys=1;end上海理工陈国平半加器A0011B0101PulseGeneratorS0
2、110ASC0001BCooPulsehafaddGenerator1Scope1PulseGenerator:XOR1APeriod,4,PhaseDelay,2LogicalSPulseGenerator1:Operator12Period,2,PhaseDelay,1BAND2CoLogicalOperator上海理工陈国平半加器A0011B0101S0110Co0001PulseGenerator:Period,4,PhaseDelay,2PulseGenerator1:Period,2,PhaseDelay,1上海理工陈国平半加器A0011PulseB0101G
3、eneratorhafaddsfunS0110S-FunctionPulseScopeCo0001Generator1PulseGenerator:Period,4,PhaseDelay,2PulseGenerator1:Period,2,PhaseDelay,1上海理工陈国平•S函数hafaddsfun.m•editsfuntmplsizes.NumOutputs=2;sizes.NumInputs=2;functionsys=mdlOutputs(t,x,u)ifu(1)==0&u(2)==0sys(1)=0;sys(2)=0;elseifu(1)==0&u(2)==
4、1sys(1)=1;sys(2)=0;elseifu(1)==1&u(2)==0sys(1)=1;sys(2)=0;elseifu(1)==1&u(2)==1sys(1)=0;sys(2)=1;end%sys=[];上海理工陈国平全加器A00110011B01010101CI00001111S01101001Co00010111SABCICABACBCOII上海理工陈国平全加器SABCIPulseCABACBCGeneratorOII1PulseXORAXOR1Generator1ASScopeLogicalBLogicalSCiCo2
5、Operator1SubsystemOperator2PulseBGenerator2ANDOR23LogicalCoCiOperatorLogicalOperator5ANDLogicalOperator3ANDLogicalOperator4上海理工陈国平全加器A00110011B01010101CI00001111S01101001Co00010111上海理工陈国平SIMULINK建模实例•并行转换(FLASH)结构模数转换器•分辨率N,需要2N-1个比较器上海理工陈国平2BitA/DA0001B0011C0111a0011b0101aABCABCBCbAB
6、CABC(AB)C上海理工陈国平1.5BitA/DA001B011a001b010aABbAB上海理工陈国平1.5Bit上海理工陈国平建模上海理工陈国平•新建子系统•触发子系统•MATLAB函数comparator1.mcomparator2.mfunctionsys=comparator1(u)functionsys=comparator2(u)dl=-1/4;dl=1/4;ifu=dlelseifu>=dlsys=1;sys=1;上海理工endend陈国平•S函数•editsfuntmplsubdac
7、.msizes.NumOutputs=1;sizes.NumInputs=2;functionsys=mdlOutputs(t,x,u)ifu(1)==0&u(2)==0sys=-1;elseifu(1)==1&u(2)==0sys=0;elseifu(1)==1&u(2)==1sys=1;end%sys=[];上海理工陈国平上海理工陈国平Vout2VinDnDn1VrefDnDn1Vref上海理工陈国平习题1•(1)使用MATLAB函数模块进行1位半加器的SIMULINK建模。•(2)使用S函数模块进行1位比较器的