基于某某matlab地码型转换

上传人:无*** 文档编号:100510671 上传时间:2022-06-02 格式:DOC 页数:23 大小:169KB
收藏 版权申诉 举报 下载
基于某某matlab地码型转换_第1页
第1页 / 共23页
基于某某matlab地码型转换_第2页
第2页 / 共23页
基于某某matlab地码型转换_第3页
第3页 / 共23页
资源描述:

《基于某某matlab地码型转换》由会员分享,可在线阅读,更多相关《基于某某matlab地码型转换(23页珍藏版)》请在装配图网上搜索。

1、word实验内容:利用Matlab软件的GUI界面编程,做一个简单的界面,通过此界面调用相关的程序去实现由抽样判决后的AMI码型、CMI码型和HDB3码型数字序列恢复出原始的PCM脉冲编码信号。实验目的:1,熟悉Matlab的GUI的编程操作,学会运用GUI来建立一个界面2.掌握AMI,CMI,HDB3码型的特点和意义,学会将PCM脉冲编码信号转化为AMI,CMI,HDB3的编码以与AMI,CMI,HDB3解码的方式。实验方法:实验中采用的方法是先建立大概的界面,其中包括输入框、按钮、提示内容与坐标系等。然后再对各种组件设置好属性,并对各个组件编写回调函数,最后进展调试验证饥渴。实验代码:1.

2、 AMI码型转换: % 编码 %p = -1;for i=1:length(f); if f(i)=1 e(i) = (-1)*p; p = e(i); else e(i) = f(i); endend% 译码 %for i=1:length(f); if e(i)=0 l(i) = 1; else e(i) = 0; endend编码:代码中的f代表着输入字符串转化后的ASCII码,用变量p来实现原信号中1的正负交替。例如,f1=1,如此e1=1,p=1;f2=1,如此e2=-1,p=-1。如此就可以得到正负1交替了。译码:当ei不等于0,就把结果等于1。2. CMI码型转换 % 编码 %m

3、=1;p=-1; for i=1:length(f) if(f(i)=1&m=1) s(i)=3; m=m*p; else if(f(i)=1&m=-1) s(i)=0; m=m*p; else s(i)=1; endend end k=dec2bin(s,2); l=k; x=l(:); y=x; n=str2num(y(1);for i=2:length(y) n=n str2num(y(i);end% 译码 % if n(1)=0 if n(2)=1 cm=0; else cm=1; end else cm=1; endr=3;while rlength(n) if n(r)=0 if

4、n(r+1)=1 cm=cm 0; else cm=cm 1; end else cm=cm 1; end r=r+2;end3. HDB3码型转换 % 编码 %yn=xn;% 输出yn初始化num=0;% 计数器初始化for k=1:length(xn) if xn(k)=1 num=num+1; % 1计数器 if num/2 = fix(num/2) % 奇数个1时输出-1,进展极性交替 yn(k)=1; else yn(k)=-1; end endend % HDB3编码num=0; % 连零计数器初始化yh=yn; % 输出初始化sign=0; % 极性标志初始化为0V=zeros(

5、1,length(yn);% V脉冲位置记录变量 B=zeros(1,length(yn);% B脉冲位置记录变量for k=1:length(yn) if yn(k)=0 num=num+1; % 连“0个数计数 if num=4 % 如果4连“0 num=0; % 计数器清零 yh(k)=1*yh(k-4); % 让0000的最后一个0改变为与前一个非零符号一样极性的符号 V(k)=yh(k); % V脉冲位置记录 if yh(k)=sign % 如果当前V符号与前一个V符号的极性一样 yh(k)=-1*yh(k); % 如此让当前V符号极性反转,以满足V符号间相互极性反转要求 yh(k-

6、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符号开始再交替变化 end sign=yh(k); % 记录前一个V符号的极性 end else num=0; % 当前输入为“1如此连“0计数器清零 endend % 译码 %input=yh; % HDB3码输入decode=input; % 输出初始化sign=0; % 极性标志初始化for k=1:length(yh) if input(k

7、) = 0 if sign=yh(k) % 如果当前码与前一个非零码的极性一样 decode(k-3:k)=0 0 0 0;% 如此该码判为V码并将*00V清零 end sign=input(k); % 极性标志 endenddecode=abs(decode); % 整流实验现象:总体界面:AMI:CMI:HDB3:总结:1. 本次实验中因为对画方波不太熟悉,在使用stairs函数时,方波图总是在最后少了一位,后来经查询后才知道stairs的正确用法。2. 由于对GUI界面设置的不熟悉,很多细节都没做到位,界面的美观有待提高。3. 在编代码是经常没有写注释,导致后来有些变量混淆了。附录:全部

8、代码function varargout = untitled1(varargin)% UNTITLED1, by itself, creates a new UNTITLED1 or raises the existing% singleton*.% H = UNTITLED1 returns the handle to a new UNTITLED1 or the handle to% the existing singleton*.% UNTITLED1(CALLBACK,hObject,eventData,handles,.) calls the local% function nam

9、ed CALLBACK in UNTITLED1.M with the given input arguments.% UNTITLED1(Property,Value,.) creates a new UNTITLED1 or raises the% existing singleton*. Starting from the left, property value pairs are% applied to the GUI before untitled1_OpeningFunction gets called. An% unrecognized property name or inv

10、alid value makes property application% stop. All inputs are passed to untitled1_OpeningF via varargin.% *See GUI Options on GUIDEs 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 untitled1%

11、 Last Modified by GUIDE v2.5 21-Dec-2014 19:55:20% Begin initialization code - DO NOT EDITgui_Singleton = 1;gui_State = struct(gui_Name, mfilename, .gui_Singleton, gui_Singleton, .gui_OpeningF, untitled1_OpeningF, .gui_OutputF, untitled1_OutputF, .gui_LayoutF, , .gui_Callback, );if nargin & ischar(v

12、arargin1) gui_State.gui_Callback = str2func(varargin1);endif nargout varargout1:nargout = gui_mainf(gui_State, varargin:);else gui_mainf(gui_State, varargin:);end% End initialization code - DO NOT EDIT% - Executes just before untitled1 is made visible.function untitled1_OpeningF(hObject, eventdata,

13、handles, varargin)% This function has no output args, see OutputF.% 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 mand line arguments to untitled1 (see VARARGIN)% Choose default mand li

14、ne output for untitled1handles.output = hObject;% Update handles structureguidata(hObject, handles);% UIWAIT makes untitled1 wait for user response (see UIRESUME)% uiwait(handles.maxing);% - Outputs from this function are returned to the mand line.function varargout = untitled1_OutputF(hObject, even

15、tdata, 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 mand line output from handles structurevarargout1 = h

16、andles.output;function edit_Callback(hObject, eventdata, handles)% hObject handle to edit (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 edit as text% str2double(

17、get(hObject,String) returns contents of edit as a double% - Executes during object creation, after setting all properties.function edit_CreateF(hObject, eventdata, handles)% hObject handle to edit (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles empty - handles n

18、ot created until after all CreateFs called% Hint: edit controls usually have a white background on Windows.% See ISPC and PUTER.if ispc & isequal(get(hObject,BackgroundColor), get(0,defaultUicontrolBackgroundColor) set(hObject,BackgroundColor,white);end% - Executes on button press in ami.function am

19、i_Callback(hObject, eventdata, handles)user_string=get(handles.edit,string);a=dec2bin(user_string,8);b=a;c=b(:);d=c;f=str2num(d(1);for i=2:length(d) f=f str2num(d(i);endf=f 0;% %p = -1;for i=1:length(f);if f(i)=1 e(i) = (-1)*p; p = e(i);else e(i) = f(i);endend% %for i=1:length(f);if e(i)=0 l(i) = 1;

20、else e(i) = 0;endendaxes(handles.axes1)t=1:length(f);stairs(t-1,f)axis(0 length(f) -2 2)xlabel(ASCII);grid minor;axes(handles.axes2)t=1:length(e);stairs(t-1,e)axis(0 length(e) -2 2)xlabel(AMI );grid minor;axes(handles.axes3)t=1:length(l);stairs(t-1,l)axis(0 length(l) -2 2)xlabel(AMI );grid minor;% h

21、Object handle to ami (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% - Executes on button press in cmi.function cmi_Callback(hObject, eventdata, handles)user_string=get(handles.edit,string);a=dec2bin(user_strin

22、g,8);b=a;c=b(:);d=c;f=str2num(d(1);for i=2:length(d) f=f str2num(d(i);endf=f 0;% %m=1;p=-1;for i=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;else s(i)=1;endendend k=dec2bin(s,2); l=k; x=l(:); y=x; n=str2num(y(1);for i=2:length(y) n=n str2num(y(i);end% %if n(1)=0if n(2)=

23、1 cm=0;else cm=1;endelse cm=1;endr=3;while rlength(n)if n(r)=0if n(r+1)=1 cm=cm 0;else cm=cm 1;endelse cm=cm 1;end r=r+2;endaxes(handles.axes1)t=1:length(f);stairs(t-1,f)axis(0 length(f) -2 2)xlabel(ASCII);grid minor;axes(handles.axes2)t=1:length(n);stairs(t-1,n)axis(0 length(n) -2 2)xlabel(CMI );gr

24、id minor;axes(handles.axes3)t=1:length(cm);stairs(t-1,cm)axis(0 length(cm) -2 2)xlabel(CMI );grid minor;% hObject handle to cmi (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% - Executes on button press in hdb3

25、.function hdb3_Callback(hObject, eventdata, handles)user_string=get(handles.edit,string);a=dec2bin(user_string,8);b=a;b=a;c=b(:);d=c;xn=str2num(d(1);for i=2:length(d) xn=xn str2num(d(i);endxn=xn 0;% %yn=xn;% ynnum=0;% for k=1:length(xn)if xn(k)=1 num=num+1; % 1if num/2 = fix(num/2) % 1-1, yn(k)=1;el

26、se yn(k)=-1;endendend% HDB3num=0; % yh=yn; % sign=0; % 0V=zeros(1,length(yn);% V B=zeros(1,length(yn);% Bfor k=1:length(yn)if yn(k)=0 num=num+1; % 0if num=4 % 40 num=0; % yh(k)=1*yh(k-4); % 00000 V(k)=yh(k); % Vif yh(k)=sign % VV yh(k)=-1*yh(k); % V,V yh(k-3)=yh(k); % B,V B(k-3)=yh(k); % B V(k)=yh(k

27、); % V yh(k+1:length(yn)=-1*yh(k+1:length(yn);% Vend sign=yh(k); % Vendelse num=0; % 10endend% %input=yh; % HDB3decode=input; % sign=0; % for k=1:length(yh)if input(k) = 0if sign=yh(k) % decode(k-3:k)=0 0 0 0;% V*00Vend sign=input(k); % endenddecode=abs(decode); % axes(handles.axes1)t=1:length(xn);s

28、tairs(t-1,xn)axis(0 length(xn) -2 2)xlabel(ASCII);grid minor;axes(handles.axes2)t=1:length(yh);stairs(t-1,yh)axis(0 length(yh) -2 2)xlabel(HDB3 );grid minor;axes(handles.axes3)t=1:length(decode);stairs(t-1,decode)axis(0 length(decode) -2 2)xlabel(HDB3 );grid minor;% hObject handle to hdb3 (see GCBO)

29、% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% - Executes when plent is resized.function plent_ResizeF(hObject, eventdata, handles)% hObject handle to plent (see GCBO)% eventdata reserved - to be defined in a future ver

30、sion of MATLAB% handles structure with handles and user data (see GUIDATA)% -function plent_ButtonDownF(hObject, eventdata, handles)% hObject handle to plent (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% - Executes during object creation, after setting all properties.function plent_CreateF(hObject, eventdata, handles)% hObject handle to plent (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles empty - handles not created until after all CreateFs called文案大全

展开阅读全文
温馨提示:
1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
2: 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
3.本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
关于我们 - 网站声明 - 网站地图 - 资源地图 - 友情链接 - 网站客服 - 联系我们

copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!