- Visual C++源码
- Visual Basic源码
- C++ Builder源码
- Java源码
- Delphi源码
- C/C++源码
- PHP源码
- Perl源码
- Python源码
- Asm源码
- Pascal源码
- Borland C++源码
- Others源码
- SQL源码
- VBScript源码
- JavaScript源码
- ASP/ASPX源码
- C#源码
- Flash/ActionScript源码
- matlab源码
- PowerBuilder源码
- LabView源码
- Flex源码
- MathCAD源码
- VBA源码
- IDL源码
- Lisp/Scheme源码
- VHDL源码
- Objective-C源码
- Fortran源码
- tcl/tk源码
- QT源码
This_one.m
资源名称:This_one.rar [点击查看]
上传用户:sdyljs
上传日期:2019-09-30
资源大小:1k
文件大小:3k
源码类别:
通讯/手机编程
开发平台:
Matlab
- %%%%%%%%%%%%%%%%%%%%%%%%%METHOD%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- %(a) Generate random binary sequence of +1抯 and -1抯.
- %(b) Given different Power to the source and the relay as well
- %(c) Multiply the symbols with the channel and then add white Gaussian noise.
- %(d) At any receiver, equalize (divide) the received symbols with the known channel
- %(e) Perform hard-decision-decoding and count the bit errors
- %(f) Plot the power given to both source(Ps) and relay(Pr) with both SNR and BER
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- %Total Power available PT=Ps+Pr=100dB
- clear
- N = 100; % bit stream
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%SOURCE_NODE%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- ip = rand(1,N)>0.5; % generating 0,1 with equal probability
- s = 2*ip-1; % BPSK modulation 0 -> -1; 1 -> 0
- Ps=linspace(1,100,N);%Power given to the source(in dB)
- for j=1:length(Ps)
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%DIFINING_CHANNEL_AND_NOISE%%%%%%%%%%%%%%%%%%%%%
- n = 1/sqrt(2)*(randn(1,N) + 1i*randn(1,N)); % white gaussian noise, 0dB variance
- h = 1/sqrt(2)*(randn(1,N) + 1i*randn(1,N)); % Rayleigh channel
- ys=sqrt(Ps(j)).*h.*+ n;%Signal and noise added together(broadcasted in the first time slot)
- SNR1=(Ps(j).*h.^2)./n;%SNR_Souce-Relay,Souce-destination-link
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%RELAY_NODE%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- %Pr=100-Ps Power given to the relay
- % equalization
- yHat = ys./sqrt(Ps(j)).*h;
- % hard-decision-decoding
- ipHat = real(yHat)>0;% signal at the relay after decoding
- s1=2*ipHat-1;%BPSK modulation(before sending in the second time slot)
- yr= sqrt(100-Ps(j)).*h.*s1+ n; %signal broadcasted by the relay in the second time slot
- SNR2=((100-Ps(j)).*h.^2)./n;%SNR_Relay-Destination-link
- %%%%%%%%%%%%%%%%%%%%%%%%%DESTINATION_NODE%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- yd=ys+yr;
- SNR3=max(SNR1,SNR2);% Selection_combining(SC)
- SNR_RC=SNR1+SNR2;%Ratio_combining
- % equalization
- yHat_dest =ys./sqrt(Ps(j)).*h+yr./sqrt(80-Ps(j)).*h;
- % hard-decision-decoding
- ipHat_dest=real(yHat_dest)>0;
- % counting the errors
- nErr(j) = size(find((ip- ipHat_dest)),2);
- end
- BER=real(nErr/N);%bit error rate
- %plotting
- close all
- figure
- subplot(2,1,1)
- plot(Ps,SNR3,'r')
- xlabel('Ps,Pr')
- ylabel('SNR')
- hold on
- plot(100-Ps,SNR3,'g')
- legend('Source-Power','Relay-Power')
- grid on
- subplot(2,1,2)
- plot(Ps,BER,'r')
- hold on
- plot(100-Ps,BER,'g')
- xlabel('Ps,Pr')
- ylabel('BER')
- grid on
- legend('Source-Power','Relay-Power')
- %%%%%%%%%%%%%%%%%%%%%%%RATION_COMBINING%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- %plotting
- % close all
- % figure
- % subplot(2,1,1)
- % plot(Ps,SNR_RC,'r--')
- % xlabel('Ps,Pr')
- % ylabel('SNR-RC')
- % hold on
- % plot(100-Ps,SNR_RC,'g--')
- % legend('Source-Power;SNR-RC','Relay-Power;SNR-RC')
- % grid on
- % subplot(2,1,2)
- % plot(Ps,SNR3,'r')
- % hold on
- % plot(100-Ps,SNR3,'g')
- % xlabel('Ps,Pr')
- % ylabel('SNR3')
- % grid on
- % legend('Source-Power;SNR3','Relay-Power;SNR3')