?? demodulation.m
字號:
function demod_out = demodulation(demod_in,mod_mode)
%%*************************************************************************
%%Function information:
%%由信道信號的復數值解調對應的二進制序列(In this program,the channel value are demodulated.)
%%-------------------------------------------------------------------------
%%First time : 3/25/2002
%%Newest modified time:6/20/2002
%%Programmer:Xuewei Mao
%%Version: 0.2
%%-------------------------------------------------------------------------
%%*************************************************************************
%%*************************************************************************
%% Reference:
%%-------------------------------------------------------------------------
%%
%%-------------------------------------------------------------------------
%% Note:
%%-------------------------------------------------------------------------
%% Here,the method for the four modulation modes is the same ,so see the note
%%for QPSK, and the note for the other three is omitted.
%%-------------------------------------------------------------------------
%% Function discription:
%%-------------------------------------------------------------------------
%% 由信道信號的復數值找出對應的二進制序列。方法如下:由信道值,
%%求出該值與星座圖中所有點的距離,找出距離最小的點,該點對應的
%%二進制序列及為該信道對應的解調結果。
%% In this program,the channel value are demodulated.
%% The process: firstly,calculate the distance between the channel value
%% and all the constellation points.then,find the shortest distance,thus ,the point
%% is the one.At last,put out the binary sequence symbolizing the point.
%%-------------------------------------------------------------------------
%% Input:
%%-------------------------------------------------------------------------
%% demod_in :輸入信道值 (the input channel value)
%%-------------------------------------------------------------------------
%% Output:
%%-------------------------------------------------------------------------
%% demod_out:解調結果 (demodulation output(binary) )
%%-------------------------------------------------------------------------
%% Global Variable:
%%-------------------------------------------------------------------------
%% g_RT
%%-------------------------------------------------------------------------
%%*************************************************************************
%system_parameters
switch (mod_mode)
case 2
%BPSK modulation
demod_out=zeros(1,length(demod_in));
for i=1:length(demod_in)
if abs( demod_in(i)-1)-abs( demod_in(i)+1)<=0 %demod_in(i)-1:接收點到1的距離; demod_in(i)+1:接收點到-1的距離
demod_out(i)=1;
else
demod_out(i)=0;
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
case 4
%QPSK modulation
d=zeros(4,length(demod_in)); % 'd ' is the distance between the channel value and the constellation point
m=zeros(1,length(demod_in));
temp=[-1-j -1+j 1-j 1+j]/sqrt(2);
for i=1:length(demod_in)
for n=1:4
%下面的demod_in(i)為啥要乘以sqrt(2)? --yzh
d(n,i)=(abs(demod_in(i)-temp(n))).^2;%由信道值,求出該值與星座圖中所有點的距離
end %calculate the distance between the channel and the constellation points
[min_distance,constellation_point] = min(d(:,i)) ; %D(:,i)=sort(d(:,i));%排序 (sort the distance in ascending order.)
m(i) = constellation_point;
end
A=de2bi([0:3],'left-msb');%寫出0到N-1(N為星座圖點數)
%(converts a nonnegative decimal vector [0,3] to a binary matrix A.)
for i=1:length(demod_in)
DEMOD_OUT(i,:)=A(m(i),:); %matrix:length(demod_in)*2 --yzh
% 最小值對應的星座點序號的二進制表示即為解調結果
end
demod_out=reshape(DEMOD_OUT',1,length(demod_in)*2);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
case 16
d=zeros(16,length(demod_in));
b=ones(1,length(demod_in));
m=zeros(1,length(demod_in));
temp=[-3-3*j -3-j -3+3*j -3+j ...
-1-3*j -1-j -1+3*j -1+j ...
3-3*j 3-j 3+3*j 3+j ...
1-3*j 1-j 1+3*j 1+j]/sqrt(10);
for i=1:length(demod_in)
for n=1:16
%下面的demod_in(i)為啥又不需要乘以sqrt(10)? --yzh
d(n,i)=(abs(demod_in(i)-temp(n))).^2; %加上sqrt(10),與其他解調對應 --yzh
end
[min_distance,constellation_point] = min(d(:,i)) ; %D(:,i)=sort(d(:,i));%排序 (sort the distance in ascending order.)
m(i) = constellation_point;
end
A=de2bi([0:15],'left-msb');
for i=1:length((demod_in))
DEMOD_OUT(i,:)=A(m(i),:);
end
demod_out=reshape(DEMOD_OUT',1,length(demod_in)*4);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
case 64
%64_QAM
d=zeros(64,length(demod_in));
D=zeros(64,length(demod_in));
m=zeros(1,length(demod_in));
temp=[-7-7*j -7-5*j -7-j -7-3*j -7+7*j -7+5*j -7+j -7+3*j...
-5-7*j -5-5*j -5-j -5-3*j -5+7*j -5+5*j -5+j -5+3*j...
-1-7*j -1-5*j -1-j -1-3*j -1+7*j -1+5*j -1+j -1+3*j...
-3-7*j -3-5*j -3-j -3-3*j -3+7*j -3+5*j -3+j -3+3*j...
7-7*j 7-5*j 7-j 7-3*j 7+7*j 7+5*j 7+j 7+3*j...
5-7*j 5-5*j 5-j 5-3*j 5+7*j 5+5*j 5+j 5+3*j...
1-7*j 1-5*j 1-j 1-3*j 1+7*j 1+5*j 1+j 1+3*j...
3-7*j 3-5*j 3-j 3-3*j 3+7*j 3+5*j 3+j 3+3*j ]/sqrt(42);
for i=1:length(demod_in)
for n=1:64
d(n,i)=(abs(demod_in(i)-temp(n))).^2;
end
[min_distance,constellation_point] = min(d(:,i)) ; %D(:,i)=sort(d(:,i));%排序 (sort the distance in ascending order.)
m(i) = constellation_point;
end
A=de2bi([0:63],'left-msb');
for i=1:length(demod_in)
DEMOD_OUT(i,:)=A(m(i),:);
end
demod_out=reshape(DEMOD_OUT',1,length(demod_in)*6);
otherwise
disp('Error! Please input again');
end
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -