-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathOFDM_Baseband.m
95 lines (76 loc) · 2.19 KB
/
OFDM_Baseband.m
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
%% OFDM Baseband code
% Process:
% - input text data
% - convert text to binary
% - convert binary to symbol
% - OFDM idft
clear all; close all; clc
% Load Function libraries
QPSK = QPSK_lib;
OFDM_lib;
%% Input text data
% Load text file
fid = fopen('usdeclar.txt');
cAr = fread(fid,inf); % Read as ASCII decimal characters
fclose(fid);
% % Load 32 char string
% load('Test_Strings.mat','QPSKstr'); % This will allow for a single OFDM char
% cAr = double(QPSKstr);
% %cAr = double('A');
%% Convert to binary
binDat = Binary_cnvrt(cAr);
%% Map to QPSK symbol
symDat = QPSK.bin2symb(binDat,1); % symbols are [1 -1 j -j]
% correspond to [0 180 90 270] degrees
%% OFDM symbols
N = 128;
O_data = idft(symDat,N);
%% Cyclic Prefix
% cpS = floor(N*0.25); % CP size
% xp = [O_data(end-cpS+1:end,:); O_data]; % Parallel data
% No CP
xp = O_data;
%% Parallel to Serial
xDim = size(xp); % Matrix dimensions
% xDim(1): OFDM symbol length
% xDim(2): # of symbols
xn = reshape(xp,1,xDim(1)*xDim(2));
n = 1:length(xn);
% pad zeros between each sample, then use Nyquist root cosine filter?
% Average TX power
Pt = mean(xn.*conj(xn)); % E{|x[i]|^2}
%%
SNR_dB = 12.598;
SNR = 10^(SNR_dB/10);
%% %%%%%%%%%%%%%%%%%% Channel %%%%%%%%%%%%%%%%%%%%%
% Rayleigh (block) fading with AWGN
h = 1; % Channel Gain
% h = sqrt(1/2).*(randn(1)+1i*randn(1));
% Pn = Pt*(h.*conj(h))/SNR; % Average Noise Power
Pn = Pt/SNR; % Average Noise Power
noise = sqrt(Pn/2).*(randn(1,length(xn))+1i*randn(1,length(xn)));
%% %%%%%%%%%%%%%%%%% Receiver %%%%%%%%%%%%%%%%%%%%%%
y = h.*xn + noise;
%% FFT then Parallel to Serial
yp = reshape(y,xDim(1),xDim(2));
ySym = dft(yp,N);
% Assume Receiver knows the length of unencoded message
ySym = ySym(1:length(symDat)); % Remove extra data added from idft from TX
% yn = reshape(ySym,1,xDim(1)*xDim(2));
%% Show Symbol Constellation
figure(2)
QPSK.Constellation(ySym, SNR_dB);
%% De-map symbols and convert to binary
[bin2, symDat2] = QPSK.sym2bin(ySym);
%% Calculate SER & BER
SER = mean(symDat2 ~= symDat);
BER = mean(binDat ~= bin2);
%
% %% Convert to ASCII character data
%
% dOut = bin2ascii(bin2)';
%
% %% Number of error characters
%
% ChER = mean(dOut ~= cAr);
%% Compare STDev to Noise Variance