⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 errorprob.m

📁 alamouti仿真程序供大家分享,有什么问题就提出来哈
💻 M
字号:
%***********errorprob.m**********************
% function [ps]=errorprob(snr_in_dB)
%	input:
%		snr_in_dB: signal to noise ratio in dB
%	output:
%		ps: the rate of the error symbols 
%   Programed by Cao xiaoling
%   Data: 2004.5.1
%*******************************************


function [ps]=errorprob(snr_in_dB)

%--Initialization--------------------------------
N=1000000;               %--Total symbols number;
Es=4;                           %--Energy of one transmit symbol;
error_symbols=0;        %--The number of error symbols;
x(1)=1+i;                     %--x(1) to x(4) represent QPSK modulation;
x(2)=-1+i;
x(3)=-1-i;
x(4)=1-i;

EsN0=10^(snr_in_dB/10);      
sgma=sqrt(0.5*Es/EsN0);         %--The variance of the Gaussian white noise


%***************generation of symbols********************
for k=1:(N/2)
	temp_num_one=rand;
	if (temp_num_one<0.25)
		source_one=1+i;
	elseif (temp_num_one<0.5)
		source_one=-1+i;
	elseif (temp_num_one<0.75)
		source_one=-1-i;
	else
		source_one=1-i;
	end
	temp_num_two=rand;
	if (temp_num_two<0.25)
		source_two=1+i;
	elseif (temp_num_two<0.5)
		source_two=-1+i;
	elseif (temp_num_two<0.75)
		source_two=-1-i;
	else
		source_two=1-i;
	end
%**************generation of noise****************	
	nc1=sgma*randn;
	ns1=sgma*randn;
	nc2=sgma*randn;
	ns2=sgma*randn;
   
%--Generation Rayleigh channel-------------------
    a=randn/sqrt(2);
    b=randn/sqrt(2);
    h1=a+b*i;                       %--The variance of the channel coefficient is 1
    c=randn/sqrt(2);
    d=randn/sqrt(2);
    h2=c+d*i;                       %--The variance of the channel coefficient is 1
    
%--The signal transmit through rayleigh channel and add white noise---

	r1=h1*source_one+h2*source_two+nc1+ns1*i;
	r2=-1*h1*conj(source_two)+h2*conj(source_one)+nc2+ns2*i;

%*************detection of the signal********************
	for m=1:4
		for n=1:4
			temp1=x(m);
			temp2=x(n);
			distance(m,n)=(abs(r1-h1*temp1-h2*temp2))^2+(abs(r2+h1*conj(temp2)-h2*conj(temp1)))^2;
		end
	end
	[p,q]=findmin(distance);
	decision_one=x(p);
	decision_two=x(q);


	if (source_one~=decision_one)
		error_symbols=error_symbols+1;
	elseif (source_two~=decision_two)
		error_symbols=error_symbols+1;
	end
end
ps=error_symbols/N;

%*********************end of the function*********************************

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -