📄 demodulation.asv
字号:
function output_frame = demodulation1(input_modu, index)
% demodulation for IEEE802.11a
% Input: input_modu, complex values representing constellation points
% index
% Output: output_frame, output bit stream (data unit is one bit)
% In this version, increase the quatilization levels into 8.
% note: Matlab index starts from 1
guiyi=[1 sqrt(2) sqrt(6) sqrt(10) sqrt(20) sqrt(42)];
input_modu=input_modu*guiyi(index);
Q_length=length(input_modu);
Q_length=length(input_modu);
QAM_input_I = real(input_modu);
QAM_input_Q = imag(input_modu);
output_frame = zeros(1,length(input_modu)*index);
switch index
case 1,
BPSK_Demodu_I = [0 1]; %f(m)=(m+1)/2 + 1, so I=-1 ---> 1, I=1 ---> 2
idx = find(QAM_input_I>1); %找出大于1的数据的位置,从第一列开始向下排列,大于1和小于-1是因为AWGN噪声的原因,对于QR方法,在前面求的时候最后就用到了mapping,所以不会出现>1和<-1的情况,只有在ZF和MMSE的时候才会出现这种情况
QAM_input_I(idx) = 1;
idx = find(QAM_input_I<-1);
QAM_input_I(idx) = -1;
output_frame = BPSK_Demodu_I(round((QAM_input_I+1)/2) + 1); %f(m)指的就是这,round是朝最近的整数取整,round将小于0的都整成1,大于0的都整成2. BPSK_Demodu_I将1-->0, 2-->1
case 2,
QPSK_Demodu_IQ = [0 1]; %f(m)=(m+1)/2 + 1, so I=-1 ---> 1, I=1 ---> 2
idx = find(QAM_input_I>1);
QAM_input_I(idx) = 1;
idx = find(QAM_input_I<-1);
QAM_input_I(idx) = -1;
idx = find(QAM_input_Q>1);
QAM_input_Q(idx) = 1;
idx = find(QAM_input_Q<-1);
QAM_input_Q(idx) = -1;
output_frame(1:2:end) = QPSK_Demodu_IQ(round((QAM_input_I+1)/2) + 1);
output_frame(2:2:end) = QPSK_Demodu_IQ(round((QAM_input_Q+1)/2) + 1);
case 3,
mapping=[3+i 1+i -3+i -1+i -3-i -1-i 3-i 1-i];
remapping=[0 0 0;0 0 1;0 1 0;0 1 1;1 0 0;1 0 1;1 1 0;1 1 1].';
a=ones(1,8);
for j=1:Q_length
b = mapping-input_modu(j)*a;
[gk k1]=min(abs(b).^2);
output_frame((1+(j-1)*3):(3+(j-1)*3))=remapping((1+3*(k1-1)):(3+3*(k1-1)));
end
case 4,
QAM_16_Demodu_IQ = [0 1 3 2]; %f(m)=(m+3)/2 + 1, so I=-3 ---> 1, I=1 ---> 3
idx = find(QAM_input_I>3);
QAM_input_I(idx) = 3;
idx = find(QAM_input_I<-3);
QAM_input_I(idx) = -3;
idx = find(QAM_input_Q>3);
QAM_input_Q(idx) = 3;
idx = find(QAM_input_Q<-3);
QAM_input_Q(idx) = -3;
tmp = round((QAM_input_I+3)/2) + 1;
output_frame(1:4:end) = bitget(QAM_16_Demodu_IQ(tmp),2); %获取每个数的次低位,如 0 1 3 3 就是 00 01 11 11 则2就是 0 0 1 1
output_frame(2:4:end) = bitget(QAM_16_Demodu_IQ(tmp),1); %获取最低位
tmp = round((QAM_input_Q+3)/2) + 1;
output_frame(3:4:end) = bitget(QAM_16_Demodu_IQ(tmp),2);
output_frame(4:4:end) = bitget(QAM_16_Demodu_IQ(tmp),1);
case 5,
mapping=[5+i 3+i 1+i 5+3*i 3+3*i 1+3*i 3+5*i 1+5*i -5+i -3+i -1+i -5+3*i -3+3*i -1+3*i -3+5*i -1+5*i -5-i -3-i -1-i -5-3*i -3-3*i -1-3*i -3-5*i -1-5*i 5-i 3-i 1-i 5-3*i 3-3*i 1-3*i 3-5*i 1-5*i];
remapping=[0 0 0 0 0;0 0 0 0 1;0 0 0 1 0;0 0 0 1 1;0 0 1 0 0;0 0 1 0 1;0 0 1 1 0;0 0 1 1 1;
0 1 0 0 0;0 1 0 0 1;0 1 0 1 0;0 1 0 1 1;0 1 1 0 0;0 1 1 0 1;0 1 1 1 0;0 1 1 1 1;
1 0 0 0 0;1 0 0 0 1;1 0 0 1 0;1 0 0 1 1;1 0 1 0 0;1 0 1 0 1;1 0 1 1 0;1 0 1 1 1;
1 1 0 0 0;1 1 0 0 1;1 1 0 1 0;1 1 0 1 1;1 1 1 0 0;1 1 1 0 1;1 1 1 1 0;1 1 1 1 1].';
a=ones(1,32);
for j=1:Q_length
b = mapping-input_modu(j)*a;
[gk k1]=min(abs(b).^2);
output_frame((1+(j-1)*5):(5+(j-1)*5))=remapping((1+5*(k1-1)):(5+5*(k1-1)));
end
case 6,
QAM_64_Demodu_IQ = [0 1 3 2 6 7 5 4]; %f(m)=(m+7)/2 + 1, so I=-7 ---> 1, I=1 ---> 5
idx = find(QAM_input_I>7);
QAM_input_I(idx) = 7;
idx = find(QAM_input_I<-7);
QAM_input_I(idx) = -7;
idx = find(QAM_input_Q>7);
QAM_input_Q(idx) = 7;
idx = find(QAM_input_Q<-7);
QAM_input_Q(idx) = -7;
tmp = round((QAM_input_I+7)/2) + 1;
output_frame(1:6:end) = bitget(QAM_64_Demodu_IQ(tmp),3);
output_frame(2:6:end) = bitget(QAM_64_Demodu_IQ(tmp),2);
output_frame(3:6:end) = bitget(QAM_64_Demodu_IQ(tmp),1);
tmp = round((QAM_input_Q+7)/2) + 1;
output_frame(4:6:end) = bitget(QAM_64_Demodu_IQ(tmp),3);
output_frame(5:6:end) = bitget(QAM_64_Demodu_IQ(tmp),2);
output_frame(6:6:end) = bitget(QAM_64_Demodu_IQ(tmp),1);
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -