-
Notifications
You must be signed in to change notification settings - Fork 0
/
OFDM_Modulator_and_Demodulator.m
63 lines (53 loc) · 1.98 KB
/
OFDM_Modulator_and_Demodulator.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
% OFDM_Modulator_and_Demodulator.md
function out = OFDM_Modulator_P(mappedSignal, NumFFT, CPlen, NumSC)
% Calculate block size
block_size = size(mappedSignal, 1) * size(mappedSignal, 2) / NumSC;
% Serial to Parallel conversion
S2P = reshape(mappedSignal, block_size, NumSC);
Sub_carrier = S2P; % Serial to Parallel conversion
% IFFT Block
ifft_Subcarrier = [];
for j = 1:NumSC
if(NumFFT > 0)
ifft_Subcarrier(:,j) = ifft(S2P(:,j), NumFFT);
end
if(NumFFT == 0)
ifft_Subcarrier(:,j) = ifft(S2P(:,j));
end
end
% Add Cyclic Prefix
cp_start = block_size - CPlen;
cyclic_prefix = [];
Append_prefix = [];
for i = 1:NumSC
for j = 1:CPlen
cyclic_prefix(j, i) = ifft_Subcarrier(j + cp_start, i);
end
Append_prefix(:, i) = vertcat(cyclic_prefix(:, i), ifft_Subcarrier(:, i));
end
% Conversion to serial stream for transmission
[rows_Append_prefix, cols_Append_prefix] = size(Append_prefix);
len_ofdm_data = rows_Append_prefix * cols_Append_prefix;
% OFDM signal to be transmitted
out = reshape(Append_prefix, 1, len_ofdm_data);
end
function out = OFDM_Demodulator_P(receivedSignal, NumFFT, CPlen, NumSC)
% Calculate block size
rxBlock_size = size(receivedSignal, 1) * size(receivedSignal, 2) / NumSC;
% Remove cyclic Prefix
rx_Subcarrier = reshape(receivedSignal, rxBlock_size, NumSC);
rx_Subcarrier(1:CPlen, :) = [];
% FFT Block
fft_data = [];
for w = 1:NumSC
if(NumFFT > 0)
fft_data(:, w) = fft(rx_Subcarrier(:, w), NumFFT);
end
if(NumFFT == 0)
fft_data(:, w) = fft(rx_Subcarrier(:, w));
end
end
% Conversion to serial and demodulation
size_serial_data = [size(fft_data, 2) * size(fft_data, 1), 1];
out = reshape(fft_data, size_serial_data(1), 1);
end