% FBMC Modulator
% Frame, Number of "FBMC symbols"
clear all;
close all;
clc;
N=128;
Frame=10;
% Prototype Filter For FBMC
M=N;% number of sub-channels
K=4; % overlapping factor
lp=K*M;% prototype filter length
yyy=[1 sqrt(2)/2];% coefficient of filter when K=2
s=2*pi/(K*M);
p1 = zeros(1,lp);
p2 = zeros(1,lp);
p3 = zeros(1,lp);
for r = 1:lp
p3(r)=yyy(1,1)-2*yyy(1,2)*cos(r*s); % prototype filter equation K=2
end
[v2,~]=max(p3);
p3 = p3/v2;
h = p3;
figure(1);
plot(h);
title ('Filter Impulse response');
%% Transmitter
% Initialization for transmission
y=zeros(1,4*N+(Frame-1)*N);
x=zeros(N,Frame+6);
s = zeros(N,Frame);
% s(:,1) = sign(randn(N,1)) + 1i.* sign(randn(N,1));
for ttx = 1:Frame
% % OQPSK Modulator: adjacent subcarriers are orthogonal to each other
% rxI = sign(randn(N/2,1));
% rxQ = 1i.*sign(randn(N/2,1));
% s(1:2:end,ttx) = rxI(1:end) + [1i ; rxQ(1:end-1)];
% s(2:2:end,ttx) = rxI(1:end) + rxQ(1:end);
% % adjacent frames are orthogonal to each other
% s(:,ttx) = exp(1i.*(ttx-1).*pi./2).*s(:,1);
% % QPSK
s(:,ttx) = (sign(randn(N,1)) + 1i.* sign(randn(N,1)));
xtime=ifft(s(:,ttx)); % [ 0 0 0 x1 x2 .. x10 0 0 0 ]
x(:,3+ttx)=xtime./sqrt(N);%4:Frame+3
end
rxx = reshape(x,1,[]);
for ntrametx=1:(Frame+3)
xf = rxx(1,1+(ntrametx-1)*N:(3+ntrametx)*N);
txmult = xf .* h;
y(1+(ntrametx-1)*N:ntrametx*N) = txmult(1:N)+txmult((N+1):(2*N))+txmult((2*N+1):(3*N))+txmult((3*N+1):(4*N));
end
signal = y;
%% Receiver
rx=zeros(N,Frame);
hrx = [fliplr(h(1:N)) fliplr(h(1+N:2*N)) fliplr(h(1+2*N:3*N)) fliplr(h(1+3*N:4*N)) ];
sdemod = zeros(N,Frame);
for RxN=1:(Frame-1)
% Transmitted signal
rxmult = signal(1+(RxN-1)*N:(3+RxN)*N) .* hrx ;
sestn=fft(rxmult(1:N)+rxmult((N+1):(2*N))+rxmult((2*N+1):(3*N))+rxmult((3*N+1):(4*N)));
% QPSK equalizing
[v,i] = max(real(sestn));
sest=sestn/v;%/0.6863;
sdemod(:,RxN) = sest;
end
figure(2)
plot(s,'or');
hold on
plot(sdemod(:,2:end-1),'xk');
title('FBMC QPSK, o transmitted, x received');