clc;
clear all;
close all;
N = 256; % subcarriers個數
ofs = 1; % 一個迴圈傳送幾個OFDM symbol
cp =1/4*N; % CP length
% M-ary QAM modulation
M = 16;
bit = log2(M); % 一個symbol傳送的bit數
% Normalization Factor "Kmod" Modulation Scheme Value
% kmod here is a normalization constant or scale factor applied to the hard decision based on the sub-carrier constellation being used,such as BPSK, QPSK, 16-QAM or 64-QAM such that each of the sub-carriers have equal power.
% kmod=1; % BPSK
% kmod=1/sqrt(2); % QPSK
kmod=1/sqrt(10); % 16QAM
% kmod=1/sqrt(42); % 64QAM
msnr = 25;
snrindex = 0:1:msnr;
loop = 100; % 迴圈數
h = waitbar(0,'Please wait...');
for l=1:loop
s=0;
waitbar(l/loop);
for snr=snrindex
% transmitter
%******** Binary Sequence generation
bi = randint(1,bit*N*ofs); % 隨機產生二位元訊號10
%******** Serial to parallel conversion
stp = reshape(bi,N,bit*ofs); % 轉成N*(bit*ofs)矩陣
%******** QAM modulation
index = bi2de(stp,'left-msb'); % 將symbol轉成index ex:00 0,01 1,10 2,11 3
modulation = qammod(reshape(index,[],1),M); % 作M-ary調變=>星座圖
x=kmod.*modulation;
%******** IFFT
imot = ifft(x.');
%******** Guard interval insertion
ofdm = [imot(N-cp+1:N) imot]; % AD(AllData)-CP+1=OFDM symbol
ol = length(ofdm); % OFDM symbol 長度
% Channel
%******** Multipath Rayleigh Channel
path = 1; % 通道數
h1 = (sqrt(0.5)*(randn(1,path)+sqrt(-1)*randn(1,path)));
h1 = h1/norm(h1);
con = conv(ofdm,h1); % convolution
con = con(1:end-(path-1)); % L+M-1=end => L=end-(M-1)
%******** AWGN addition
ch = awgn(con,snr+10*log10(bit),'measured');
% Receiver
%******** Guard interval removal
cht = ch.'; % Serial to parallel
rcp = cht(cp+1:ol); % rempve CP
%******** FFT
frcp = fft(rcp,N);
cr = fft(h1,N); % channel response
%******** One Tap Equalizer
pry = frcp./cr.'; % equalizer (*1/H)
%******** Demoduration
pry = pry./kmod;
de = qamdemod(pry,M);
dedata = de2bi(de,'left-msb',bit);
%******** Parallel to serial conversion
pts = reshape(dedata,1,N*bit);
%******** Bit Error Rate (BER)
[num,ber(l,s+1)] = biterr(pts,bi); % [錯誤數,錯誤率]
s=s+1;
end
end
close(h)
%-------- Plot Constellation diagram
%%
%%
%------- Plot BER to SNR Performance
avber=sum(ber)/loop;
figure(2);
semilogy(snrindex,avber,'-bd');
grid on;
legend('16QAM,CP=64');
xlabel('SNR(dB)');
ylabel('BER');
axis([0 25 10^(-6) 10^(0)]);
hold on;
%%
N = 256; % subcarriers個數
ofs = 1; % 一個迴圈傳送幾個OFDM symbol
cp =32 ; % CP length
% M-ary QAM modulation
M = 16;
bit = log2(M); % 一個symbol傳送的bit數
% Normalization Factor "Kmod" Modulation Scheme Value
% kmod here is a normalization constant or scale factor applied to the hard decision based on the sub-carrier constellation being used,such as BPSK, QPSK, 16-QAM or 64-QAM such that each of the sub-carriers have equal power.
% kmod=1; % BPSK
% kmod=1/sqrt(2); % QPSK
kmod=1/sqrt(10); % 16QAM
% kmod=1/sqrt(42); % 64QAM
msnr = 25;
snrindex = 0:1:msnr;
loop = 100; % 迴圈數
h = waitbar(0,'Please wait...');
for l=1:loop
s=0;
waitbar(l/loop);
for snr=snrindex
% transmitter
%******** Binary Sequence generation
bi = randint(1,bit*N*ofs); % 隨機產生二位元訊號10
%******** Serial to parallel conversion
stp = reshape(bi,N,bit*ofs); % 轉成N*(bit*ofs)矩陣
%******** QAM modulation
index = bi2de(stp,'left-msb'); % 將symbol轉成index ex:00 0,01 1,10 2,11 3
modulation = qammod(reshape(index,[],1),M); % 作M-ary調變=>星座圖
x=kmod.*modulation;
%******** IFFT
imot = ifft(x.');
%******** Guard interval insertion
ofdm = [imot(N-cp+1:N) imot]; % AD(AllData)-CP+1=OFDM symbol
ol = length(ofdm); % OFDM symbol 長度
% Channel
%******** Multipath Rayleigh Channel
path = 1; % 通道數
load channel.mat;
% h1 = (sqrt(0.5)*(randn(1,path)+sqrt(-1)*randn(1,path)));
h1 =channel;
%h1=[-0.3084+0.5368i,0.0356-0.5375i,-0.0772-0.1704i,-0.1242-0.0886i,-0.0270+0.0481i,0.0297-0.0053i,-0.0065-0.0001i,-0.0047-0.0127i];
con = conv(ofdm,h1); % convolution
con = con(1:end-(path-1)); % L+M-1=end => L=end-(M-1)
%******** AWGN addition
ch = awgn(con,snr+10*log10(bit),'measured');
% Receiver
%******** Guard interval removal
cht = ch.'; % Serial to parallel
rcp = cht(cp+1:ol); % rempve CP
%******** FFT
frcp = fft(rcp,N);
cr = fft(h1,N); % channel response
%******** One Tap Equalizer
pry = frcp./cr.'; % equalizer (*1/H)
%******** Demoduration
pry = pry./kmod;
de = qamdemod(pry,M);
dedata = de2bi(de,'left-msb',bit);
%******** Parallel to serial conversion
pts = reshape(dedata,1,N*bit);
%******** Bit Error Rate (BER)
[num,ber(l,s+1)] = biterr(pts,bi); % [錯誤數,錯誤率]
s=s+1;
end
end
%-------- Plot Constellation diagram
%%
figure(1);
plot(real(pry),imag(pry),'*');
hold on ;
xlabel('I-ch');
ylabel('Q-ch');
%%
close(h)
%------- Plot BER to SNR Performance
avber=sum(ber)/loop;
figure(2);
semilogy(snrindex,avber,'-r');
grid on;
legend('16QAM CP = 64','16QAM,CP=32');
xlabel('SNR(dB)');
ylabel('BER');
axis([0 25 10^(-6) 10^(0)]);
OFDM.rar_ifft
版权申诉
189 浏览量
2022-09-23
00:57:02
上传
评论
收藏 2KB RAR 举报
![avatar](https://profile-avatar.csdnimg.cn/d600a32f29294db1a3be82ec9708491a_weixin_42651887.jpg!1)
weixin_42651887
- 粉丝: 82
- 资源: 1万+