36 lines
1.1 KiB
Matlab
36 lines
1.1 KiB
Matlab
% Define parameters
|
|
n = 1; % Define the memory length n+1 (e.g., 1 for duobinary, 2 for tribinary, 3 for tetrabinary)
|
|
M = 4; % Modulation order (e.g., 4 for QPSK)
|
|
d = randi([0 M-1], 1, 100); % Example input sequence d(k)
|
|
|
|
% Pre-coding: bPR(k) = (d(k) - bPR(k-1)) mod M
|
|
bPR = zeros(size(d));
|
|
%bPR(1) = d(1); % Initial condition for pre-coding
|
|
|
|
for k = 1:numel(d)-1
|
|
bPR(k+1) = mod( d(k) - bPR(k), M );
|
|
end
|
|
|
|
% Polybinary coding: Convolution with (1 + z^-1)^n
|
|
% Generate coefficients for the polybinary filter (1 + z^-1)^n
|
|
coeff = ones(1, n+1); % Initialize coefficients with ones
|
|
|
|
for i = 2:n+1
|
|
coeff(i) = nchoosek(n, i-1); % Binomial coefficient for expansion
|
|
end
|
|
|
|
% Apply convolution to get the polybinary coded sequence
|
|
polybinary_data = conv(bPR, coeff, "same");
|
|
|
|
% Modulo operation for decoding to stay within M levels
|
|
d_reconstructed = mod(polybinary_data, M);
|
|
|
|
% Check if reconstruction is correct
|
|
reconstruction_success = isequal(d, d_reconstructed);
|
|
|
|
figure(111)
|
|
hold on
|
|
stairs(d_reconstructed)
|
|
stairs(d)
|
|
|
|
disp(['Reconstruction success: ', num2str(reconstruction_success)]); |