-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathOFDM_Passband.m
120 lines (91 loc) · 2.76 KB
/
OFDM_Passband.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
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
%% OFDM Passband 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('txtDocs.mat','moby');
% cAr = moby;
% % Load 32 char string
% load('Test_Strings.mat','QPSKstr'); % This will allow for a single OFDM char
% cAr = double(QPSKstr(1:end-3));
% %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);
%% 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?
%% D/A conversion - can take a while for large data
os = 1; % Over Sample = (Fs/Rs)
xt = interp(xn,os);
figure(1)
stem(0:length(xn)-1,xn)
figure(2)
plot(0:length(xt)-1,xt)
% Check signal's spectrum s.t. it is band limited
Xf = fftshift(fft(xt));
figure(3)
plot((0:length(Xf)-1)-length(Xf)/2,sqrt(Xf.*conj(Xf)))
%% Power Amplification
%%
% %Bandpass Modulation - from SAM proj. Fall 2012
% carrier = sqrt(Rb/Fs)*cos(2*pi*Fc*t);
% bp_op = bb_op*carrier;
%% %%%%%%%%%%%%%%%%%% Channel %%%%%%%%%%%%%%%%%%%%%
% Average TX power
Pt = mean(xt.*conj(xt)); % E{|x[i]|^2}
% Rayleigh (block) fading with AWGN
h = 1; % Channel Gain
SNR_dB = 12.598;
SNR = 10^(SNR_dB/10);
Es = 2; % Symbol Energy for QPSK
Pn = (h*Pt)/SNR; % Average Noise Power
noise = sqrt(Pn/Es).*(randn(1,length(xt))+1i*randn(1,length(xt)));
NoB = mean(noise.*conj(noise)); % Measured Noise Power
%% %%%%%%%%%%%%%%%%% Receiver %%%%%%%%%%%%%%%%%%%%%%
y = h.*xt + noise;
%% A/D conversion
yn = y(1:os:end); % Decimate by factor of 10
% Assume receiver knows xDim(2)
yp = reshape(yn,xDim(1),xDim(2));
%% FFT then Parallel to Serial
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
%% Show Symbol Constellation
figure(4)
QPSK.Constellation(ySym, SNR_dB);
%% De-map symbols and convert to binary
[bin2, symDat2] = QPSK.sym2bin(ySym);
%% Calculate SER & BER
SER = sum(symDat2 ~= symDat)/length(symDat);
BER = sum(binDat ~= bin2)/length(binDat);
% %% Convert to ASCII character data - can take a while for large data
%
% dOut = bin2ascii(bin2)';
%
% %% Number of error characters
%
% ChER = sum(dOut ~= cAr)/length(dOut);