forked from kfoysalhaque/m3MIMO
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqpsk_demodulation.m
More file actions
43 lines (39 loc) · 1.66 KB
/
qpsk_demodulation.m
File metadata and controls
43 lines (39 loc) · 1.66 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
41
42
43
% function [rx_bits, corrected_bits] = qpsk_demodulation(rx_symbols)
% % QPSK Demodulation function with Hamming decoding
% % Input: rx_symbols - Received QPSK symbols
% % Output: rx_bits - Demodulated bits
% % corrected_bits - Corrected bits after Hamming decoding
%
% % Demodulate QPSK symbols
% rx_bits_I = real(rx_symbols) > 0; % Demodulate I-channel: 1 -> 1, 0 -> 0
% rx_bits_Q = imag(rx_symbols) > 0; % Demodulate Q-channel: 1 -> 1, 0 -> 0
%
% % Combine demodulated bits
% rx_bits = zeros(1, 2 * length(rx_symbols));
% rx_bits(1:2:end) = rx_bits_I;
% rx_bits(2:2:end) = rx_bits_Q;
%
% % Ensure the received bits length is a multiple of 7 for Hamming(7,4) decoding
% n = length(rx_bits);
% if mod(n, 7) ~= 0
% error('Received bits length must be a multiple of 7');
% end
%
% % Decode received bits using Hamming code
% corrected_bits = decode(rx_bits, 7, 4, 'hamming/binary');
% end
function [rx_bits, corrected_bits] = qpsk_demodulation(rx_symbols)
% QPSK Demodulation function with Hamming decoding
% Input: rx_symbols - Received QPSK symbols
% Output: rx_bits - Demodulated bits
% corrected_bits - Corrected bits after Hamming decoding
% Demodulate QPSK symbols
rx_bits_I = real(rx_symbols) > 0; % Demodulate I-channel: 1 -> 1, 0 -> 0
rx_bits_Q = imag(rx_symbols) > 0; % Demodulate Q-channel: 1 -> 1, 0 -> 0
% Combine demodulated bits
rx_bits = zeros(1, 2 * length(rx_symbols));
rx_bits(1:2:end) = rx_bits_I;
rx_bits(2:2:end) = rx_bits_Q;
% Decode received bits using Hamming code
corrected_bits = decode(rx_bits, 7, 4, 'hamming/binary');
end