Chương trình nguồn_Chương 3

Chia sẻ: Trần Huyền My | Ngày: | Loại File: PDF | Số trang:29

0
72
lượt xem
4
download

Chương trình nguồn_Chương 3

Mô tả tài liệu
  Download Vui lòng tải xuống để xem tài liệu đầy đủ

%R: tốc độc bit
%Fc: tần số sóng mang
%N: chiều dài bit cần truyền
%s: chuỗi bit truyền
%Sample: số mẫu trong 1bit

Chủ đề:
Lưu

Nội dung Text: Chương trình nguồn_Chương 3

  1. Chöông 3 : Chöông trình nguoàn CHÖÔNG 3 CHÖÔNG TRÌNH NGUOÀN Coù taát caû 32 file chöông trình chính, ôû ñaây chæ trình baøy nhöõng chöông trình chính. Chöông trình khôûi ñoäng (init.m) % R : toác ñoä bit % Fc : taàn soá soùng mang % N : chieàu daøi bit caàn truyeàn % s : chuoãi bit truyeàn % Sample : soá maãu trong 1 bit % A : bieân ñoä soùng mang % bittrain : soá bit huaán luyeän % bittransfer : soá bit truyeàn moãi laàn clear all; global R; global Fc; global N; global s Sample A bittrain bittransfer; R=0; Fc=0; N=0; Sample=50; s=[]; A=1; bittrain=10; bittransfer=500; randn('state',sum(100*clock)); rand('state',sum(100*clock)); Chöông trình löu caùc thoâng soá caàn thieát (callbacknext.m) function callbacknext global Fc R N Sample TypeMod; Sample=round(20*Fc/R); %Chon loai dieu che tin hieu HModulation=findobj('tag','modu'); HModulation=get(HModulation,'Value'); if HModulation==1 TypeMod='BPSK'; else TypeMod='QPSK'; end Leâ Thanh Nhaät-Tröông AÙnh Thu 257 GVHD :Ths. Hoaøng Ñình Chieán
  2. Chöông 3 : Chöông trình nguoàn %Chon cac loai nhieu loainhieu; totalSNR; clear HModulation; set(gcf,'Visible','off'); train; Chöông trình löu thoâng soá nhieãu (loainhieu.m) function loainhieu; global A Sample HCheckNoise=findobj('tag','CheckNoise'); HCheckNoise=get(HCheckNoise,'Value'); HCheckFading=findobj('tag','CheckFading'); HCheckFading=get(HCheckFading,'Value'); HCheckCoChannel=findobj('tag','CheckCoChannel'); HCheckCoChannel=get(HCheckCoChannel,'Value'); HRadioSNR=findobj('tag','RadioSNR'); HRadioSNR=get(HRadioSNR,'Value'); HEditSNR=findobj('tag','EditSNR'); SNRNoise=get(HEditSNR,'String'); SNRNoise=str2num(SNRNoise); HEditMean=findobj('tag','EditMean'); HEditMean=get(HEditMean,'String'); Means=str2num(HEditMean); HEditVariance=findobj('tag','EditVariance'); HEditVariance=get(HEditVariance,'String'); Vars=str2num(HEditVariance); HEditSNRFad=findobj('tag','EditSNRFad'); SNRFad=get(HEditSNRFad,'String'); SNRFad=str2num(SNRFad); HSourceFad=findobj('tag','SourceFad'); SourceFad=get(HSourceFad,'string'); SourceFad=str2num(SourceFad); HEditSNRCo=findobj('tag','EditSNRCo'); SNRCo=get(HEditSNRCo,'String'); SNRCo=str2num(SNRCo); HSourceCo=findobj('tag','SourceCo'); SourceCo=get(HSourceCo,'String'); SourceCo=str2num(SourceCo); Leâ Thanh Nhaät-Tröông AÙnh Thu 258 GVHD :Ths. Hoaøng Ñình Chieán
  3. Chöông 3 : Chöông trình nguoàn save loainhieu HCheckNoise HCheckFading HCheckCoChannel HRadioSNR SNRNoise Means Vars SNRFad SourceFad SNRCo SourceCo; if HCheckFading Ps=0.5*A^2; %Cong suat tin hieu Pn=Ps*10^(-SNRFad/10); %Cong suat nhieu tong cong RatioFad=[]; i=1; while i
  4. Chöông 3 : Chöông trình nguoàn Noise=whitenoise(SNRNoise); %Lay nhieu White Noise theo SNR else Noise=gaussnoise(Means,Vars); %Lay nhieu Gaussian end else Noise=0; end if HCheckFading==1 NoiseFading=fading; %Lay nhieu Fading else NoiseFading=0; end if HCheckCoChannel==1 NoiseCoChannel=cochannel; %Lay nhieu CoChannel else NoiseCoChannel=0; end Chöông trình taïo nhieãu nhieät vôùi SNR cho tröôùc (whitenoise.m) function out=Whitenoise(SNRNoise) global bittransfer Sample A; Ps=0.5*A^2; n=randn(1,bittransfer*Sample); out=10*n.*sqrt(Ps*10^(-SNRNoise/10)); clear n Ps; Chöông trình taïo nhieãu Gauss vôùi giaù trò trung bình vaø phöông sai cho tröôùc (gaussnoise.m) function out=Gaussnoise(Mean,Var) global bittransfer Sample; NoiseSignal=randn(1,bittransfer*Sample); out=NoiseSignal*3*Var+Mean; clear NoiseSignal; Chöông trình taïo nhieãu Fading (fading.m) function out=fading; load loainhieu PhaseShiftFad RatioFad SourceFad; global bittransfer Info Sample A t ; out=0; i=1; while i0 Fadi(bittransfer*Sample:- 1:PhaseShiftFad(i)+1)=Fadi(bittransfer*Sample-PhaseShiftFad(i):-1:1); Fadi(1:1:PhaseShiftFad(i))=0; Leâ Thanh Nhaät-Tröông AÙnh Thu 260 GVHD :Ths. Hoaøng Ñình Chieán
  5. Chöông 3 : Chöông trình nguoàn elseif PhaseShiftFad(i)
  6. Chöông 3 : Chöông trình nguoàn global Fc R N A t t0 Sample TypeMod s bittrain bittransfer; global Info FiltedTransmit Receive FiltedReceive FiltedLow ss; global AfterEq Decision; % Info : Tín hieäu ñieàu cheá khoâng coù nhieãu % FiltedTransmit : Tín hieäu ñieàu cheá sau khi qua BPF % Receive : Tín hieäu thu % FiltedReceive : Tín hieäu thu sau khi qua BPF % FiltedLow : Tín hieäu thu sau LPF % ss : chuoãi bit thu ñöôïc khoâng qua boä caân baèng % AfterEq : Tín hieäu thu sau khi qua boä caân baèng % Decision : Chuoãi bit thu ñöôïc sau khi qua boä caân baèng luutrain; set(gcf,'Visible','off'); t0=0; epre=0; etrain=0; Sample=round(20*Fc/R); T=1/R; %Huan luyen mang ban dau t=linspace(T/Sample,bittransfer*T,bittransfer*Sample); s=randint(1,bittransfer); %Dieu che if TypeMod=='BPSK' bpsk; FiltedTransmit=loc(R,Info); else qpsk; FiltedTransmit=loc(R/2,Info); end %Kenh truyen [Noise,NoiseFad,NoiseCo]=chonnhieu; Receive=FiltedTransmit+Noise+NoiseFad+NoiseCo; %Giai dieu che va huan luyen mang if TypeMod=='BPSK' FiltedReceive=loc(R,Receive); FiltedLow=debpsk(FiltedReceive); ss=detectorinter(FiltedLow); for i=1:bittrain Target((i-1)*Sample+1:i*Sample)=(-2*s(i)+1)*A; end home Leâ Thanh Nhaät-Tröông AÙnh Thu 262 GVHD :Ths. Hoaøng Ñình Chieán
  7. Chöông 3 : Chöông trình nguoàn net=huanluyen(FiltedLow(Sample+1:(bittrain+1)*Sample),Target); [AfterEq,du]=mang(net,FiltedLow); AfterEq(1)=[]; Decision=detector(AfterEq); else FiltedReceive=loc(R/2,Receive); FiltedLow=deqpsk(FiltedReceive); ss=detectorinter(FiltedLow); home for i=1:bittrain Target((i-1)*2*Sample+1:i*2*Sample)=(-2*s(2*i-1)+1)*A; end netOdd=huanluyen(FiltedLow(1,2*Sample+1:2*(bittrain+1)*Sample),Target); for i=1:bittrain Target((i-1)*2*Sample+1:i*2*Sample)=(2*s(2*i)-1)*A; end netEven=huanluyen(FiltedLow(2,2*Sample+1:2*(bittrain+1)*Sample),Target) AfterEq=[]; [AfterEq(1,:),duOdd]=mang(netOdd,FiltedLow(1,:)); [AfterEq(2,:),duEven]=mang(netEven,FiltedLow(2,:)); AfterEq(:,1)=[]; Decision=detector(AfterEq); end totals=bittransfer; epre=epre+sum(abs(s-ss)); berpre=epre/totals; etrain=etrain+sum(abs(s-Decision)); bertrain=etrain/totals; hinhve(berpre,bertrain,totals); pause(1); %Chay mo phong mang rep=N/bittransfer; if rep>1 t0=T*bittransfer; for i=2:rep t=linspace(t0+T/Sample,t0+bittransfer*T,bittransfer*Sample); s=randint(1,bittransfer); %Dieu che if TypeMod=='BPSK' Leâ Thanh Nhaät-Tröông AÙnh Thu 263 GVHD :Ths. Hoaøng Ñình Chieán
  8. Chöông 3 : Chöông trình nguoàn bpsk; FiltedTransmit=loc(R,Info); else qpsk; FiltedTransmit=loc(R/2,Info); end %Kenh truyen [Noise,NoiseFad,NoiseCo]=chonnhieu; Receive=FiltedTransmit+Noise+NoiseFad+NoiseCo; %Giai dieu che if TypeMod=='BPSK' FiltedReceive=loc(R,Receive); FiltedLow=debpsk(FiltedReceive); ss=detectorinter(FiltedLow); [AfterEq,du]=mang(net,FiltedLow,du); Decision=detector(AfterEq); else FiltedReceive=loc(R/2,Receive); FiltedLow=deqpsk(FiltedReceive); ss=detectorinter(FiltedLow); AfterEq=[]; [AfterEq(1,:),duOdd]=mang(netOdd,FiltedLow(1,:)); [AfterEq(2,:),duEven]=mang(netEven,FiltedLow(2,:)); AfterEq(:,1)=[]; Decision=detector(AfterEq); end totals=totals+bittransfer; epre=epre+sum(abs(s-ss)); berpre=epre/totals; etrain=etrain+sum(abs(s-Decision)); bertrain=etrain/totals; hinhve(berpre,bertrain,totals); pause(1); t0=t0+T*bittransfer; end end msgbox('The program finished') Chöông trình ñieàu cheá BPSK khoâng coù nhieãu (bpsk.m) function bpsk global R Fc s bittransfer Info Sample A t; Leâ Thanh Nhaät-Tröông AÙnh Thu 264 GVHD :Ths. Hoaøng Ñình Chieán
  9. Chöông 3 : Chöông trình nguoàn Info=[]; ss=[0 1]; T=1/R; tt=linspace(T/Sample,2*T,2*Sample); wt=2*pi*Fc*tt; ref=A*cos(wt+ss(ceil(tt*R-0.1/Sample))*pi); ref=reshape(ref,Sample,2)'; for i=1:bittransfer Info((i-1)*Sample+1:i*Sample)=ref(s(i)+1,:); end clear T ss ref tt i wt; Chöông trình ñieàu cheá QPSK khoâng coù nhieãu (bpsk.m) function qpsk global Fc bittransfer R s Info A Sample; Info=[]; sOdd =[0 0 0 0 1 1 1 1]; sEven=[0 0 1 1 0 0 1 1]; T=1/R; tt=linspace(T/Sample,8*T,8*Sample); wt=2*pi*Fc*tt; ref=A*(cos(wt+sOdd(ceil(tt*R-0.1/Sample))*pi)-sin(wt+sEven(ceil(tt*R- 0.1/Sample))*pi)); ref=reshape(ref,2*Sample,4)'; for i=1:bittransfer/2 Info((i-1)*2*Sample+1:i*2*Sample)=ref(2*s(2*i-1)+s(2*i)+1,:); end clear wt sEven sOdd ref T tt; Chöông trình giaûi ñieàu cheá BPSK khoâng coù nhieãu (debpsk.m) function [out]=debpsk(signal) global Fc t R bittransfer Sample; wt=2*pi*Fc*t; y=2*cos(wt); PreDeModulated=signal.*y; out=lowpass(R,PreDeModulated); Chöông trình giaûi ñieàu cheá QPSK khoâng coù nhieãu (debpsk.m) function [out]=deqpsk(signal) global R Fc t bittransfer Sample ; Leâ Thanh Nhaät-Tröông AÙnh Thu 265 GVHD :Ths. Hoaøng Ñình Chieán
  10. Chöông 3 : Chöông trình nguoàn wt=2*pi*Fc*t; y=2*cos(wt); z=2*sin(wt); PreDeModulated1=signal.*y; PreDeModulated2=signal.*z; out(1,:)=lowpass(R/2,PreDeModulated1); out(2,:)=lowpass(R/2,PreDeModulated2); Chöông trình thieát keá boä loïc baêng thoâng BPF (loc.m) % Fb : taàn soá bit thöïc % Vôùi BPSK Fb=R % Vôùi QPSK Fb=R/2 function out=loc(Fb,signal); global Fc Sample R; Fs=Sample*R; %Dung ButterWorth bac=5; passband=[Fc-Fb Fc+Fb]/(Fs/2); [Bb Ab]=butter(bac,passband); out=filter(Bb,Ab,signal); clear passband bac Bb Ab; Chöông trình thieát keá boä loïc thoâng thaáp LPF (lowpass.m) function out=lowpass(Fb,signal); global Sample R Fc; Fs=Sample*R; %Dung ButterWorth bac=5; passlow=Fc/(Fs/2); [Bb Ab]=butter(bac,passlow); out=filter(Bb,Ab,signal); clear passband bac Bb Ab; Chöông trình löu caùc thoâng soá caàn cho maïng Neural Networks (luutrain.m) function luutrain; FcnName=['compet ';'hardlim ';'hardlims';'logsig ';'poslin ';'purelin ';'radbas ';'satlin ';'satlins ';'softmax ';'tansig ';'tribas ']; HPopupNetworks=findobj('tag','PopupNetworks'); HPopupNetworks=get(HPopupNetworks,'Value'); Leâ Thanh Nhaät-Tröông AÙnh Thu 266 GVHD :Ths. Hoaøng Ñình Chieán
  11. Chöông 3 : Chöông trình nguoàn HPopupLearn=findobj('tag','PopupLearn'); HPopupLearn=get(HPopupLearn,'Value'); HSliderTapDelay=findobj('tag','SliderTapDelay'); HSliderTapDelay=get(HSliderTapDelay,'Value'); HSliderLayer=findobj('tag','SliderLayer'); HSliderLayer=get(HSliderLayer,'Value'); HPopupPerf=findobj('tag','PopupPerf'); HPopupPerf=get(HPopupPerf,'Value'); for i=1:HSliderLayer str=num2str(i); H=findobj('tag',['SliderLayer',str]); Neuron(i)=get(H,'Value'); H=findobj('tag',['PopupTransfer',str]); TransferFcn(i,:)=FcnName(get(H,'Value'),:); end clear H str i; save luutrain Chöông trình choïn loaïi maïng Neural Networks (calbacknetworks.m) function callbacknetworks; HPopupNetworks=findobj('tag','PopupNetworks'); h=get(HPopupNetworks,'Value'); if h==1|h==2|h==3|h==4|h==5|h==6|h==7|h==8|h==9|h==10|h==11|h==12 HTextLearn=findobj('tag','TextLearn'); set(HTextLearn,'Visible','on'); HPopupLearn=findobj('tag','PopupLearn'); set(HPopupLearn,'Visible','on'); HTextLayer=findobj('tag','TextLayer'); set(HTextLayer,'Visible','on'); HEditLayer=findobj('tag','EditLayer'); set(HEditLayer,'Visible','on','string',num2str(3)); HSliderLayer=findobj('tag','SliderLayer'); set(HSliderLayer,'Visible','on','Value',3); HSliderLayer=get(HSliderLayer,'Value'); HTextPerf=findobj('tag','TextPerfFunction'); set(HTextPerf,'Visible','on'); HPopupPerf=findobj('tag','PopupPerf'); Leâ Thanh Nhaät-Tröông AÙnh Thu 267 GVHD :Ths. Hoaøng Ñình Chieán
  12. Chöông 3 : Chöông trình nguoàn set(HPopupPerf,'Visible','on'); HTextNeuron=findobj('tag','TextNeuronUp'); set(HTextNeuron,'Visible','on'); HTextTransfer=findobj('tag','TextTransferUp'); set(HTextTransfer,'Visible','on'); for i=1:HSliderLayer str=num2str(i); H=findobj('tag',['TextLayer',str]); set(H,'Visible','on'); H=findobj('tag',['EditLayer',str]); set(H,'Visible','on'); H=findobj('tag',['SliderLayer',str]); set(H,'Visible','on'); H=findobj('tag',['PopupTransfer',str]); set(H,'Visible','on'); end else HTextLearn=findobj('tag','TextLearn'); set(HTextLearn,'Visible','off'); HPopupLearn=findobj('tag','PopupLearn'); set(HPopupLearn,'Visible','off'); HTextLayer=findobj('tag','TextLayer'); set(HTextLayer,'Visible','off'); HEditLayer=findobj('tag','EditLayer'); set(HEditLayer,'Visible','off'); HSliderLayer=findobj('tag','SliderLayer'); set(HSliderLayer,'Visible','off'); HSliderLayer=get(HSliderLayer,'Value'); HTextPerf=findobj('tag','TextPerfFunction'); set(HTextPerf,'Visible','off'); HPopupPerf=findobj('tag','PopupPerf'); set(HPopupPerf,'Visible','off'); HTextNeuron=findobj('tag','TextNeuronUp'); set(HTextNeuron,'Visible','off'); HTextNeuron=findobj('tag','TextNeuronDown'); set(HTextNeuron,'Visible','off'); HTextTransfer=findobj('tag','TextTransferUp'); set(HTextTransfer,'Visible','off'); Leâ Thanh Nhaät-Tröông AÙnh Thu 268 GVHD :Ths. Hoaøng Ñình Chieán
  13. Chöông 3 : Chöông trình nguoàn HTextTransfer=findobj('tag','TextTransferDown'); set(HTextTransfer,'Visible','off'); HTextLayer1=findobj('tag','TextLayer1'); set(HTextLayer1,'Visible','off'); HTextLayer2=findobj('tag','TextLayer2'); set(HTextLayer2,'Visible','off'); HTextLayer3=findobj('tag','TextLayer3'); set(HTextLayer3,'Visible','off'); for i=1:HSliderLayer str=num2str(i); H=findobj('tag',['TextLayer',str]); set(H,'Visible','off'); H=findobj('tag',['EditLayer',str]); set(H,'Visible','off'); H=findobj('tag',['SliderLayer',str]); set(H,'Visible','off'); H=findobj('tag',['PopupTransfer',str]); set(H,'Visible','off'); end end Chöông trình huaán luyeän maïng Neural Networks (huanluyen.m) function net=huanluyen(signal,Target); load luutrain; hamhl={'trainbr';'trainlm';'trainoss';'trainbfg';'trainscg';'traincgb'; 'traincgp';'traincgf';'trainrp';'traingdx';'traingdm';'traingd'}; hamhoc={'learngd';'learngdm'}; hamss={'mse';'msereg';'mae';'sse'}; h=HPopupNetworks; if h==1|h==2|h==3|h==4|h==5|h==6|h==7|h==8|h==9|h==10|h==11|h==12 BTF=hamhl{h}; BLF=hamhoc{HPopupLearn}; PF=hamss{HPopupPerf}; col=length(signal); P=zeros(HSliderTapDelay,col); for i=1:HSliderTapDelay P(i,i+1:col)=signal(1:col-i); rang(i,:)=minmax(signal); end tf=cellstr(TransferFcn); figure; Leâ Thanh Nhaät-Tröông AÙnh Thu 269 GVHD :Ths. Hoaøng Ñình Chieán
  14. Chöông 3 : Chöông trình nguoàn net=newff(rang,Neuron,tf,BTF,BLF,PF); net.trainParam.lr=0.01; net.trainParam.show=20; net.trainParam.epochs=100; net.trainParam.goal=0.1; net=train(net,P,Target); close(gcf); elseif h==13 %Adaptive Linear net col=length(signal); P=zeros(HSliderTapDelay,col); for i=1:HSliderTapDelay P(i,i+1:col)=signal(1:col-i); end net=newlind(P,Target); elseif h==14 %Batch Static col=length(signal); P=zeros(HSliderTapDelay,col); for i=1:HSliderTapDelay P(i,i+1:col)=signal(1:col-i); rang(i,:)=minmax(signal); end lr=maxlinlr(P,'bias') net=newlin(rang,1,0,lr); net.trainParam.epochs=100; net.trainParam.goal=0.01; net=train(net,P,Target); end Chöông trình moâ phoûng maïng Neural Networks (mang.m) function [dem,dura]=mang(net,signal,du) load luutrain HSliderTapDelay; global Sample bittransfer; if nargin==2 col=bittransfer*Sample+1; P=zeros(HSliderTapDelay,col); for i=1:HSliderTapDelay P(i,i+1:col)=signal(1:col-i); end else col=bittransfer*Sample; P=zeros(HSliderTapDelay,col); for i=1:HSliderTapDelay P(i,i:col)=signal(1:col-i+1); end if HSliderTapDelay>2 for i=HSliderTapDelay:-1:2 Leâ Thanh Nhaät-Tröông AÙnh Thu 270 GVHD :Ths. Hoaøng Ñình Chieán
  15. Chöông 3 : Chöông trình nguoàn P(i,1:i-1)=du(HSliderTapDelay-i+1:HSliderTapDelay-1); end end end dem=sim(net,P); dura=P(1,col-HSliderTapDelay+2:col); clear col P i; Chöông trình tính SNR (totalSNR.m) function totalSNR global TotalSNR; %Cong suat tin hieu HEditAmplitude=findobj('Tag','EditAmplitude'); Am=get(HEditAmplitude,'String'); Am=str2num(Am); Ps=0.5*Am^2; clear Am HEditAmplitude; %Cong suat nhieu WhiteNoise HCheck=findobj('Tag','CheckNoise'); Check=get(HCheck,'Value'); if Check==1 HRadioSNR=findobj('Tag','RadioSNR'); SNRW=get(HRadioSNR,'Value'); if SNRW==1 HEditSNR=findobj('Tag','EditSNR'); SNRW=get(HEditSNR,'string'); SNRW=str2num(SNRW); Pw=Ps*10^(-SNRW/10); clear HEditSNR SNRW; else HEditMean=findobj('Tag','EditMean'); Mean=get(HEditMean,'String'); Mean=str2num(Mean); HEditVariance=findobj('Tag','EditVariance'); Var=get(HEditVariance,'string'); Var=str2num(Var); Pw=Mean^2+0.5*Var; clear HEditMean Mean HEditVariance Var; end clear SNRW HRadioSNR; else Pw=0; end %Cong suat nhieu Fading HCheck=findobj('Tag','CheckFading'); Check=get(HCheck,'Value'); Leâ Thanh Nhaät-Tröông AÙnh Thu 271 GVHD :Ths. Hoaøng Ñình Chieán
  16. Chöông 3 : Chöông trình nguoàn if Check==1 HEditSNRFad=findobj('Tag','EditSNRFad'); SNRF=get(HEditSNRFad,'string'); SNRF=str2num(SNRF); Pf=Ps*10^(-SNRF/10); clear HEditSNRFad SNRF; else Pf=0; end %Cong suat nhieu CoChannel HCheck=findobj('Tag','CheckCoChannel'); Check=get(HCheck,'Value'); if Check==1 HEditSNRCo=findobj('Tag','EditSNRCo'); SNRC=get(HEditSNRCo,'string'); SNRC=str2num(SNRC); Pc=Ps*10^(-SNRC/10); clear HEditSNRCo SNRC; else Pc=0; end clear HCheck Check %Tinh Total SNR HStaticTotalSNR=findobj('tag','StaticTotalSNR'); Pn=Pw+Pf+Pc; if Pn==0 set(HStaticTotalSNR,'Visible','off'); TotalSNR=100000; else TotalSNR=10*log10(Ps/(Pw+Pf+Pc)); Cau=['Total Signal Noise Ratio : ' num2str(TotalSNR,3) ' dB']; set(HStaticTotalSNR,'Visible','on'); set(HStaticTotalSNR,'string',Cau); end clear Pn Ps Pc Pw Pf Cau HStaticTotalSNR; Chöông trình thieát keá boä quyeát ñònh (detector.m) function out=detector(signal); global Sample bittransfer R TypeMod s; T=1/R; if TypeMod=='BPSK' offset=1.5*Sample; for i=1:bittransfer-1 tong=signal((i-1)*Sample+offset); if tong>0 Leâ Thanh Nhaät-Tröông AÙnh Thu 272 GVHD :Ths. Hoaøng Ñình Chieán
  17. Chöông 3 : Chöông trình nguoàn out(i)=0; else out(i)=1; end end out(bittransfer)=s(bittransfer); else %Nghia la QPSK offset=1.5*2*Sample; for i=1:bittransfer/2-1 tong=signal(1,(i-1)*2*Sample+offset); if tong>0 ssOdd(i)=0; else ssOdd(i)=1; end end ssOdd(bittransfer/2)=s(bittransfer-1); for i=1:bittransfer/2-1 tong=signal(2,(i-1)*2*Sample+offset); if tong>0 ssEven(i)=1; else ssEven(i)=0; end end ssEven(bittransfer/2)=s(bittransfer); out(1:2:bittransfer-1)=ssOdd; out(2:2:bittransfer)=ssEven; end Chöông trình xuaát hieän cöûa soå hieån thò keát quaû (hinhve.m) function hinhve(berpre,bertrain,totals) global Fc R t Sample Info FiltedTransmit Receive FiltedReceive SS; global DECISION axesup axesdown; global FiltedLow AfterEq Decision TypeMod TotalSNR s ss line S sobit; sobit=10; line=zeros(2,9); S=[]; SS=[]; DECISION=[]; for i=1:sobit S((i-1)*Sample+1:i*Sample)=s(i); end for i=1:sobit-1 Leâ Thanh Nhaät-Tröông AÙnh Thu 273 GVHD :Ths. Hoaøng Ñình Chieán
  18. Chöông 3 : Chöông trình nguoàn SS(i*Sample+1:(i+1)*Sample)=ss(i); DECISION(i*Sample+1:(i+1)*Sample)=Decision(i); end SS(1:Sample)=0; DECISION(1:Sample)=0; Hve=findobj('Tag','ve'); if isempty(Hve) h=figure('Name','Modulation and Demodulation', ... 'NumberTitle','off','Position',[0 0 800 560], ... 'CloseRequestFcn','closereq;Htrain=findobj(''Tag'',''train''); set(Htrain,''Visible'',''on'');clear Htrain;',... 'tag','ve'); subplot(2,1,1); line(1,1)=plot(t(1:sobit*Sample),S); set(gca,'tag','Axesve1'); set(gca,'Position',[0.13 0.48 0.60 0.24]); xlabel('Time (s)'); ylabel('Amplitude'); title('Data input'); axesup=gca; subplot(2,1,2); line(2,9)=plot(t(1:sobit*Sample),DECISION,'r'); set(gca,'tag','Axesve2'); set(gca,'Position',[0.13 0.11 0.60 0.24]); xlabel('Time (s)'); ylabel('Amplitude'); title('Data output'); axesdown=gca; Hz=['Carrier Freq. ' num2str(Fc/1000) ' KHz']; Rate=['Bit Rate ' num2str(R/1000) ' Kbps']; h1 = uicontrol('Parent',h, ... 'Units','points', ... 'BackgroundColor',[0.75294117647 0.75296470588 0.752941176588], ... 'Callback','close(gcf);Htrain=findobj(''tag'',''train'');set(Htrain,''V isible'',''on'');clear Htrain;',... 'FontName','vni-times', ... 'FontSize',12, ... 'ListboxTop',0, ... 'Position',[495 255 60 20], ... 'String','Back', ... 'Tag','ButtonTrain'); h1 = uicontrol('Parent',h, ... 'Units','points', ... 'BackgroundColor',[0.752941176488 0.751176470588 0.75294110588], ... 'Callback','set(gcf,''visible'',''off'');spectrum;',... 'FontName','vni-times', ... Leâ Thanh Nhaät-Tröông AÙnh Thu 274 GVHD :Ths. Hoaøng Ñình Chieán
  19. Chöông 3 : Chöông trình nguoàn 'FontSize',12, ... 'ListboxTop',0, ... 'Position',[495 215 60 20], ... 'String','Spectrum', ... 'Tag','ButtonSpectrum'); h1 = uicontrol('Parent',h, ... 'Units','points', ... 'BackgroundColor',[0.80392157451 0.803927451 0.803921568627451], ... 'FontSize',12, ... 'HorizontalAlignment','left', ... 'ListboxTop',0, ... 'Position',[447 140 120 16], ... 'String',Rate, ... 'Style','text', ... 'Tag','TextBitRate'); h1 = uicontrol('Parent',h, ... 'Units','points', ... 'BackgroundColor',[0.8039215651 0.80392127451 0.8039215627451], ... 'FontSize',12, ... 'HorizontalAlignment','left', ... 'ListboxTop',0, ... 'Position',[447 160 150 16], ... 'String',Hz, ... 'Style','text', ... 'Tag','TextFreq'); if TypeMod=='BPSK' h1 = uicontrol('Parent',h, ... 'Units','points', ... 'BackgroundColor',[0.8039218627 0.80392156862 0.80392156862], ... 'FontSize',12, ... 'HorizontalAlignment','left', ... 'ListboxTop',0, ... 'Position',[447 120 150 16], ... 'String','Modulation : BPSK', ... 'Style','text', ... 'Tag','TextMod'); else h1 = uicontrol('Parent',h, ... 'Units','points', ... 'BackgroundColor',[0.80392156862 0.8039215686 0.80392156861], ... 'FontSize',12, ... 'HorizontalAlignment','left', ... 'ListboxTop',0, ... 'Position',[447 120 150 16], ... 'String','Modulation : QPSK', ... 'Style','text', ... 'Tag','TextMod'); end Leâ Thanh Nhaät-Tröông AÙnh Thu 275 GVHD :Ths. Hoaøng Ñình Chieán
  20. Chöông 3 : Chöông trình nguoàn BER2=['Real BER before train ' num2str(berpre,5)]; BER3=['Real BER after train ' num2str(bertrain,5)]; h1 = uicontrol('Parent',h, ... 'Units','points', ... 'BackgroundColor',[0.803921568621 0.803921568627 0.80392156851], ... 'FontSize',12, ... 'HorizontalAlignment','left', ... 'ListboxTop',0, ... 'Position',[447 80 150 16], ... 'String',BER2, ... 'Style','text', ... 'Tag','TextBERrealpre'); h1 = uicontrol('Parent',h, ... 'Units','points', ... 'BackgroundColor',[0.80392156862 0.8039215651 0.803921568627], ... 'FontSize',12, ... 'HorizontalAlignment','left', ... 'ListboxTop',0, ... 'Position',[447 60 150 16], ... 'String',BER3, ... 'Style','text', ... 'Tag','TextBERrealtrain'); Totalbit=['Sum of bit is transfered ' num2str(totals)]; h1 = uicontrol('Parent',h, ... 'Units','points', ... 'BackgroundColor',[0.803921568627 0.803921568621 0.80392156864], ... 'FontSize',12, ... 'HorizontalAlignment','left', ... 'ListboxTop',0, ... 'Position',[447 40 150 16], ... 'String',Totalbit, ... 'Style','text', ... 'Tag','TextTotalbit'); h1 = uicontrol('Parent',h, ... 'Units','points', ... 'BackgroundColor',[0.8 0.807843137254902 0.807843137254902], ... 'FontName','Vni-book', ... 'FontSize',11, ... 'HorizontalAlignment','left', ... 'ListboxTop',0, ... 'Position',[15 365.25 75 15], ... 'String','Data Input', ... 'Style','Text', ... 'Tag','S', ... 'Value',1); h1 = uicontrol('Parent',h, ... 'Units','points', ... 'BackgroundColor',[0.8 0.807843137254902 0.807843137254902], ... Leâ Thanh Nhaät-Tröông AÙnh Thu 276 GVHD :Ths. Hoaøng Ñình Chieán
Đồng bộ tài khoản