《基于matlab码型转换..》由会员分享,可在线阅读,更多相关《基于matlab码型转换..(15页珍藏版)》请在金锄头文库上搜索。
1、实验内容:利用Matlab软件的GUI界面编程,做一个简单的界面,通过此界面调用相关的程序去实现由抽样判决后的AMI码型、CMI码型和 HDB3码型数字序列恢复出原始的PCM脉冲编码信号。实验目的:1,熟悉Matlab的GUI的编程操作,学会运用GUI来建立一个界面 2掌握AMI,CM1,HDB3码型的特点和意义,学会将PCM脉冲编码信号转化为AMI,CMI,HDB3的编码以及AMI,CMI,HDB3解码的方式。实验方法:实验中采用的方法是先建立大概的界血,其中包括输入框、按钮、提示内容及坐标系等然后再对各种组件设置好属性,并对各个组件编写回调函数,最后进行调试验证饥渴。实验代码:1. AMI
2、码型转换:罨砉吊罨编码 Pfor i=l : length (f);主0 f 蚓:1 :e房f(凵;endend 罨鼍罨译码 for主:1:length(f);主0 e 0)、一0end end 编码:代码中的f代表着输入字符串转化后的ASCII码,用变量p来实现原信号中1的正负交替。例如,f 0)一1,则e 0)一1,p=l:f 0)一1,则e(2)一0 p=le如此就可以得到正负I交替了。译码:当e (i)不等于0,就把结果等于2CMI码型转换fori=l:length(f) if(f(i)l&ml)elseif(f(i)l&m=l)s(ik=dec2bin(s,2);n=str2num(
3、Y(1); fori=2length(y) n=n str2num(Y(i); 译码 ifn(l)0 ifn(2)lelse cm-卩;Plength(n)ifn(r+l)l cm=cm 0;cm=cm刂;else cm-lcm刂;厂r+2;3HDB3码型转换yn=xn;%输出yn初始化 num-0;%计数器初始化 for k=l:length(xn) ifxn(k)l 1 计数器 ifnum/2fix(nuW2)0/0奇数个1时输出丞进行极性交替 yn(k)=l, else%HDB3编码 num-O,连零计数器初始化 yh=yn;输出初始化 sign-O,极性标志初始化为0V一zeros(l
4、长ng山(yn月;V脉冲位置记录变量 Bzeros(l,length(yn);% B脉冲位置记录变量 fork=l:length(yn) ifyn(k)0 num-num-Fl;连“ 0 ”个数计数 ifnum4如果4连“ 0 ” num=0计数器清零 yh(k)=1*yh(k-4);让0000的最后一个0改变为与前一个非零符号相同极性的符号v脉冲位置记录ifyh(k)srgn如果当前v符号与前一个v符号的极性相同 yh(k)=l*yh(k);则让当前v符号极性反转,以满足v符号间相互极性反转要求 yh(k-3)=yh(k);添加B符号,与v符号同极性 B(k-3)=yh(k);B脉冲位置记录
5、 v脉冲位置记录 yh(k+l:length(yn)=-l*yh(k+l:length(yn);并让后面的非零符号从v符号开始再交替变化sign=yh(k);记录前一个V符号的极性“ 0 计数器清零unputyh; HDB3码输入 输出初始化 sign-O极性标志初始化 fork-I:length(yh) if input(k)一0 ifsignyh(k) 如果当前码与前一个非零码的极性相同 decode(k-3:k)=0000;%则该码判为v码并将嚀00v清零signinput(k);极性标志整流实验现象:总体界面:码型转换AMI到HDB3:function varargout = unti
6、tledl (varargin) UNTITLEDI M-file for untitledl.figUNTITLEDI, by itself, creates a new UNETLEDI or raises the existing singleton .H = UNTITLEDI returns the handle to a new UNTITLEOI or the handle to the existing singleton* .UNTITLEDI ( CALLBACK , h0biect, handles, . . . ) calls the local function na
7、med CALLBACK in UNTITLEDI.M with the given input arguments .UNTITLEDI ( , Value , . . . ) creates a new UNTITLEDI or raises the existing singleton . Starting from the left, property value parrs are applied to the GUI before untitledl OpeningFunction gets called.unrecognized property name o: invaLid
8、value makes property app I i cation stop. ALL inputs are passed untitledl OpeningEcn via varargln .*See GUI Options on GUIDEs 2001s menu. Choose allows only one instance to run (singleton) see also: GUIDE, GUIDATA, GUANDLES* Edit the above text to modify the response to help untitledl* Last Modified
9、 by GUIDE v2.5* Begin initialization code NOT EDIT gui_SingIeton = gui State struct ( gui_Name,m filename,gui Singleton , gui_SingIeton, gui_OpeningFcn , untitledl OpeningFcn, gui_OutputFcn , untitledl OutputFcn, .gui_LayoutEcn , gui Callback, if nargin ischar (varargin(l) str2func (varargin(l) ; en
10、dif nargout tvarargout I : nargout I gui_mainfcn (gui State, varargin .else gui mainfcn (gui_State, varargin(: ) ; end End initialization code NOT EDITExecutes just before untitLedI is made visible.function untitledl OpeningFcn (hobject, eventdata, handles, varargin) * This function has no output ar
11、gs, see OutputFcn. hob ect handle to figure eventdata reserved to be defined in a future version of MAT LAB handles structure with handles and user data (see GUI DATA) varargin command line arguments to untitledl (see VARARGIN) Choose default command line output for untitledl handles. output hobject
12、; Update handles structure guidata (hob ect, handles) ; UI WAIT makes untitledl wait for user (see UIRESUME) uiwait (handles . maxing) ;Outputs from this function are returned to the command line.function varargout untitledl OutputEcn (hobject, eventdata, handles) varargout cell array for returning
13、output args (see VARARGOUT) ; hObj ect handle to figure eventdata reserved to be defined in a future version of MAT LAB handles structure with handles and user data (see GUI DATA) Get default command line output from handles structure varargoutl handles. output;function edit Callback (hobject, event
14、data, handles) h Object handle to edit ( see GCEO) eventdata reserved to be defined in a future version of MAT LAB handlesstructure with handles and user data (see GUI DATA) Hints: get (hObject, String ) returns contents of edit as text str2doubLe (get (hObject, String) ) returns contents of edit as
15、 a doubleExecutes during object creation, after setting all properties .function edit CreateFcn (hobject, eventdata, handles) h Object handle to edit ( see G CEO) eventdata reserved to be defined in a future version of MAT LAB handlesempty handles not created until after all CreateEcns called Hint: edit controls usually have a white background on nindows. see zspc and COMPUTER.isequal (get (hObject, BackgroundCoIor) ,set (hobject, wh