基于某matlab地码型转换Word文档下载推荐.docx
《基于某matlab地码型转换Word文档下载推荐.docx》由会员分享,可在线阅读,更多相关《基于某matlab地码型转换Word文档下载推荐.docx(20页珍藏版)》请在冰点文库上搜索。
if(f(i)==1&
m==1)
s(i)=3;
m=m*p;
elseif(f(i)==1&
m==-1)
s(i)=0;
s(i)=1;
k=dec2bin(s,2);
l=k'
;
x=l(:
);
y=x'
n=str2num(y
(1));
fori=2:
length(y)
n=[nstr2num(y(i))];
%%%%%%%%%%%%译码%%%%%%%%%%%%%
ifn
(1)==0
ifn
(2)==1
cm=[0];
cm=[1];
r=3;
whiler<
length(n)
ifn(r)==0
ifn(r+1)==1
cm=[cm0];
cm=[cm1];
r=r+2;
3.HDB3码型转换
yn=xn;
%输出yn初始化
num=0;
%计数器初始化
fork=1:
length(xn)
ifxn(k)==1
num=num+1;
%"
1"
计数器
ifnum/2==fix(num/2)%奇数个1时输出-1,进行极性交替
yn(k)=1;
yn(k)=-1;
%HDB3编码
%连零计数器初始化
yh=yn;
%输出初始化
sign=0;
%极性标志初始化为0
V=zeros(1,length(yn));
%V脉冲位置记录变量
B=zeros(1,length(yn));
%B脉冲位置记录变量
length(yn)
ifyn(k)==0
%连“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脉冲位置记录
yh(k+1:
length(yn))=-1*yh(k+1:
length(yn));
%并让后面的非零符号从V符号开始再交替变化
sign=yh(k);
%记录前一个V符号的极性
%当前输入为“1”则连“0”计数器清零
end
input=yh;
%HDB3码输入
decode=input;
%极性标志初始化
length(yh)
ifinput(k)~=0
ifsign==yh(k)%如果当前码与前一个非零码的极性相同
decode(k-3:
k)=[0000];
%则该码判为V码并将*00V清零
sign=input(k);
%极性标志
decode=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.
Property'
'
Value'
...)createsanewUNTITLED1orraisesthe
%existingsingleton*.Startingfromtheleft,propertyvaluepairsare
%appliedtotheGUIbeforeuntitled1_OpeningFunctiongetscalled.An
%unrecognizedpropertynameorinvalidvaluemakespropertyapplication
%stop.Allinputsarepassedtountitled1_OpeningFcnviavarargin.
%*SeeGUIOptionsonGUIDE'
sToolsmenu.Choose"
GUIallowsonlyone
%instancetorun(singleton)"
.
%Seealso:
GUIDE,GUIDATA,GUIHANDLES
%Edittheabovetexttomodifytheresponsetohelpuntitled1
%LastModifiedbyGUIDEv2.521-Dec-201419:
55:
20
%Begininitializationcode-DONOTEDIT
gui_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});
ifnargout
[varargout{1:
nargout}]=gui_mainfcn(gui_State,varargin{:
});
else
gui_mainfcn(gui_State,varargin{:
%Endinitializationcode-DONOTEDIT
%---Executesjustbeforeuntitled1ismadevisible.
functionuntitled1_OpeningFcn(hObject,eventdata,handles,varargin)
%Thisfunctionhasnooutputargs,seeOutputFcn.
%hObjecthandletofigure
%eventdatareserved-tobedefinedinafutureversionofMATLAB
%handlesstructurewithhandlesanduserdata(seeGUIDATA)
%varargincommandlineargumentstountitled1(seeVARARGIN)
%Choosedefaultcommandlineoutputforuntitled1
handles.output=hObject;
%Updatehandlesstructure
guidata(hObject,handles);
%UIWAITmakesuntitled1waitforuserresponse(seeUIRESUME)
%uiwait(handles.maxing);
%---Outputsfromthisfunctionarereturnedtothecommandline.
functionvarargout=untitled1_OutputFcn(hObject,eventdata,handles)
%varargoutcellarrayforreturningoutputargs(seeVARARGOUT);
%Getdefaultcommandlineoutputfromhandlesstructure
varargout{1}=handles.output;
functionedit_Callback(hObject,eventdata,handles)
%hObjecthandletoedit(seeGCBO)
%Hints:
get(hObject,'
String'
)returnscontentsofeditastext
%str2double(get(hObject,'
))returnscontentsofeditasadouble
%---Executesduringobjectcreation,aftersettingallproperties.
functionedit_CreateFcn(hObject,eventdata,handles)
%handlesempty-handlesnotcreateduntilafterallCreateFcnscalled
%Hint:
editcontrolsusuallyhaveawhitebackgroundonWindows.
%SeeISPCandCOMPUTER.
ifispc&
isequal(get(hObject,'
BackgroundColor'
),get(0,'
defaultUicontrolBackgroundColor'
))
set(hObject,'
white'
%---Executesonbuttonpressinami.
functionami_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));
length(d)
f=[fstr2num(d(i))];
f=[f0];
%%%%%%%%%%%%±
à
Â
ë
%%%%%%%%%%%%%
iff(i)==1
%%%%%%%%%%%%Ò
%%%%%%%%%%%%
ife(i)~=0
axes(handles.axes1)
t=1:
stairs(t-1,f)
axis([0length(f)-22])
xlabel('
ASCIIÂ
gridminor;
axes(handles.axes2)
length(e);
stairs(t-1,e)
axis([0length(e)-22])
AMI±
axes(handles.axes3)
length(l);
stairs(t-1,l)
axis([0length(l)-22])
AMIÒ
%hObjecthandletoami(seeGCBO)
%---Executesonbuttonpressincmi.
functioncmi_Callback(hObject,eventdata,handles)
if(f(i)==1&
elseif(f(i)==1&
ifn
(1)==0
ifn
(2)==1
ifn(r)==0
ifn(r+1)==1
length(n);
stairs(t-1,n)
axis([0length(n)-22])
CMI±
length(cm);
stairs(t-1,cm)
axis([0length(cm)-22])
CMIÒ
%hObjecthandletocmi(seeGCBO)
%---Executesonbuttonpressinhdb3.
functionhdb3_Callback(hObject,eventdata,handles)
xn=str2num(d
(1));
xn=[xnstr2num(d(i))];
xn=[xn0];
%Ê
ä
³
ö
yn³
õ
Ê
¼
»
¯
%¼
Æ
ý
÷
ifxn(k)==1
ifnum/2==fix(num/2)%Æ
æ
¸
1Ê
±
-1,½
ø
Ð
«
Ô
½
Ì
%HDB3±
%Á
¬
Á
ã
%Ê
%¼
ê
Ö
¾
Î
ª
%VÂ
å
Ã
Ç
¿
%BÂ
ifyn(k)==0
¡
°
0¡
ifnum==4%È
ç
¹
û
4Á
%È
0000µ
Ä
×
î
º
ó
Ò
0¸
Ó
·
Å
Ï
Í
µ
%VÂ
ifyh(k)==sign%È
V·
%Ô
ò
È
´
Ò
ú
¥
%Ì
í
B·
Ó
%BÂ
%²
¢
Ù
%µ
1¡
%HDB3Â
ifinput(k)~=0
ifsign==yh(k)%È
k)