forked from kfoysalhaque/m3MIMO
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqpsk_modulation.m
More file actions
40 lines (35 loc) · 1.59 KB
/
qpsk_modulation.m
File metadata and controls
40 lines (35 loc) · 1.59 KB
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
% function [tx_symbols, encoded_bits] = qpsk_modulation(bits)
% % QPSK Modulation function with Hamming encoding
% % Input: bits - Input bits to be modulated
% % Output: tx_symbols - Modulated QPSK symbols
% % encoded_bits - Encoded bits with Hamming code
%
% % Ensure the input bits length is a multiple of 4 for Hamming(7,4) encoding
% n = length(bits);
% if mod(n, 4) ~= 0
% error('Input bits length must be a multiple of 4');
% end
%
% % Encode input bits with Hamming code
% encoded_bits = encode(bits, 7, 4, 'hamming/binary');
%
% % Generate QPSK symbols from encoded bits
% symbols_I = 2*encoded_bits(1:2:end) - 1; % Map bits to I-channel: 0 -> -1, 1 -> 1
% symbols_Q = 2*encoded_bits(2:2:end) - 1; % Map bits to Q-channel: 0 -> -1, 1 -> 1
%
% % Combine I and Q channel to form complex symbols
% tx_symbols = symbols_I + 1j * symbols_Q;
% end
function [tx_symbols, encoded_bits] = qpsk_modulation(bits)
% QPSK Modulation function with Hamming encoding
% Input: bits - Input bits to be modulated
% Output: tx_symbols - Modulated QPSK symbols
% encoded_bits - Encoded bits with Hamming code
% Encode input bits with Hamming code
encoded_bits = encode(bits, 7, 4, 'hamming/binary');
% Generate QPSK symbols from encoded bits
symbols_I = 2*encoded_bits(1:2:end) - 1; % Map bits to I-channel: 0 -> -1, 1 -> 1
symbols_Q = 2*encoded_bits(2:2:end+1) - 1; % Map bits to Q-channel: 0 -> -1, 1 -> 1
% Combine I and Q channel to form complex symbols
tx_symbols = symbols_I + 1j * symbols_Q;
end