基于matlab的码型转换

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

实验内容:利用Matlab软件的GUI界面编程,做一个简单的界面,通过此界面调用相关的程序去实现由抽样判决后的AMI码型、CMI码型和HDB3码型数字序列恢复出原始的PCM脉冲编码信号。实验目的:1,熟悉Matlab的GUI的编程操作,学会运用GUI来建立一个界面2.掌握AMI,CMI,HDB3码型的特点和意义,学会将PCM脉冲编码信号转化为AMI,CMI,HDB3的编码以及AMI,CMI,HDB3解码的方式。实验方法:实验中采用的方法是先建立大概的界面,其中包括输入框、按钮、提示内容及坐标系等。然后再对各种组件设置好属性,并对各个组件编写回调函数,最后进行调试验证饥渴。实验代码:1.AMI码型转换:%%%%%%%%%%%%编码%%%%%%%%%%%%%p=-1;fori=1:length(f);iff(i)==1e(i)=(-1)*p;p=e(i);elsee(i)=f(i);endend%%%%%%%%%%%%译码%%%%%%%%%%%%fori=1:length(f);ife(i)~=0l(i)=1;elsee(i)=0;endend编码:代码中的f代表着输入字符串转化后的ASCII码,用变量p来实现原信号中1的正负交替。例如,f(1)=1,则e(1)=1,p=1;f(2)=1,则e(2)=-1,p=-1。如此就可以得到正负1交替了。译码:当e(i)不等于0,就把结果等于1。2.CMI码型转换%%%%%%%%%%%%编码%%%%%%%%%%%%%m=1;p=-1;fori=1:length(f)if(f(i)==1&m==1)s(i)=3;m=m*p;elseif(f(i)==1&m==-1)s(i)=0;m=m*p;elses(i)=1;endendendk=dec2bin(s,2);l=k';x=l(:);y=x';n=str2num(y(1));fori=2:length(y)n=[nstr2num(y(i))];end%%%%%%%%%%%%译码%%%%%%%%%%%%%ifn(1)==0ifn(2)==1cm=[0];elsecm=[1];endelsecm=[1];endr=3;whilerlength(n)ifn(r)==0ifn(r+1)==1cm=[cm0];elsecm=[cm1];endelsecm=[cm1];endr=r+2;end3.HDB3码型转换%%%%%%%%%%%%编码%%%%%%%%%%%%%yn=xn;%输出yn初始化num=0;%计数器初始化fork=1:length(xn)ifxn(k)==1num=num+1;%1计数器ifnum/2==fix(num/2)%奇数个1时输出-1,进行极性交替yn(k)=1;elseyn(k)=-1;endendend%HDB3编码num=0;%连零计数器初始化yh=yn;%输出初始化sign=0;%极性标志初始化为0V=zeros(1,length(yn));%V脉冲位置记录变量B=zeros(1,length(yn));%B脉冲位置记录变量fork=1:length(yn)ifyn(k)==0num=num+1;%连“0”个数计数ifnum==4%如果4连“0”num=0;%计数器清零yh(k)=1*yh(k-4);%让0000的最后一个0改变为与前一个非零符号相同极性的符号V(k)=yh(k);%V脉冲位置记录ifyh(k)==sign%如果当前V符号与前一个V符号的极性相同yh(k)=-1*yh(k);%则让当前V符号极性反转,以满足V符号间相互极性反转要求yh(k-3)=yh(k);%添加B符号,与V符号同极性B(k-3)=yh(k);%B脉冲位置记录V(k)=yh(k);%V脉冲位置记录yh(k+1:length(yn))=-1*yh(k+1:length(yn));%并让后面的非零符号从V符号开始再交替变化endsign=yh(k);%记录前一个V符号的极性endelsenum=0;%当前输入为“1”则连“0”计数器清零endend%%%%%%%%%%%%译码%%%%%%%%%%%%%input=yh;%HDB3码输入decode=input;%输出初始化sign=0;%极性标志初始化fork=1:length(yh)ifinput(k)~=0ifsign==yh(k)%如果当前码与前一个非零码的极性相同decode(k-3:k)=[0000];%则该码判为V码并将*00V清零endsign=input(k);%极性标志endenddecode=abs(decode);%整流实验现象:总体界面:AMI:CMI:HDB3:总结:1.本次实验中因为对画方波不太熟悉,在使用stairs函数时,方波图总是在最后少了一位,后来经查询后才知道stairs的正确用法。2.由于对GUI界面设置的不熟悉,很多细节都没做到位,界面的美观有待提高。3.在编代码是经常没有写注释,导致后来有些变量混淆了。附录:全部代码functionvarargout=untitled1(varargin)%UNTITLED1M-fileforuntitled1.fig%UNTITLED1,byitself,createsanewUNTITLED1orraisestheexisting%singleton*.%%H=UNTITLED1returnsthehandletoanewUNTITLED1orthehandleto%theexistingsingleton*.%%UNTITLED1('CALLBACK',hObject,eventData,handles,...)callsthelocal%functionnamedCALLBACKinUNTITLED1.Mwiththegiveninputarguments.%%UNTITLED1('Property','Value',...)createsanewUNTITLED1orraisesthe%existingsingleton*.Startingfromtheleft,propertyvaluepairsare%appliedtotheGUIbeforeuntitled1_OpeningFunctiongetscalled.An%unrecognizedpropertynameorinvalidvaluemakespropertyapplication%stop.Allinputsarepassedtountitled1_OpeningFcnviavarargin.%%*SeeGUIOptionsonGUIDE'sToolsmenu.ChooseGUIallowsonlyone%instancetorun(singleton).%%Seealso:GUIDE,GUIDATA,GUIHANDLES%Edittheabovetexttomodifytheresponsetohelpuntitled1%LastModifiedbyGUIDEv2.521-Dec-201419:55:20%Begininitializationcode-DONOTEDITgui_Singleton=1;gui_State=struct('gui_Name',mfilename,...'gui_Singleton',gui_Singleton,...'gui_OpeningFcn',@untitled1_OpeningFcn,...'gui_OutputFcn',@untitled1_OutputFcn,...'gui_LayoutFcn',[],...'gui_Callback',[]);ifnargin&&ischar(varargin{1})gui_State.gui_Callback=str2func(varargin{1});endifnargout[varargout{1:nargout}]=gui_mainfcn(gui_State,varargin{:});elsegui_mainfcn(gui_State,varargin{:});end%Endinitializationcode-DONOTEDIT%---Executesjustbeforeuntitled1ismadevisible.functionuntitled1_OpeningFcn(hObject,eventdata,handles,varargin)%Thisfunctionhasnooutputargs,seeOutputFcn.%hObjecthandletofigure%eventdatareserved-tobedefinedinafutureversionofMATLAB%handlesstructurewithhandlesanduserdata(seeGUIDATA)%varargincommandlineargumentstountitled1(seeVARARGIN)%Choosedefaultcommandlineoutputforuntitled1handles.output=hObject;%Updatehandlesstructureguidata(hObject,handles);%UIWAITmakesuntitled1waitforuserresponse(seeUIRESUME)%uiwait(handles.maxing);%---Outputsfromthisfunctionarereturnedtothecommandline.functionvarargout=untitled1_OutputFcn(hObject,eventdata,handles)%varargoutcellarrayforreturningoutputargs(seeVARARGOUT);%hObjecthandletofigure%eventdatareserved-tobedefinedinafutureversionofMATLAB%handlesstructurewithhandlesanduserdata(seeGUIDATA)%Getdefaultcommandlineoutputfromhandlesstructurevarargout{1}=handles.output;functionedit_Callback(hObject,eventdata,handles)%hObjecthandletoedit(seeGCBO)%eventdatareserved-tobedefinedinafutureversionofMATLAB%handlesstructurewithhandlesanduserdata(seeGUIDATA)%Hints:get(hObject,'String')returnscontentsofeditastext%str2double(get(hObject,'String'))returnscontentsofeditasadouble%---Executesduringobjectcreation,aftersettingallproperties.functionedit_CreateFcn(hObject,eventdata,handles)%hObjecthandletoedit(seeGCBO)%eventdatareserved-tobedefinedinafutureversionofMATLAB%handlesempty-handlesnotcreateduntilafterallCreateFcnscalled%Hint:editcontrolsusuallyhaveawhitebackgroundonWindows.%SeeISPCandCOMPUTER.ifispc&&isequal(get(hObject,'BackgroundColor'),get(0,'def

1 / 14
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功