Index exceed matrix dimension!!

In the temp variable is having a index exceed matrix dimension, is there any solution?
close all; clear; clc;
semi_fig = figure();
semi_ax = axes('Parent', semi_fig);
hold(semi_ax, 'on')
for M = 2:4 % bit resolutions
Lavg=2^M; % average symbol length
nsym=500; % number of PPM symbols
Lsig=nsym*Lavg; % length of PPM slots
Rb=1e6; % bit rate
Ts=M/(Lavg*Rb); % slot duration
Tb=1/Rb; % bit duration
Dt =0.4;
Drms=Dt*Tb; % RMS delay spread
a=12*sqrt(11/13)*Drms;
nsamp=10; % samples per symbols
Tsamp=Tb/nsamp; % sampling time
K=30*nsamp; % number of channel taps
k=0:K;
h=((6*a^6)./(((k*Tsamp)+a).^7)); % channel impulse response
h=h./sum(h);
Tx_filter = ones(1,nsamp);
Rx_filter = fliplr(Tx_filter);
c = conv(Tx_filter,h);
c = conv(c,Rx_filter);
delay = find (c==max(c));
if delay > nsamp;
hi(1) = c(delay-nsamp);
else hi(1) = 0;
end
hi = [hi(1) c(delay:nsamp:end)];
hi = hi/sum(hi);
EbN0=0:12; % energy per slot
EsN0=EbN0+10*log10(M); % energy per symbol
SNR=10.^(EbN0./10);
for ii=1:length(EbN0)
PPM=generate_PPM(M,nsym);
Rx_signal = conv(PPM,hi);
Rx_signal = Rx_signal(2:nsym+1);
MF_out=awgn(Rx_signal,EsN0(ii)+3,'measured');
% hard decision decoding
Rx_PPM_th=zeros(1,Lsig);
Rx_PPM_th(find(MF_out>0.5))=1;
[No_of_Error(ii) ser_hdd(ii)]=biterr(Rx_PPM_th, PPM);
% soft decision decoding
PPM_SDD=[];
start=1;
finish=2^M;
for k=1:nsym
temp=MF_out(start:finish);
m=max(temp);
temp1=zeros(1,2^M);
temp1(find(temp==m))=1;
PPM_SDD=[PPM_SDD temp1];
start=finish+1;
finish=finish+2^M;
end
[No_of_Error(ii) ser_sdd(ii)]=biterr(PPM_SDD,PPM);
end
Tx_signal=rectpulse(PPM,nsamp); % Pulse shaping function (rectangular pulse)
channel_output=conv(Tx_signal,h); % channel output
eyediagram(channel_output, 3*nsamp);
axis([-0.5 0.5 0 1]);
% theoretical calculation
Pse_ppm_hard=qfunc(sqrt(M*2^M*0.5*SNR));
Pse_ppm_soft=qfunc(sqrt(M*2^M*SNR));
if(M==2)
semilogy(semi_ax, EbN0,(1/log2(M))*Pse_ppm_hard,'k-','linewidth',2);
semilogy(semi_ax, EbN0,(1/log2(M))*Pse_ppm_soft,'r-','linewidth',2);
elseif (M==3)
semilogy(semi_ax, EbN0,(1/log2(M))*Pse_ppm_hard,'k-X','linewidth',2);
semilogy(semi_ax, EbN0,(1/log2(M))*Pse_ppm_soft,'r-X','linewidth',2);
else
semilogy(semi_ax, EbN0,(1/log2(M))*Pse_ppm_hard,'k--','linewidth',2);
semilogy(semi_ax, EbN0,(1/log2(M))*Pse_ppm_soft,'r--','linewidth',2);
end
grid(semi_ax, 'on')
end
legend(semi_ax, 'M=2 (HDD)','M=2 (SDD)','M=3 (HDD)','M=3 (SDD)','M=4 (HDD)','M=4 (SDD)');
xlabel(semi_ax, 'Eb/N0, dB');
ylabel(semi_ax, 'Bit Error Rate');
title(semi_ax, 'Bit error probability curve for PPM modulation');
hold(semi_ax, 'off')
The generate_PPM code is
function PPM=generate_PPM(M,nsym)
% function to generate PPM
% 'M' bit resolution
% 'nsym': number of PPM symbol
PPM=[];
for i= 1:nsym
temp=randint(1,M); % random binary number
dec_value=bi2de(temp,'left-msb'); % converting to decimal value
temp2=zeros(1,2^M); % zero sequence of length 2^M
temp2(dec_value+1)=1; % placing a pulse according to decimal value
% note that in matlab index does not start from zero, so need to add 1;
PPM=[PPM temp2]; % PPM symbol
end
end

 Accepted Answer

Alex - is the error occurring in this block of code?
for k=1:nsym
temp=MF_out(start:finish);
m=max(temp);
temp1=zeros(1,2^M);
temp1(find(temp==m))=1;
PPM_SDD=[PPM_SDD temp1];
start=finish+1;
finish=finish+2^M;
end
If so, the problem could be because the indices in the interval start:finish exceed the dimensions of MF_out and so you will need a check before you access the elements in this array. Perhaps something like
for k=1:nsym
temp=MF_out(start:finish);
m=max(temp);
temp1=zeros(1,2^M);
temp1(find(temp==m))=1;
PPM_SDD=[PPM_SDD temp1];
start=finish+1;
finish=finish+2^M;
if finish > length(MF_out)
break;
end
end

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!