%% FBMC/OQAM
%% FBMC-AWGN: BER verus SNR for FBMC/OQAM using polyphase structure
%%------------------------------------------------------------------------------------------------------------%%
%
% "Prototype filter and filter bank structure"
% FBMC/OQAM with noise
%%------------------------------------------------------------------------------------------------------------%%
clc
clear all;
%%------------------------------------------------------------------------------------------------------------%%
% Intialization
%%------------------------------------------------------------------------------------------------------------%%
nd=2; %number of OQAM sample per symbols (not change)
M=512;% number of sub-channels
K=4; % overlapping factor(good K=4)
lp=K*M-1;% prototype filter length
SNR= 0:5:30; % signal to noise ratio
frame=100; % Number of simulation loops
Rate0= zeros(1, length(SNR));
%%------------------------------------------------------------------------------------------------------------%%
% Design of Prototype Filter
%%------------------------------------------------------------------------------------------------------------%%
% low pass filter FIR
y=[1 0.97195983 sqrt(2)/2 0.23514695 ]; % coefficient of filter when K=4
yy=[1 0.911438 0.411438];% coefficient of filter when K=3
yyy=[1 sqrt(2)/2];% coefficient of filter when K=2
u=lp-1;
s=2*pi/(K*M);
for m=0:u-1
r=m+1;
p(m+1)=y(1,1)-2*y(1,2)*cos(r*s)+2*y(1,3)*cos(2*r*s)-2*y(1,4)*cos(3*r*s);% prototype filter equation K=4
%p(m+1)=yy(1,1)-2*yy(1,2)*cos(r*s)+2*yy(1,3)*cos(2*r*s); % prototype filter equation K=3
%p(m+1)=yyy(1,1)-2*yyy(1,2)*cos(r*s); % prototype filter equation K=2
%p(m+1)=1; % prototype filter equation for OFDM
end
p=[0 p 0]; % extra delay sample (z^-2)
ty=p; %
%%------------------------------------------------------------------------------------------------------------%
%%------------------------------------------------------------------------------------------------------------%%
%%------------------------------------------------------------------------------------------------------------%%
% Transmitter
%%------------------------------------------------------------------------------------------------------------%%
for ebn0=1:length(SNR)
ebn0
for iii=1:frame
% Data generation
q=2;% binary data
m=4;% modulation level
In_Data=randi([0 q-1],M,1);% random input data M x 1
% OQAM Modulation
[OQAM_In_Data]=OQAM_preprocessing(In_Data,m,M); % OQAM modulation M x nd
%%------------------------------------------------------------------------------------------------------------%%
% Transform Block
%%------------------------------------------------------------------------------------------------------------%%
%% beta carrier
for k=0:M-1
B(k+1)=(-1)^k*exp(-1*i*2*pi*k*(lp-1)/(2*M));
end
B=reshape(B,M,1);
% ch1=Bi*Di beta*data
for k=0:M-1
CHD1(k+1,:)=B(k+1)*OQAM_In_Data(k+1,:);
end
%% 'ifft'
CHD2=ifft(CHD1);
% figure(2)
% spe_test=fftshift(CHD1);
% spe_test_1=20*log10(abs(CHD1(:,1)));
% plot(1:1:512,spe_test_1(:,1));
%%------------------------------------------------------------------------------------------------------------%%
% Polyphase Filters SFB
%%------------------------------------------------------------------------------------------------------------%%
% polyphase filters SFB
for k=0:M-1
j(k+1,:)=p(k+1+M*(0:K-1));%% Aq coefficients
ss=upsample(j(k+1,:),2);
CHD3(k+1,:)=cconv(CHD2(k+1,:),ss,nd);%% ch2*Aq
end
% figure(3)
% spe_test=fftshift(fft(CHD3));
% spe_test_1=20*log10(abs(spe_test(:,1)));
% plot(1:512,spe_test_1(:,1));
%%------------------------------------------------------------------------------------------------------------%%
% P/S Conversion
%%------------------------------------------------------------------------------------------------------------%%
% Up sample and delay chain
% instead of up sample and delay chain
[a b]=size(CHD3);
CHD4=reshape(CHD3,a*b,1);
%%------------------------------------------------------------------------------------------------------------%%
% Channel Effect
%%------------------------------------------------------------------------------------------------------------%%
%% channel effects
CHD5=reshape(CHD4,a*b,1);
figure(2)
spe_test=fftshift(abs(fft(CHD5)));
spe_test_1=10*log10(spe_test);
plot(-length(spe_test_1)/2:length(spe_test_1)/2-1,spe_test_1(:,1));
%%
CHD6=CHD5;
% CHD7 = awgn(CHD6,ebn0,'measured');
% EbN0 = 10^(SNR(ebn0)/10);
% EsN0 = EbN0*2;
% Es=1; %QPSK符号的能量
% N0 = Es/EsN0;
% sigma = sqrt(N0);
% noise=sigma*randn(size( CHD6, 1),size( CHD6, 2));
signal_in_dB=10*log10(std(CHD6)^2);
noise_in_dB=signal_in_dB-SNR(ebn0);
noise=(10^(noise_in_dB/10)^(1/2))*randn(size( CHD6, 1),size( CHD6, 2));
CHD7=CHD6+noise;
%%------------------------------------------------------------------------------------------------------------%%
% Receiver
%%------------------------------------------------------------------------------------------------------------%%
%%------------------------------------------------------------------------------------------------------------%%
% S/P Conversion
%%------------------------------------------------------------------------------------------------------------%%
CHD7=reshape(CHD7,a,b);
%%------------------------------------------------------------------------------------------------------------%%
% Polyphase Filters AFB
%%------------------------------------------------------------------------------------------------------------%%
for k=0:M-1
ee=upsample(j(M-k,:),2);
CHD8(k+1,:)=cconv(CHD7(k+1,:),ee,nd);
end
%%------------------------------------------------------------------------------------------------------------%%
% Transform Block
%%------------------------------------------------------------------------------------------------------------%%
% 'fft'
CHD9=fft(CHD8);
% Beta demodulator
for k=0:M-1
BB(k+1)=(-1)^k*exp(1*i*2*pi*k*(lp-1)/(2*M));
end
BB=reshape(BB,M,1);
%
for k=0:M-1
CHD10(k+1,:)=BB(k+1)*CHD9(k+1,:);
end
%%------------------------------------------------------------------------------------------------------------%%
%
%%------------------------------------------------------------------------------------------------------------%%
%%------------------------------------------------------------------------------------------------------------%%
%OQAM Demodulation
[Out_Data]=OQAM_postprocessing(reshape(CHD10,M,nd),m,M);
%%------------------------------------------------------------------------------------------------------------%%
% BER
%%-----------------