📄 ofdmtransmitter.m
字号:
%function [frameout,re,im,n]=ofdmtransmitter()
echo off
clear;
frame_num = input('Please enter the numbers of frame frame_num: ( default: frame_num = 1 )');
if isempty(frame_num)
frame_num =1;
end
frame_len = input('Please enter the length of the frame frame_len: ( default: frame_len =64 )');
if isempty(frame_len)
frame_len =64;
end
rate = input('Please enter the rate(6M, 12M, 24M, 48M) rate: (default: rate = 6)');
if isempty(rate)
rate= 6;
end
encodeon = input('add convolutioanal enter 1 to add 0 to mask (default: encodeon= 0)');
if isempty(encodeon)
encodeon = 0;
end
scrambleon = input('add scramble enter 1 to add 0 to mask (default: scrambleon= 0)');
if isempty(scrambleon)
scrambleon = 0;
end
interleavingon = input('add interleaving enter 1 to add 0 to mask (default: interleavingon= 0)');
if isempty(interleavingon)
interleavingon = 0;
end
%signal to noise ratio in dB
EsN0db = input('Please enter Es/N0 in dB : default -10 ');
if isempty(EsN0db)
EsN0db = -10;
end
%determine the modulation mode and coding rate
switch rate
case 6
modu_mode=1;%BPSK
coding_rate=1/2;
Ncbps=48;
Ndbps=24;
Kmod=1;
case 9
modu_mode=1;%BPSK
coding_rate=3/4;
Ncbps=48;
Ndbps=36;
Kmod=1;
case 12
modu_mode=2;%QPSK
coding_rate=1/2;
Ncbps=96;
Ndbps=48;
Kmod=0.707;
case 18
modu_mode=2;%QPSK
coding_rate=3/4;
Ncbps=96;
Ndbps=72;
Kmod=0.707;
case 24
modu_mode=4;%16-QAM
coding_rate=1/2;
Ncbps=192;
Ndbps=96;
Kmod=0.316;
case 36
modu_mode=4;%16-QAM
coding_rate=3/4;
Ncbps=192;
Ndbps=144;
Kmod=0.316;
case 48
modu_mode=6;%64-QAM
coding_rate=2/3;
Ncbps=288;
Ndbps=192;
Kmod=0.154;
case 54
modu_mode=6;%64-QAM
coding_rate=3/4;
Ncbps=288;
Ndbps=216;
Kmod=0.154;
otherwise
fprintf('rate input error');
end
pn=[1,1,1,1,-1,-1,-1,1,-1,-1,-1,-1,1,1,-1,1,-1,-1,1,1,-1,1,1,-1,1,1,1,1,1,1,-1,1,...
1,1,-1,1,1,-1,-1,1,1,1,-1,1,-1,-1,-1,1,-1,1,-1,-1,1,-1,-1,1,1,1,1,1,-1,-1,1,1,...
-1,-1,1,-1,1,-1,1,1,-1,-1,-1,1,1,-1,-1,-1,-1,1,-1,-1,1,-1,1,1,1,1,-1,1,-1,1,-1,1,...
-1,-1,-1,-1,-1,1,-1,1,1,-1,1,-1,1,1,1,-1,-1,1,-1,-1,-1,1,1,1,-1,-1,-1,-1,-1,-1,-1];%used to scramble the pilot
%short preamble define
preamble=[0.0, 0.0, 0.0, 0.0,... %Generate Short Preamble No.1-No.5
0.0, 0.0, 0.0, 0.0,...
1.472+1.472i, 0.0, 0.0, 0.0,...
-1.472-1.472i, 0.0, 0.0, 0.0,...
1.472+1.472i, 0.0, 0.0, 0.0,...
-1.472-1.472i, 0.0, 0.0, 0.0,...
-1.472-1.472i, 0.0, 0.0, 0.0,...
1.472+1.472i, 0.0, 0.0, 0.0,...
0.0, 0.0, 0.0, 0.0,...
-1.472-1.472i, 0.0, 0.0, 0.0,...
-1.472-1.472i, 0.0, 0.0, 0.0,...
1.472+1.472i, 0.0, 0.0, 0.0,...
1.472+1.472i, 0.0, 0.0, 0.0,...
1.472+1.472i, 0.0, 0.0, 0.0,...
1.472+1.472i, 0.0, 0.0, 0.0,...
0.0, 0.0, 0.0, 0.0 ];
%ifft short preamble
t_s_preamble=b_ifft(preamble);
%transmitter_out=y;
%define long preamble
l_preamble=[0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 1.000, 1.000,... %Generate Long Preamble No.1
-1.000, -1.000, 1.000, 1.000, -1.000, 1.000, -1.000, 1.000,... %back to back
1.000, 1.000, 1.000, 1.000, 1.000, -1.000, -1.000, 1.000,...
1.000, -1.000, 1.000, -1.000, 1.000, 1.000, 1.000, 1.000,...
0.000, 1.000, -1.000, -1.000, 1.000, 1.000, -1.000, 1.000,...
-1.000, 1.000, -1.000, -1.000, -1.000, -1.000, -1.000, 1.000,...
1.000, -1.000, -1.000, 1.000, -1.000, 1.000, -1.000, 1.000,...
1.000, 1.000, 1.000, 0.000, 0.000, 0.000, 0.000, 0.000];
%ifft long preamble
t_l_preamble=b_ifft(l_preamble);
%generate SIGNAL Field
switch rate
case 6
signal(1:4)=[1 1 0 1];
case 9
signal(1:4)=[1 1 1 1];
case 12
signal(1:4)=[0 1 0 1];
case 18
signal(1:4)=[0 1 1 1];
case 24
signal(1:4)=[1 0 0 1];
case 36
signal(1:4)=[1 0 1 1];
case 48
signal(1:4)=[0 0 0 1];
case 54
signal(1:4)=[0 0 1 1];
otherwise
fprintf('rate input error');
end
signal(5)=0;
signal(6:17)=dec_to_bi(frame_len,12);
parity=0;
for i=1:17
parity=xor(parity,signal(i));
end
signal(18)=parity;
signal(19:24)=0;
%convolutional process
if encodeon==1
signal_out=convo_process(signal,1/2);% 48 bits
else
signal_out(1:12)=0;
signal_out(13:36)=signal;
signal_out(37:48)=0;
end
%interleaving signal process
if interleavingon==1
signal_to_modu=interleaving(signal_out,48,1);
else
signal_to_modu=signal_out;
end
%mapping and insert pilot
signal_in_fre=mapping(signal_to_modu,pn(1),1);
%ifft signal
signal_in_time=b_ifft(signal_in_fre);
%generate data field
data(1:16)=0; %sevice field of data
for k=1:frame_len
data_byte(k)=floor(128*rem(randn,1));
data((17+(k-1)*8):(17+(k-1)*8+7))=dec_to_bi(data_byte(k),8);
end
data((17+frame_len*8):(17+frame_len*8+5))=0;%tail of the data
Nsym=ceil((17+frame_len*8+5)/Ndbps);
Ndata=Nsym*Ndbps;
Npad=Ndata-(17+frame_len*8+5);
Ncbps=Ndbps/coding_rate;
if Npad>0
data((17+frame_len*8+6):Ndata)=0; %pad of the data
end
%scramble the data field
if scrambleon
data_s=scramble(data);
data_s((17+frame_len*8):(17+frame_len*8+5))=0;%tail of the data
else
data_s=data;
end
%divide into symbols
for i=1:Nsym
data_sym(i,:)=data_s((1+(i-1)*Ndbps):(i*Ndbps));
end
%convolutional process in data field
if encodeon==1
for i=1:Nsym
data_sym_c(i,:)=convo_process(data_sym(i,:),coding_rate);
end
else
for i=1:Nsym
data_sym_c(i,(1:(Ncbps-Ndbps)/2))=0;
data_sym_c(i,(((Ncbps-Ndbps)/2+1):(Ndbps+(Ncbps-Ndbps)/2)))=data_sym(i,:);
data_sym_c(i,(Ndbps+(Ncbps-Ndbps)/2+1):Ncbps)=0;
end
end
%interleaving process in data field
if interleavingon==1
for i=1:Nsym
data_sym_int(i,:)=interleaving(data_sym_c(i,:),Ncbps,modu_mode);
end
else
data_sym_int(i,:)=data_sym_c(i,:);
end
%mapping and insert pilot in data
for i=1:Nsym
data_sym_fre(i,:)=mapping(data_sym_int(i,:),pn(i+1),modu_mode);
end
%ifft data
for i=1:Nsym
data_ifft(i,:)=b_ifft(data_sym_fre(i,:));
end
%insert predix
for i=1:Nsym
data_in_time(i,1:16)=data_ifft(i,49:64);
data_in_time(i,17:80)=data_ifft(i,1:64);
end
%transmit in time of the whole frame
Nsample=160+80*2+80+80*Nsym;
for i=1:160
frame_s_p(i)=t_s_preamble(rem(i-1,16)+1);
end
frame_s_p(1)=0.5*frame_s_p(1);
frame_s_p(161)=0.5*frame_s_p(1);
for i=162:1:Nsample+1
frame_s_p(i)=0;
end
for i=1:160
frame_l_p(i)=0;
end
frame_l_p(161:176)=t_l_preamble(49:64);
frame_l_p(161)=0.5*frame_l_p(161);
frame_l_p(177:192)=t_l_preamble(49:64);
frame_l_p(193:256)=t_l_preamble(1:64);
frame_l_p(257:320)=t_l_preamble(1:64);
frame_l_p(321)=0.5*t_l_preamble(1);
for i=322:1:Nsample+1
frame_l_p(i)=0;
end
for i=1:320
frame_signal(i)=0;
end
frame_signal(321:336)=signal_in_time(49:64);
frame_signal(321)=0.5*frame_signal(321);
frame_signal(337:400)=signal_in_time(1:64);
frame_signal(401)=0.5*signal_in_time(1);
for i=402:1:Nsample+1
frame_signal(i)=0;
end
for n=1:Nsym
for i=1:(400+(n-1)*80)
frame_data(n,i)=0;
end
frame_data(n,((400+(n-1)*80+1):(400+n*80)))=data_in_time(n,1:80);
frame_data(n,(400+(n-1)*80+1))=0.5*frame_data(n,(400+(n-1)*80+1));
frame_data(n,(400+n*80+1))=0.5*data_in_time(n,17);
for i=(400+n*80+2):1:Nsample+1
frame_data(n,i)=0;
end
end
frameout=frame_s_p+frame_l_p+frame_signal;
for n=1:Nsym
frameout=frameout+Kmod*frame_data(n,:);
end
% frameout1=AWAG_channel_backup(frameout,1500000000,1.3);
% re=real(frameout1);
% im=imag(frameout1);
% x(1,1:2242)=0:2241;
% x(2,2:2242)=re;
% x(2,1)=0;
% x=x';
% y(1,1:2242)=0:2241;
% y(2,2:2242)=im;
% y(2,1)=0;
% y=y';
% n=1:1:Nsample+1;
% n=n';
%in(1,:)=frameout;
%in(2,:)=n;
%a=size(in);
%len=a(2);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -