I keep getting a "convenc" error. Line 88. Could be "varargin" missing argument? Not sure.

2 visualizzazioni (ultimi 30 giorni)
clc
clear all
%% initialization
para=52;
noc=52;
fftlen=64;
gi=0;
nd=128; % number of OFDM frames to send
nb=para*nd/2; % total bits to send
np=1; % number of paths
% snr=50; %dB
tblen=7; % traceback length for viterbi
trellis = poly2trellis(3,[7 5]);
allsnr=[20:40];
ii=0;
msg = randi(1,nb); % generate message stream.
for snr=allsnr
ii=ii+1; % keep track of the loop
%% transmitter
% convolutional encoding
encoded = convenc(msg,trellis,);
% serial to parallel data
encodedFrames=reshape(encoded,para,nd);
modulated=encodedFrames*2-1;
% mapping
crmapped(2:27,:) = modulated(1:26,:);
crmapped(39:64,:)= modulated(27:52,:);
%% ifft
transmitted = ifft(crmapped);
%% Fading channel model
% start fading model. This is the part you will modify or complete
fd = 50; % Doppler shift
M = 2; % Number of delayed signal paths
Mdelay = [1 3]; % delay of each delayed signal
K=4; % rice factor
dt = 1/250000; % minimum time resolution
N = 6; % number of oscillators for Jake’s fading model
for sc=1:fftlen, % sc is the subcarrier number
phi = rand*1000; % fading counter
faded(sc,:) = fadingModel(transmitted(sc,:),fd,M,Mdelay,K,dt,N,phi);
% function to build
end
% end fading model
%% ------------------------------------
% AWGN
noisyFaded = awgn(faded,snr);
% noisyFaded=toChannel;
%% receiver
% fft
received = fft(noisyFaded);
% channel estimation
tr0 = crmapped(:,1); % original "training" data;
tr1 = received(:,1); % training symbol
h = tr0./tr1; % reverse rotation
H = h*ones(1,nd); % extend the reverse rotation matrix to cover all symbols
compensated=received.*H; % signal compensation
% compensated = received; % disable signal compensation
% demapper
crdemapped = zeros(para,nd);
crdemapped(1:26,:) = compensated(2:27,:);
crdemapped(27:52,:) = compensated(39:64,:);
% demodulate
demodulated = double(crdemapped>0);
% parallel to serial
demapped = reshape(demodulated,1,[]);
% decoder
decoded = vitdec(demapped,trellis,tblen,'trunc','hard'); % viterbi decoder
sdecoded = decoded;
% calculate ber
[be(ii) ber(ii)] = biterr(msg,decoded)
end
% plot ber
plot(allsnr,ber);
title('BER vs. SNR')
xlabel('SNR')
ylabel('BER')
  1 Commento
Jan
Jan il 27 Feb 2023
Please post the complete error message. Then the readers do not have to count, where "line 88" is.

Accedi per commentare.

Risposte (2)

Jan
Jan il 27 Feb 2023
The line is incomplete:
encoded = convenc(msg,trellis,);
% ^ ???
  1 Commento
Marcel
Marcel il 27 Feb 2023
% Check msg
outType = class(msg); % for output data type
if ~isempty(msg)
validateattributes(msg, {'numeric', 'logical'}, ... <--- Line 88
{'vector', 'binary'}, 'convenc', 'MSG');
coder.internal.errorIf(mod(length(msg), k) ~=0, ...
'comm:convenc:InvalidMsgLength');
end

Accedi per commentare.


Steven Lord
Steven Lord il 27 Feb 2023
If you're calling the convenc function from Communications Toolbox, the section of that documentation page that describes the msg input argument states that its data type must be either double or logical and it must be a vector of binary values. The code you've posted does call it with a double array, but the line of code you've used to create that array:
nb = 4; % Added so this code runs
msg = randi(1,nb); % generate message stream.
creates an nb-by-nb matrix of values where each element is an integer in the range [1, 1]. Unless nb is 1, msg is not a vector of 0's and/or 1's.
msg
msg = 4×4
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
You could make this return a 1-by-nb vector by adding one input to randi listing the range of values from which you want to generate the random data.
msg = randi([0 1], 1, nb)
msg = 1×4
0 1 0 1

Categorie

Scopri di più su Link-Level Simulation in Help Center e File Exchange

Prodotti


Release

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by