?? runradarsim_v2.m
字號:
processedRecivedSignal = recievedSignal;
end
% ------------------------------- Was there a target ---------------------------------------------------
signalInRangeCells = processedRecivedSignal(rangeCellInd);
isMTIused = get(handles.useMTI,'value');
if isMTIused
freqInRangeCells = fft( signalInRangeCells,freqRes,2 );
energyInFreqRangeCells = abs( freqInRangeCells(:,freqInd) ).^2;
if useCFAR
noiseLevel = median( energyInFreqRangeCells(:) ); % Th is per frequency
freqTh = noiseLevel * CFAR * nPRI;
else
freqTh = Th * nPRI;
end
% Find in each range cell the maximum frequency (I only
% allow one target per range cell)
[maxFreq maxFreqInd] = max( energyInFreqRangeCells,[],2);
localMaxEnergy = imdilate( maxFreq , dilateKer );
rangeCell = find( localMaxEnergy == maxFreq & maxFreq > freqTh );
targetInd = sub2ind( [numSamplesInPRI freqRes], rangeCell, maxFreqInd( rangeCell ) );
else
% no MTI
energyInRangeCells = sum( abs(signalInRangeCells).^2,2 );
if useCFAR
noiseLevel = median( energyInRangeCells );
Th = noiseLevel * CFAR;
end
% Thresholding to find targets
localMaxEnergy = imdilate(energyInRangeCells,dilateKer);
targetInd = find ( energyInRangeCells == localMaxEnergy & energyInRangeCells > Th);
end % if isMTIused
if ~isempty(targetInd)
foundTargetInBuffer = 1;
if isMTIused
[rangeCell ans] = ind2sub(size(energyInFreqRangeCells),targetInd(:));
RCS = energyInFreqRangeCells(targetInd(:));
else
rangeCell = targetInd;
RCS = energyInRangeCells(targetInd);
end
targetRange = ( rangeCell -PWn/2) / Fs / 2 * 3e8; %target ranges
targetV = ones(length(targetInd),1)*12345;
for Rind = 1:length(targetInd)
%Processing each Target
pos = targetRange(Rind)*[cos(radarAngle) sin(radarAngle)];
if isMTIused
% Calculating the targets velocity acording to its dopler frequency
targetV(Rind) = MTIcalcVelocityFromFourier(energyInFreqRangeCells,targetInd(Rind),freqRes,handles.IF_Freq,PRI);
end
if isempty(handles.foundTargets)
% adding the new target to the foundTargets structure
handles.foundTargets(end+1) = ...
createTargetObj( pos, RCS(Rind), targetRange(Rind), targetV(Rind), radarAngle,0, radarAngle,radarAngle,[],numRadarTurn );
h = plotTarget( handles.foundTargets(end), handles );
handles.foundTargets(end).hPlot = h;
else
% ---------------- Checking if this target was already detected ------------------------------
M = length(handles.foundTargets);
% angleToOldTargets = zeros(M,1);
dAngle = zeros(M,1);
dRange = zeros(M,1);
dV = zeros(M,1);
for mm=1:M
d1 = calcDiffAngle( handles.foundTargets(mm).counterClockWise, radarAngle );
% d2 = -calcDiffAngle( handles.foundTargets(mm).clockWise, radarAngle );
d2 = pi;
dAngle(mm) = min ( d1, d2)/angleRes;
dRange(mm) = abs( handles.foundTargets(mm).R - targetRange(Rind) )/rangeRes;
dV(mm) = abs( handles.foundTargets(mm).v - targetV(Rind) )/velocityRes ;
end
[sameTargetScore sameTargetInd] = min( dAngle.^2 + dRange.^2 + dV.^2 );
% Was this target already detected
if sameTargetScore < 1
% This target was already detected !
if handles.foundTargets(sameTargetInd).RCS < RCS(Rind)
% Keeping the parameters of the better recived target;
handles.foundTargets(sameTargetInd).pos = pos;
handles.foundTargets(sameTargetInd).RCS = RCS(Rind);
handles.foundTargets(sameTargetInd).R = targetRange(Rind);
handles.foundTargets(sameTargetInd).v = targetV(Rind);
handles.foundTargets(sameTargetInd).angle = radarAngle;
delete( handles.foundTargets(sameTargetInd).hPlot );
h = plotTarget( handles.foundTargets(sameTargetInd), handles );
handles.foundTargets(sameTargetInd).hPlot = h;
% handles.foundTargets(sameTargetInd).foundInTurn = numRadarTurn;
end
if d1 < d2 % new target is before old target
handles.foundTargets(sameTargetInd).counterClockWise = radarAngle;
else
handles.foundTargets(sameTargetInd).clockWise = radarAngle;
end
else
% This is a new target (wasn't detected yet)
handles.foundTargets(end+1) = ...
createTargetObj( pos, RCS(Rind), targetRange(Rind), targetV(Rind), radarAngle,0, radarAngle,radarAngle,[],numRadarTurn );
h = plotTarget( handles.foundTargets(end), handles );
handles.foundTargets(end).hPlot = h;
end % m < angleRes & distFromOldTarget < rangeRes % Was this target already detected
end % if isempty(handles.foundTargets)
end % for n = 1:length(R)
end %if ~isempty(f)
%---------------------------------------------------------------------------------------------------------------------
dt = currentTime-lastUpdate ;
if dt > updateRate %Is it time to update the display
lastUpdate = currentTime;
currentRealTime = toc;
delay = dt - (currentRealTime - lastUpdateRealTime); % syncronizing to real time
lastUpdateRealTime = currentRealTime;
% delay = max(delay,1e-5); %to allowupdate of the display and
% GUI response
if delay > 0
pause(delay);
end
% -------------------------------------------------------------------------
isPersistentDisplay = get(handles.persistentDisplay,'value');
handles = plotFOV(handles,currentTime,antenaTurnVelocity,radarSector,maxDist,isPersistentDisplay);
updatedDisplay = true;
% updating the mini-map display every 5 seconds
if currentTime > miniDisplayUpdateTime + 5
if ~get( handles.scopeDisplay,'value' )
miniDisplayUpdateTime = currentTime;
displayTargets(handles,'in radar display')
numRadarTurn = ceil(currentTime*antenaTurnVelocity/2/pi);
end
if isPersistentDisplay
if length( handles.persistentPlotHandle ) > 1000
temp = handles.persistentPlotHandle;
delete( temp( 1:end-1000 ) );
handles.persistentPlotHandle = temp(end-999:end);
end
end
end
%---------------------------------------------------------------------------------------------------------------------
% Updating targets position, velocity & accelaration
targetsTime = currentTime; % the time in which the target position was updated
for n =1:length(handles.Targets)
handles.Targets(n).XY = handles.Targets(n).XY + dt*handles.Targets(n).v+dt^2*handles.Targets(n).a;
handles.Targets(n).v = handles.Targets(n).v + dt*handles.Targets(n).a;
handles.Targets(n).a = handles.Targets(n).a * 0.95^dt;
targetsManuv = handles.Targets(n).maneuverability;
if (1-exp(-dt/targetsManuv)) > rand(1) % deciding if the target changes it's acceleration
phi = atan( handles.Targets(n).v(2)/handles.Targets(n).v(1) );
phi = phi + 2*pi*(rand(1)-0.5);
handles.Targets(n).a = randn(1)*20*[cos(phi) sin(phi)] - handles.Targets(n).v/targetsManuv/2;
end
end
end % if dt > updateRate %Is it time to update the display
%---------------------------------------------------------------------------------------------------------------------
if isAnalyzeBufferMode
if get(handles.waitForTarget,'value')
% wait for a target in the buffer
if foundTargetInBuffer
if isMTIused
analyzBufferWithMTI(handles,recievedSignal,processedRecivedSignal,energyInFreqRangeCells,PWn,freqTh,freqInRangeCells,numSamplesInPRI,rangeCellInd);
else
analyzBuffer(handles,recievedSignal,processedRecivedSignal,energyInRangeCells,PWn,Th,rangeCellInd,localMaxEnergy);
end
set(handles.run,'string','Pause');
radarSimulation('run_Callback',handles.run,[],guidata(handles.run));
end
else
if isMTIused
analyzBufferWithMTI(handles,recievedSignal,processedRecivedSignal,energyInFreqRangeCells,PWn,freqTh,freqInRangeCells,numSamplesInPRI,rangeCellInd);
else
analyzBuffer(handles,recievedSignal,processedRecivedSignal,energyInRangeCells,PWn,Th,rangeCellInd,localMaxEnergy);
set(handles.run,'string','Pause');
radarSimulation('run_Callback',handles.run,[],guidata(handles.run));
end
set(handles.run,'string','Pause');
radarSimulation('run_Callback',handles.run,[],guidata(handles.run));
end
end
% ------------------------------------------------------------------------------------
% play recived signal sound
if get(handles.soundOn,'value')
% soundSig = abs(processedRecivedSignal);
soundSig = tanh( abs(processedRecivedSignal) );
% soundSig = abs( tanh( processedRecivedSignal ) );
% soundSig = angle(processedRecivedSignal); %I tried to listen
% to targets velocity
soundSig = soundSig / max(soundSig);
soundSamples = decimate(soundSig,sound2SampleRatio );
player.stop;
player = audioplayer( soundSamples, soundFs );
play(player);
end
% ------------------------------------------------------------------------------------
% Display analog scope !!!!!
if get(handles.scopeDisplay,'value')
hold( handles.miniDisplay,'off');
sig = abs(processedRecivedSignal(rangeCellInd));
plot(handles.miniDisplay,log( sig( PWn+1:end,:) ),'color',[239 255 250]/256,'linewidth',1);
set( handles.miniDisplay,'color',[118 219 237]/256);
ylim(handles.miniDisplay,[-22 -8]);
xlim( handles.miniDisplay,[1 numSamplesInPRI-PWn] );
grid( handles.miniDisplay,'on');
if ~updatedDisplay
drawnow;
updatedDisplay = false;
end
end
% ------------------------------------------------------------------------------------
end %if ~mod(pulseNum,nPRI) %Only processing every N number of pulses
pulseNum = pulseNum+1;
end % while get(handles.run,'value')
handles.numRadarTurn = numRadarTurn;
handles.pulseNum = pulseNum;
handles.currentTime = currentTime;
guidata(handles.run,handles);
handleRadarControlls(handles,'on');
set(handles.PW,'value',PW/PRI);
function x = fastSemiRandn(N)
% this nested function recives the number of elements to return
% it allways returns an N by 2 matrix of random numbers samppled
% from the vector randVec
vInd = ceil(rand(2)* (randVecLength-N));
x = [ randVec(vInd(1):vInd(1)+N-1) randVec(vInd(2):vInd(2)+N-1)];
end
end
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -