I am getting some errors of a script that I try to run
36 views (last 30 days)
Show older comments
When I run below script
% Parameters
M = 16; % Modulation order
k = log2(M); % Bits per symbol
numBits = k * 2.5e5; % Total bits to process
sps = 4; % Samples per symbol (oversampling factor)
filtlen = 10; % Filter length in symbols
rolloff = 0.25; % Filter rolloff factor
% Generate random binary data
dataIn = randi([0 1], numBits, 1);
% Apply convolutional encoding
constrlen = [5 4]; % Code constraint length
genpoly = [23 35 0; 0 5 13]; % Generator polynomials
tPoly = poly2trellis(constrlen, genpoly);
dataEnc = convenc(dataIn, tPoly);
% Modulate using 16-QAM
dataSymbolsIn = bit2int(dataEnc, k);
dataMod = qammod(dataSymbolsIn, M);
% Apply raised cosine filtering
rrcFilter = rcosdesign(rolloff, filtlen, sps);
txSignal = upfirdn(dataMod, rrcFilter, sps, 1);
% Add AWGN (simulate noisy channel)
SNR_dB = 10; % Signal-to-noise ratio in dB
rxSignal = awgn(txSignal, SNR_dB, 'measured');
% Demodulate 16-QAM
dataSymbolsOut = qamdemod(rxSignal, M, 'OutputType', 'bit');
% Viterbi decoding
decodedData = vitdec(dataSymbolsOut, tPoly, 100, 'trunc', 'hard');
% Calculate bit error rate
bitErrors = biterr(dataIn, decodedData);
bitErrorRate = bitErrors / numBits;
fprintf('Bit Error Rate: %.4f\n', bitErrorRate);
I am getting below errors,
Error using vitdec (line 271)
Length of the input code vector must be a multiple of the number of bits in an
input symbol.
Error in test3 (line 34)
decodedData = vitdec(dataSymbolsOut, tPoly, 100, 'trunc', 'hard');
can someone help me to correct them
0 Comments
Answers (1)
Alberto Alvarez Polegre
on 17 Apr 2024 at 8:21
You forgot to include the filter at the receiver. Try this:
% Parameters
M = 16; % Modulation order
k = log2(M); % Bits per symbol
numBits = k * 2.5e5; % Total bits to process
sps = 4; % Samples per symbol (oversampling factor)
filtlen = 10; % Filter length in symbols
rolloff = 0.25; % Filter rolloff factor
% Generate random binary data
dataIn = randi([0 1], numBits, 1);
% Apply convolutional encoding
constrlen = [5 4]; % Code constraint length
genpoly = [23 35 0; 0 5 13]; % Generator polynomials
tPoly = poly2trellis(constrlen, genpoly);
dataEnc = convenc(dataIn, tPoly);
% Modulate using 16-QAM
dataMod = qammod(dataEnc,M,InputType='bit');
% Transmit filter
rrcFilter = rcosdesign(rolloff,filtlen,sps);
txSignal = upfirdn(dataMod,rrcFilter,sps);
% Add AWGN (simulate noisy channel)
SNR_dB = 10; % Signal-to-noise ratio in dB
rxSignal = awgn(txSignal, SNR_dB, 'measured');
% Receive filter
rxSignalFilt = upfirdn(rxSignal,rrcFilter,1,sps); % Apply receive filter
rxSignalFilt = rxSignalFilt(filtlen+1:end-filtlen); % Account for filter delay
% Demodulate 16-QAM
dataSymbolsOut = qamdemod(rxSignalFilt, M, 'OutputType', 'bit');
% Viterbi decoding
decodedData = vitdec(dataSymbolsOut, tPoly, 100, 'trunc', 'hard');
% Calculate bit error rate
bitErrors = biterr(dataIn, decodedData);
bitErrorRate = bitErrors / numBits;
fprintf('Bit Error Rate: %.4f\n', bitErrorRate);
0 Comments
See Also
Categories
Find more on PHY Components in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!