1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
| %--------OFDM TRANSMISSION CHAIN---------%
close all;
clearvars;
% nfft and nsymbols
n_sc = 512; % number of subcarriers
n_symbol = 1000; % number of symbols
ofdmBW = 26.2 * 10 ^ 6 ; % OFDM bandwidth
Fs = 75 * 10 ^ 6;
Ts = 1/Fs;
% t = 0:1/Fs:1-1/Fs;
%---modulation type---%
M = 4; % QPSK
k = log2(M);
n_cp = 16;
% channel type
chan = 'awgn';
EbNo = 0:50;
SNR = EbNo + 10*log10(k)+10*log10(n_sc/(n_sc+n_cp));
EbNoLin = 10.^(EbNo/10);
% generating data
x_source = randi([0,1],n_symbol*n_sc*k,1);
% multipath channel
% % h = [0.5*exp(1i*pi/2)];% 0.2 0.4];
h = [0.8 0.5 0.4];
% tx = [1 2 3]*1e-6;
n = length(h);
tx = [0:n-1]%*1e-9;
% delay_rms = sqrt(sum((h.^2).*(tx.^2))/sum(h.^2)-(sum((h.^2).*tx)/sum(h.^2)).^2)
% Bc=1/(50*delay_rms)
figure (2)
stem(tx,h)
xlim([0 20])
%insertion zero
h1 = [h,zeros(1,528-n)];
hF = (fft(h1,528));
% [h,f]=freqz(h1);
% plot(f,abs(h)) % réponse du canal
% transfer fuction
h2 = [h,zeros(1,512-n)];
hf2 = (fft(h2,512));
% channel = randn(6,1);
% stem(10*log10(abs(channel)))
% hF = fft(channel,512);
%modulation
for i = 1:length(EbNo)
x_conversion = bi2de(reshape(x_source,k,numel(x_source)/k).','left-msb');
x_modulation = pskmod(x_conversion,M,pi/4,'gray');
% figure (1)
% plot(real(x_modulation), imag(x_modulation),'o');
% serial to parallel
x_sp = reshape(x_modulation,n_sc,numel(x_modulation)/n_sc).';
%IFFT
x_ifft = ifft(x_sp,n_sc,2);
%cyclic p ofdm_signal =[ x_Time( N-Ncp + 1: N) x_Time];
x_cp = [x_ifft(:,n_sc-n_cp+1:n_sc),x_ifft];
%%
%convolution using fft frequency domain
X_cp = fft(x_cp); % passe en freq
for m = 1 : size(x_cp,1)
Y(m,:) = hF.*X_cp(m,:);
end
x_conv = ifft(Y);
% x_conv = convn(h1,x_cp);
%add noise
bruit = awgn(x_conv,SNR(i),'measured')- x_cp;
%awgn
y_awgn = x_conv+bruit;
%remove CP
y_cp = y_awgn(:,n_cp+1:end);
%fft
y_fft = fft(y_cp,n_sc,2);
% plot(real(y_fft(1:10,:)),imag(y_fft(1:10,:)),'o')
% egalisation
for m = 1 : size(x_cp,1)
%y_egal(m,:) = y_fft(m,:);
y_egal(m,:) = y_fft(m,:)./hf2;
end
% y_egal=y_fft./hf2;
% parallel to serial
y_ps = reshape(y_fft.',numel(y_fft),1);
%demodulation
y_demodulation = pskdemod(y_ps,M,pi/4,'gray');
y_conversion = de2bi(y_demodulation,'left-msb');
y_sortie = reshape(y_conversion.',numel(y_conversion),1);
%BER counter
ber(i) = sum(x_source~=y_sortie)/numel(x_source);
end
%plot
% BER = berawgn(EbNo,'psk',M,'nondiff');
% ber théorique
for i = 1:length(EbNo)
berth(i)=0;
for w =1:n_sc
EbNow=10*log10(abs(hf2(w))^2)+SNR(i)-10*log10(k)+10*log10(n_sc/(n_sc+n_cp));
%EbNow=10*log10(abs(0.5^2))+SNR(i)-10*log10(k)+10*log10(n_sc/(n_sc+n_cp));
berth(i)=berth(i)+0.5*erfc(sqrt(10.^(EbNow/10)));
end
berth(i)=berth(i)/n_sc;
end
BERawgn = berawgn(EbNo,'psk',M,'nondiff');
figure(5)
semilogy(EbNo,BERawgn,EbNo,berth,EbNo,ber,'r - o','linewidth',2);
title(' BER Vs EbNo for OFDM with QPSK modulation over Rayleigh channel');
xlabel(' Eb/ N0 (dB)');
ylabel(' BER');
legend(' awgn','theoretical Ray',' simulated');
% xlabel('EbNo(dB)')
% ylabel('BER')
axis([EbNo(1) EbNo(end) 1e-5 1])
% axis([EbNo(1) EbNo(end) 0 0])
ber |
Partager