How to eliminate this error, Array indices must be positive integers or logical values?
Show older comments
Hi, I am getting this error
Array indices must be positive integers or logical values.
Error in untitled11 (line 43)
bwrmss = bandwidth(h)/sqrt(12);
Please resolve it. Following is my code
c = physconst('LightSpeed');
fc = 2.4e9;
pri = 2e-05;
fs = 100e+06;
Numtgts = 3;
tgtpos = zeros(Numtgts);
tgtpos(1,:) = [500 530 750];
tgtvel = zeros(3,Numtgts);
tgtvel(1,:) = [-60 20 40];
tgtrcs = db2pow(10)*[1 1 1];
tgtmotion = phased.Platform(tgtpos,tgtvel);
target = phased.RadarTarget('PropagationSpeed',c,'OperatingFrequency',fc, ...
'MeanRCS',tgtrcs);
radarpos = [0;0;0];
radarvel = [0;0;0];
radarmotion = phased.Platform(radarpos,radarvel);
txantenna = phased.IsotropicAntennaElement;
rxantenna = clone(txantenna);
code2 = comm.GoldSequence('FirstPolynomial','x^6+x+1', 'FirstInitialConditions',[ 0 0 0 0 0 1], 'SecondPolynomial','x^6 + x^5 + x^4 + x^3 + x^2 + x + 1', 'SecondInitialConditions',[0 0 0 0 0 1], 'Index',2, 'SamplesPerFrame',63);
gold_code = code2();
PRF = 50000; % Pulse repetition frequency in Hz
pulseWidth = 2e-8; % Pulse width in seconds
rangeRes = 3e8 * pulseWidth; % Range resolution in meters
h = zeros(length(gold_code ), length(tgtpos(1,:))); % Preallocate matrix for transmitted pulses
for i = 1:length(targets)
h(:,i) = [gold_code ; zeros(1, round(pulseWidth/code2.SamplesPerFrame*PRF)-length(gold_code ))];
end
sig = h()
disp(size(h));
bwrmss = mean(abs(h(:)))/sqrt(12);
Nr = length(sig);
bwrmss = bandwidth(h)/sqrt(12);
rngrms = c/bwrmss;
peakpower = 11e+03;
txgain = 20.0;
transmitter = phased.Transmitter( ...
'PeakPower',peakpower, ...
'Gain',txgain, ...
'InUseOutputPort',true);
radiator = phased.Radiator( ...
'Sensor',txantenna,...
'PropagationSpeed',c,...
'OperatingFrequency',fc);
channel = phased.FreeSpace( ...
'SampleRate',fs, ...
'PropagationSpeed',c, ...
'OperatingFrequency',fc, ...
'TwoWayPropagation',true);
collector = phased.Collector( ...
'Sensor',rxantenna, ...
'PropagationSpeed',c, ...
'OperatingFrequency',fc);
rxgain = 42.0;
noisefig = 1;
receiver = phased.ReceiverPreamp( ...
'SampleRate',fs, ...
'Gain',rxgain, ...
'NoiseFigure',noisefig);
Np = 128;
dt = pri;
cube = zeros(Nr,Np);
for n = 1:Np
[sensorpos,sensorvel] = radarmotion(dt);
[tgtpos,tgtvel] = tgtmotion(dt);
[tgtrng,tgtang] = rangeangle(tgtpos,sensorpos);
% Calculate Doppler frequency shift for each target
fd = (2 * tgtvel(1, :) * fc) / c;
sig = h();
[txsig,txstatus] = transmitter(sig);
txsig = radiator(txsig,tgtang);
txsig = channel(txsig,sensorpos,tgtpos,sensorvel,tgtvel);
tgtsig = target(txsig);
rxcol = collector(tgtsig,tgtang);
rxsig = receiver(rxcol);
cube(:,n) = rxsig;
end
imagesc([0:(Np-1)]*pri*1e6,[0:(Nr-1)]/fs*1e6,abs(cube))
xlabel('Slow Time {\mu}s')
ylabel('Fast Time {\mu}s')
axis xy
ndop = 128;
rangedopresp = phased.RangeDopplerResponse('SampleRate',fs, ...
'PropagationSpeed',c,'DopplerFFTLengthSource','Property', ...
'DopplerFFTLength',ndop,'DopplerOutput','Speed', ...
'OperatingFrequency',fc);
matchingcoeff = getMatchedFilter(h);
[rngdopresp,rnggrid,dopgrid] = rangedopresp(cube,matchingcoeff);
imagesc(dopgrid,rnggrid,10*log10(abs(rngdopresp)))
title('Barker Code Range Doppler Map')
xlabel('Closing Speed (m/s)')
ylabel('Range (m)')
axis xy
mfgain = matchingcoeff'*matchingcoeff;
dopgain = Np;
noisebw = fs;
noisepower = noisepow(noisebw,receiver.NoiseFigure,receiver.ReferenceTemperature);
noisepowerprc = mfgain*dopgain*noisepower;
noise = noisepowerprc*ones(size(rngdopresp));
rangeestimator = phased.RangeEstimator('NumEstimatesSource','Auto', ...
'VarianceOutputPort',true,'NoisePowerSource','Input port', ...
'RMSResolution',rngrms);
dopestimator = phased.DopplerEstimator('VarianceOutputPort',true, ...
'NoisePowerSource','Input port','NumPulses',Np);
detidx = NaN(2,Numtgts);
tgtrng = rangeangle(tgtpos,radarpos);
tgtspd = radialspeed(tgtpos,tgtvel,radarpos,radarvel);
tgtdop = 2*speed2dop(tgtspd,c/fc);
for m = 1:numel(tgtrng)
[~,iMin] = min(abs(rnggrid-tgtrng(m)));
detidx(1,m) = iMin;
[~,iMin] = min(abs(dopgrid-tgtspd(m)));
detidx(2,m) = iMin;
end
%Find the noise power at the detection locations.
ind = sub2ind(size(noise),detidx(1,:),detidx(2,:))
%Estimate the range and range variance at the detection locations. The estimated ranges agree with the postulated ranges.
[rngest,rngvar] = rangeestimator(rngdopresp,rnggrid,detidx,noise(ind))
%Estimate the speed and speed variance at the detection locations. The estimated speeds agree with the predicted speeds.
[spdest,spdvar] = dopestimator(rngdopresp,dopgrid,detidx,noise(ind))
Accepted Answer
More Answers (0)
Categories
Find more on Detection 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!