clear; clc;
%load('ber0.mat');
t = cputime;
%% parameter
N = 128; % number of subcarrier
M = 4; % M - ary modulation
data_length = N * log2(M);
mapping_table = [-1+1j, -1-1j, 1+1j, 1-1j]; %/ sqrt(2); % gray mapping & normalization
%[1+1j, -1+1j, 1-1j, -1-1j]
%ber = zeros();
tic
%% 송신기
% code generation
source = randi([0 1], 1, data_length); %데이터 스트림 생성
source_frame = reshape(source, log2(M), N); % log2(M) bit 씩 쪼갬
source_parallel = source_frame.';
% modulation
source_bi = bi2de(source_parallel); % binary to decimal conversion
A = qammod(source_bi, 4);
%A = mapping_table(bi2de(source_parallel, 'left-msb')+1); % mapping
% IFFT
Sr = ifft(A,N)*sqrt(N);
for EbNodB = 0:10
err_count = 0;
Number = 0;
while err_count < 400
%% chanel noise
Eb=1;
No = (10^(-EbNodB/10))*Eb;
std_var = sqrt(No/2);
Rk = Sr + (std_var * (randn(size(Sr)) + 1j * randn(size(Sr))));
%% 수신기
y = fft(Rk, N) / sqrt(N);
%decision and demodulation
output_demod = qamdemod(y,4);
z = de2bi(output_demod);
z = z.';
%% 에러 카운트
Number = Number + 256;
errors = sum(sum(xor(z, source_frame)).');
err_count = err_count + errors;
end
ber(EbNodB+1) = err_count/Number;
ber
end
e = cputime - t
%% graph
index = [0:10];
semilogy(index, ber, 'o', 'Linewidth', 1.5);
grid on;
xlabel('Eb/No [dB]');
ylabel('BER');
legend('Theory', 'Simulation')
hold on;
评论0