lct_firstpath.c 69 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874
  1. // 秒寻科技
  2. // 计算第一径数据队列
  3. // zt
  4. // 2023-03-25
  5. #include "../../includes/includes.h"
  6. // 导出全局变量
  7. extern flt32 gg_afOneFrameLocationData[PUB_SLOT_FRAME_LEN]; // 一帧临时定位数据
  8. extern LCT_FIRSTPATH_PARAM_T gg_stFirstPathParam; // 第一径模块参数
  9. extern flt32 g_afSincFilterDataList[24001]; // sinc滤波器
  10. extern PUB_SYS_STATUS_T gg_stSysStatus;
  11. extern uint32 gg_dwFrameNo;
  12. extern LCT_FIRSTPATH_PREDICTION_DIRECTION_DATA_T gLct_astPredictionDirectionDataList[PUB_SYS_CARRIER_NUM];
  13. void lct_firstpath_init(LCT_FIRSTPATH_PARAM_T stFirstPathParam)
  14. {
  15. // 帧内最小值选择因子
  16. gg_stFirstPathParam.byMinValueFactor = stFirstPathParam.byMinValueFactor;
  17. // 帧内锚点因子
  18. gg_stFirstPathParam.byAnchorFactor = stFirstPathParam.byAnchorFactor;
  19. gg_stFirstPathParam.byAnchorThreshold = stFirstPathParam.byAnchorThreshold;
  20. // 峰间距
  21. gg_stFirstPathParam.byPeakPeakDistance = stFirstPathParam.byPeakPeakDistance;
  22. // 计算帧内噪声门限时信号因子
  23. gg_stFirstPathParam.byNoiseSignalFactor = stFirstPathParam.byNoiseSignalFactor;
  24. // 计算帧内噪声门限时噪声放大倍数
  25. gg_stFirstPathParam.byNoiseHightScale = stFirstPathParam.byNoiseHightScale;
  26. gg_stFirstPathParam.byNoiseLowScale = stFirstPathParam.byNoiseLowScale;
  27. // cfar因子
  28. gg_stFirstPathParam.byCfarLeftFactor = stFirstPathParam.byCfarLeftFactor;
  29. // sinc门限因子
  30. gg_stFirstPathParam.bySincFactor = stFirstPathParam.bySincFactor;
  31. // 第一径联系锚点的因子
  32. gg_stFirstPathParam.byFirstPathContactFactor = stFirstPathParam.byFirstPathContactFactor;
  33. // 第一径联系锚点的峰间距离
  34. gg_stFirstPathParam.wFirstPathContactDistance = stFirstPathParam.wFirstPathContactDistance;
  35. //// 计算跟踪径的参数
  36. // 跟踪窗口宽度(跟踪径索引左右两边的距离-单边距离)
  37. gg_stFirstPathParam.wFirstPathTrackWindowWidth = stFirstPathParam.wFirstPathTrackWindowWidth;
  38. // 跟踪径保护带宽
  39. gg_stFirstPathParam.wFirstPathTrackPeakGuardWidth = stFirstPathParam.wFirstPathTrackPeakGuardWidth;
  40. // 跟踪径噪声查找宽度(从保护带宽左侧向左开始算)
  41. gg_stFirstPathParam.wFirstPathTrackNoiseFindWidth = stFirstPathParam.wFirstPathTrackNoiseFindWidth;
  42. // 跟踪径增益因子
  43. gg_stFirstPathParam.byFirstPathTrackPeakGainFactor = stFirstPathParam.byFirstPathTrackPeakGainFactor;
  44. return;
  45. }
  46. // 模块主控函数:根据定位基站队列,生产第一径队列
  47. // pstLctBtsList:一组定位基站
  48. // pstLctDataList:定位数据队列
  49. // pstFirstPathList:第一径数据队列(返回参数)
  50. void lct_firstpath_main(PUB_LCT_BTS_LIST_T *pstLctBtsList, PUB_LOCATION_DATA_T *pstLctDataList, LCT_FIRSTPATH_LIST_T *pstFirstPathList)
  51. {
  52. uint32 dwFrameNo = 0;
  53. uint8 byRemainder = 0;
  54. int32 dwSyncOffset = 0;
  55. uint8 byLctBtsNum = pstLctBtsList->byBtsNum; // 有效定位基站组的基站个数
  56. PUB_LCT_BTS_T *pstLctBts = NULL; // 定位基站
  57. PUB_LOCATION_DATA_T *pstLctData = NULL; // 定位数据
  58. uint8 byFreqIndex = 0; // 基站频率索引
  59. uint16 wAheadFrameFirstIndex = 0; // 上一次帧内第一径索引
  60. uint16 wMaxValueIndex = 0;
  61. flt32 fMaxValue; // 最大值
  62. uint16 wAnchorIndex = 0;
  63. flt32 fNoise = 0;
  64. flt32 fPeakThreshold = 0;
  65. FIRST_PATH_T stFirstPath = {0};
  66. uint8 byCounter = 0;
  67. uint16 wFrameTraceIndex = 0; // 帧内跟踪索引
  68. LCT_FIRSTPATH_T *pstFirstPath = NULL;
  69. // 复位预测方向数据有效标识符
  70. lct_firstpath_reset_direction_valid_flag(gLct_astPredictionDirectionDataList);
  71. // 遍历定位基站队列,计算基站第一径
  72. for (uint8 i = 0; i < byLctBtsNum; i++)
  73. {
  74. pstLctBts = &pstLctBtsList->astLocationBts[i]; // 定位基站
  75. byFreqIndex = pstLctBts->dwFreqIndex; // 基站的频率索引
  76. pstLctData = &pstLctDataList[byFreqIndex]; // 基站的定位数据
  77. // 获取该基站一帧定位数据
  78. lct_firstpath_get_lct_data(pstLctData, gg_afOneFrameLocationData);
  79. // TODO测试
  80. if (PUB_DEBUG_ENABLE)
  81. {
  82. if (pstLctData->byFreqIndex < 8 && pstLctData->dwFrameNo > 232)
  83. {
  84. char *pfileName = "E:\\work\\ips8000\\aplm8000sdk\\output\\lctdata\\firstpath.bin";
  85. util_write_flt32_to_bin_file(pfileName, PUB_SLOT_FRAME_LEN, gg_afOneFrameLocationData, 1);
  86. uint8 byTmp = 0;
  87. }
  88. }
  89. // 当前一秒数据有效(是定位基站、定位基站有效、当前幅度值有效)
  90. if (pstLctData->byLctBtsFlag && pstLctData->byBtsValidFlag && pstLctData->byCurrentAmplValidFlag)
  91. {
  92. // 帧内跟踪索引
  93. wFrameTraceIndex = pstLctData->wAheadFrameTrackPathIndex;
  94. // 基站第一径数据
  95. pstFirstPath = &pstFirstPathList->astFirstPath[byCounter]; // 返回参数
  96. memset(pstFirstPath, 0, sizeof(LCT_FIRSTPATH_T));
  97. ////将定位基站数据中的数据,复制到第一径数据结构中
  98. pstFirstPath->byMainFlag = (uint8)pstLctBts->dwMainBtsFlag;
  99. pstFirstPath->dwBuildId = pstLctBts->dwBuildId;
  100. pstFirstPath->dwLayerId = pstLctBts->dwLayerId;
  101. pstFirstPath->dwBtsId = pstLctBts->dwBtsId;
  102. pstFirstPath->byFreqIndex = (uint8)pstLctBts->dwFreqIndex;
  103. pstFirstPath->bySlot = (uint8)pstLctBts->dwSlot;
  104. pstFirstPath->dwLctType = pstLctBts->dwLctType;
  105. pstFirstPath->dwTwoBtsNum = pstLctBts->dwTwoBtsNum;
  106. memcpy(pstFirstPath->adwTwoBtsList, pstLctBts->adwTwoBtsList, sizeof(uint32) * pstLctBts->dwTwoBtsNum);
  107. pstFirstPath->dwCoordX = pstLctBts->dwCoordX;
  108. pstFirstPath->dwCoordY = pstLctBts->dwCoordY;
  109. pstFirstPath->dwCoordZ = pstLctBts->dwCoordZ;
  110. // 计算"计算径",并存参数
  111. lct_firstpath_cal_calpath(gg_afOneFrameLocationData, wFrameTraceIndex, &wMaxValueIndex, &wAnchorIndex, &fNoise, &fPeakThreshold, &stFirstPath);
  112. if (stFirstPath.wFirstPathIndex > 3000) // 计算径结果有效
  113. {
  114. // pstFirstPath->dwCalPathIndex = pstLctData->dwDdcIndex + pstLctData->dwSignalSlotSyncOffset + pstLctData->dwSignalSyncIndex + stFirstPath.wFirstPathIndex; // 第一径绝对索引
  115. // pstFirstPath->dwCalPathIndex = pstLctData->dwDdcIndex + pstLctData->dwSignalSyncIndex + stFirstPath.wFirstPathIndex; // 第一径绝对索引
  116. pstFirstPath->dwCalPathIndex = PUB_SLOT_FRAME_LEN + pstLctData->dwSignalSlotSyncOffset + pstLctData->dwSignalSyncIndex + stFirstPath.wFirstPathIndex; // 第一径绝对索引
  117. pstFirstPath->wFrameCalIndex = stFirstPath.wFirstPathIndex; // 第一径帧内索引
  118. pstFirstPath->fFrameCalPathValue = gg_afOneFrameLocationData[stFirstPath.wFirstPathIndex]; // 计算径值
  119. pstFirstPath->fCalPathIndexSnr = stFirstPath.fSnr; // 计算径信噪比
  120. fMaxValue = gg_afOneFrameLocationData[wMaxValueIndex];
  121. pstFirstPath->fMaxAmplValue = fMaxValue; // 帧内最大值
  122. // TODO测试
  123. if (PUB_DEBUG_ENABLE)
  124. {
  125. if (pstLctData->byFreqIndex < 8 && pstLctData->dwFrameNo > 220)
  126. {
  127. printf("frame no:%d, freq index:%d, sync index:%d, cal frame index:%d, cal index:%d\n", pstLctData->dwFrameNo - 1, pstFirstPath->byFreqIndex, pstLctData->dwSignalSyncIndex, pstFirstPath->wFrameCalIndex, pstFirstPath->dwCalPathIndex);
  128. uint8 byTmp = 0;
  129. }
  130. }
  131. }
  132. else
  133. {
  134. pstFirstPath->wFrameCalIndex = 0;
  135. }
  136. // 计算"跟踪径"
  137. if (wFrameTraceIndex && wFrameTraceIndex < 12000)
  138. {
  139. lct_firstpath_cal_trackpath(gg_afOneFrameLocationData, wFrameTraceIndex, fNoise, fPeakThreshold, wAnchorIndex, wMaxValueIndex, &stFirstPath);
  140. // 跟踪成功
  141. if (stFirstPath.byTrackSuccessFlag && stFirstPath.wFirstPathIndex > 3000)
  142. {
  143. // pstFirstPath->dwTrackPathIndex = pstLctData->dwDdcIndex + pstLctData->dwSignalSlotSyncOffset + pstLctData->dwSignalSyncIndex + stFirstPath.wFirstPathIndex; // 第一径绝对索引
  144. // pstFirstPath->dwTrackPathIndex = pstLctData->dwDdcIndex + pstLctData->dwSignalSyncIndex + stFirstPath.wFirstPathIndex; // 第一径绝对索引
  145. pstFirstPath->dwTrackPathIndex = PUB_SLOT_FRAME_LEN + pstLctData->dwSignalSlotSyncOffset + pstLctData->dwSignalSyncIndex + stFirstPath.wFirstPathIndex; // 第一径绝对索引
  146. pstFirstPath->wFrameTrackIndex = stFirstPath.wFirstPathIndex; // 第一径帧内索引
  147. pstFirstPath->fFrameTrackPathValue = gg_afOneFrameLocationData[stFirstPath.wFirstPathIndex]; // 跟踪径值
  148. pstFirstPath->fTrackPathIndexSnr = stFirstPath.fSnr; // 跟踪径信噪比
  149. }
  150. // 跟踪失败,则使用计算径的数据
  151. else
  152. {
  153. pstFirstPath->dwTrackPathIndex = pstFirstPath->dwCalPathIndex; // 第一径绝对索引
  154. pstFirstPath->fFrameTrackPathValue = pstFirstPath->fFrameCalPathValue;
  155. pstFirstPath->wFrameTrackIndex = pstFirstPath->wFrameCalIndex;
  156. pstFirstPath->fTrackPathIndexSnr = pstFirstPath->fCalPathIndexSnr;
  157. }
  158. }
  159. else
  160. {
  161. pstFirstPath->dwTrackPathIndex = pstFirstPath->dwCalPathIndex; // 第一径绝对索引
  162. pstFirstPath->fFrameTrackPathValue = pstFirstPath->fFrameCalPathValue;
  163. pstFirstPath->wFrameTrackIndex = pstFirstPath->wFrameCalIndex;
  164. pstFirstPath->fTrackPathIndexSnr = pstFirstPath->fCalPathIndexSnr;
  165. }
  166. // TODO测试
  167. if (PUB_DEBUG_ENABLE)
  168. {
  169. if (pstFirstPath->wFrameTrackIndex > 0 && pstLctData->byFreqIndex < 8 && pstLctData->dwFrameNo > 220)
  170. {
  171. printf("frame no:%d, freq index:%d, sync index:%d, track frame index:%d, track index:%d\n", pstLctData->dwFrameNo - 1, pstFirstPath->byFreqIndex, pstLctData->dwSignalSyncIndex, pstFirstPath->wFrameTrackIndex, pstFirstPath->dwTrackPathIndex);
  172. uint8 byTmp = 0;
  173. }
  174. }
  175. // 第一径合法
  176. if (pstFirstPath->wFrameCalIndex > 3000 || pstFirstPath->wFrameTrackIndex > 3000)
  177. {
  178. byCounter++;
  179. // 备份第一径数据,用于预测移动方向
  180. lct_firstpath_save_first_path_data(pstLctData, pstFirstPath, gLct_astPredictionDirectionDataList);
  181. }
  182. }
  183. }
  184. // 保存第一径数据队列的基站数量
  185. pstFirstPathList->byBtsNum = byCounter;
  186. // 预测移动方向
  187. lct_firstpath_prediction_move_direction(gLct_astPredictionDirectionDataList);
  188. return;
  189. }
  190. // 获取一帧定位数据
  191. // pstLctData:定位数据队列
  192. // pfOutData:输出参数,一帧定位数据
  193. void lct_firstpath_get_lct_data(PUB_LOCATION_DATA_T *pstLctData, flt32 *pfOutData)
  194. {
  195. int32 dwStartIndex = 0;
  196. uint32 dwTmpIndex = 0;
  197. // 计算定位数据所在队列中的开始索引
  198. // dwStartIndex = pstLctData->dwLocationIndex + (bySolt * PUB_SLOT_FRAME_LEN);
  199. dwStartIndex = pstLctData->dwLocationIndex + pstLctData->dwSignalSyncIndex;
  200. if (dwStartIndex < 0)
  201. {
  202. dwStartIndex += PUB_LCT_DATA_LIST_LEN;
  203. }
  204. else if (dwStartIndex >= PUB_LCT_DATA_LIST_LEN)
  205. {
  206. dwStartIndex -= PUB_LCT_DATA_LIST_LEN;
  207. }
  208. // 获取一帧数据
  209. util_looplist_get_flt32(pstLctData->afData, PUB_LCT_DATA_LIST_LEN, dwStartIndex, pfOutData, PUB_SLOT_FRAME_LEN, &dwTmpIndex);
  210. return;
  211. }
  212. // 计算 "计算径"
  213. // pfLocationData:定位数据
  214. // pwMaxValueIndex:大值索引(返回参数)
  215. // pwAnchorIndex:锚点索引(返回参数)
  216. // pdwNoise:噪声(返回参数)
  217. // pdwPeakThreshold:选峰门限(返回参数)
  218. // pstFirstPath:计算径(返回参数)
  219. void lct_firstpath_cal_calpath(flt32 *pfLocationData, uint16 wAheadFrameFirstPath, uint16 *pwMaxValueIndex, uint16 *pwAnchorIndex, flt32 *pfNoise, flt32 *pfPeakThreshold, FIRST_PATH_T *pstFirstPath)
  220. {
  221. uint16 wMaxValueIndex = 0; // 帧内最大值索引
  222. uint16 wMinValueIndex = 0;
  223. flt32 fNoise = 0; // 帧内噪声
  224. flt32 fSnr = 0; // 信噪比
  225. flt32 fSelPeakThreshold = 0; // 帧内峰值门限
  226. flt32 fMiniValueFactor = (flt32)gg_stFirstPathParam.byMinValueFactor / 100;
  227. uint16 awPeakList[PUBLIC_LCT_PEAK_LIST_LEN]; // 峰值索引队列
  228. uint16 wPeakListLen = 0; // 峰值索引队列长度
  229. uint16 wAnchorIndex = 0; // 帧内锚点索引
  230. flt32 fThresholdWithAnchor = 0;
  231. uint16 wFirstPathLen = 0; // 第一径队列长度
  232. uint16 awOriginalList[PUBLIC_LCT_PEAK_LIST_LEN]; // 原始峰值索引队列
  233. uint16 wOriginalListLen = 0; // 原始峰值索引队列长度
  234. uint16 wFirstPathIndex = 0; // 第一径索引
  235. memset(awOriginalList, 0, sizeof(uint16) * PUBLIC_LCT_PEAK_LIST_LEN);
  236. memset(awPeakList, 0, sizeof(uint16) * PUBLIC_LCT_PEAK_LIST_LEN);
  237. // 计算帧内最大值索引、噪声和信噪比
  238. lct_firstpath_cal_frame_max_min_value_index_noise_snr(pfLocationData, wAheadFrameFirstPath, &wMaxValueIndex, &wMinValueIndex, &fNoise, &fSnr);
  239. *pwMaxValueIndex = wMaxValueIndex;
  240. *pfNoise = fNoise;
  241. // 计算选峰门限
  242. lct_firstpath_cal_peak_threshold(fNoise, fSnr, &fSelPeakThreshold);
  243. if (fSelPeakThreshold < fMiniValueFactor * pfLocationData[wMaxValueIndex])
  244. {
  245. fSelPeakThreshold = fMiniValueFactor * pfLocationData[wMaxValueIndex];
  246. }
  247. *pfPeakThreshold = fSelPeakThreshold;
  248. // 选左侧峰
  249. lct_firstpath_select_left_peak(pfLocationData, fSelPeakThreshold, wMinValueIndex, wMaxValueIndex, awPeakList, &wPeakListLen);
  250. // 计算锚点索引
  251. lct_firstpath_cal_anchor_index(awPeakList, wPeakListLen, pfLocationData, fSnr, &wAnchorIndex);
  252. *pwAnchorIndex = wAnchorIndex;
  253. // 二次计算选峰门限
  254. fSelPeakThreshold = lct_firstpath_recal_peak_value_threshold(pfLocationData, wMaxValueIndex, wAnchorIndex, fSelPeakThreshold);
  255. *pfPeakThreshold = fSelPeakThreshold;
  256. // 二次选峰
  257. lct_firstpath_select_peak_by_anchor(awPeakList, wPeakListLen, wAnchorIndex, pfLocationData, fSelPeakThreshold, &wPeakListLen);
  258. //// 基于峰值门限计算第一径
  259. wFirstPathLen = 0;
  260. lct_firstpath_cal_first_path_by_peak_value_threshold(pfLocationData, wMaxValueIndex, fSelPeakThreshold, awPeakList, wPeakListLen, 0, &wFirstPathLen);
  261. wPeakListLen = wFirstPathLen; // 调整峰值队列长度
  262. //// 基于CFAR规则计算第一径
  263. wFirstPathLen = 0;
  264. lct_firstpath_cal_first_path_by_cfar(pfLocationData, wMaxValueIndex, awPeakList, wPeakListLen, 0, &wFirstPathLen);
  265. wPeakListLen = wFirstPathLen; // 调整峰值队列长度
  266. //// 基于SINC规则计算第一径
  267. wFirstPathLen = 0;
  268. lct_firstpath_cal_first_path_by_sinc(pfLocationData, wMaxValueIndex, fNoise, awPeakList, wPeakListLen, 0, &wFirstPathLen);
  269. wPeakListLen = wFirstPathLen; // 调整峰值队列长度
  270. // 检查锚点是否还是有效峰
  271. lct_firstpath_check_anchor_index(awPeakList, wPeakListLen, wAnchorIndex, wMaxValueIndex, &wAnchorIndex, &wPeakListLen);
  272. // 检查第一径与锚点间的关联性
  273. memcpy(awOriginalList, awPeakList, sizeof(uint16) * wPeakListLen);
  274. wOriginalListLen = wPeakListLen;
  275. lct_firstpath_check_first_path_contact(pfLocationData, awPeakList, wPeakListLen, awOriginalList, wOriginalListLen, wAnchorIndex, wMaxValueIndex, &wFirstPathIndex);
  276. // 保存输出参数
  277. pstFirstPath->wFirstPathIndex = wFirstPathIndex;
  278. pstFirstPath->fSnr = pfLocationData[wFirstPathIndex] / fNoise;
  279. return;
  280. }
  281. // 计算帧内最大值索引、最小值索引、噪声和信噪比
  282. // pdwData:定位数据
  283. // wAheadFrameFirstPath:上一次第一径帧内索引
  284. // pwMaxValueIndex:帧内最大值索引(返回参数)
  285. // pwMinValueIndex:帧内最小值索引(返回参数)
  286. // pdwNose:帧内噪声(返回参数)
  287. // pfSnr:帧内信噪比(返回参数)
  288. void lct_firstpath_cal_frame_max_min_value_index_noise_snr(flt32 *pfData, uint16 wAheadFrameFirstPath, uint16 *pwMaxValueIndex, uint16 *pwMinValueIndex, flt32 *pfNose, flt32 *pfSnr)
  289. {
  290. flt32 fMaxValue = 0;
  291. uint16 wMaxValueIndex = 0; // 最大值索引
  292. flt32 *pfDataHead = NULL;
  293. flt32 fTmpValue = 0;
  294. flt32 fMinValue = FLT_MAX; // FLT_MAX在系统库中有定义,最大值
  295. uint16 wMinValueIndex = 0;
  296. flt32 afDataNoiseList[PUB_SLOT_FRAME_LEN] = {0};
  297. flt32 fMiddleValue = 0;
  298. flt32 fNoiseHightScale = (flt32)gg_stFirstPathParam.byNoiseHightScale / 10;
  299. flt32 fLeftAverageValue = 0;
  300. flt32 fNoise = 0;
  301. uint16 wStartIndex = 0;
  302. //// 1、计算最大值索引
  303. if (wAheadFrameFirstPath > 1500)
  304. {
  305. wStartIndex = wAheadFrameFirstPath - 1500;
  306. for (uint16 k = wStartIndex; k < PUB_SLOT_FRAME_LEN; k++)
  307. {
  308. if (pfData[k] > fMaxValue)
  309. {
  310. fMaxValue = pfData[k];
  311. wMaxValueIndex = k;
  312. }
  313. }
  314. }
  315. else
  316. {
  317. wMaxValueIndex = util_looplist_find_max_value_index_flt32(pfData, PUB_SLOT_FRAME_LEN);
  318. fMaxValue = pfData[wMaxValueIndex];
  319. }
  320. ////2、在最大值左侧找一个最小值
  321. wStartIndex = wMaxValueIndex > 1000 ? 1000 : 0;
  322. pfDataHead = pfData;
  323. for (uint16 i = wStartIndex; i < wMaxValueIndex; i++)
  324. {
  325. fTmpValue = *pfDataHead;
  326. if (fTmpValue < fMinValue)
  327. {
  328. fMinValue = fTmpValue;
  329. wMinValueIndex = i;
  330. }
  331. pfDataHead++;
  332. }
  333. *pwMinValueIndex = wMinValueIndex;
  334. fMinValue *= fNoiseHightScale;
  335. ////3、 计算最小值左右两侧均值(左侧有可能包含泄露噪声)
  336. wMinValueIndex += 501;
  337. for (uint16 k = 0; k < wMinValueIndex; k++)
  338. {
  339. fLeftAverageValue += pfData[k] / wMinValueIndex;
  340. afDataNoiseList[k] = pfData[k];
  341. }
  342. ////4、 计算中位数
  343. util_sort_flt32_asc(afDataNoiseList, wMinValueIndex);
  344. fMiddleValue = afDataNoiseList[wMinValueIndex * 65 / 100];
  345. ////5、计算帧内噪声
  346. fNoise = fLeftAverageValue > fMinValue ? fLeftAverageValue : fMinValue;
  347. fNoise = fMiddleValue > fNoise ? fMiddleValue : fNoise;
  348. ////6、保存参数
  349. *pwMaxValueIndex = wMaxValueIndex;
  350. *pfNose = fNoise;
  351. *pfSnr = fMaxValue / fNoise;
  352. return;
  353. }
  354. // 计算噪声、信噪比和峰值门限
  355. // fNoise:噪声
  356. // fSnr:信噪比
  357. // pfPeakThreshold(返回参数)
  358. void lct_firstpath_cal_peak_threshold(flt32 fNoise, flt32 fSnr, flt32 *pfPeakThreshold)
  359. {
  360. uint8 byNoiseSignalFactor = gg_stFirstPathParam.byNoiseSignalFactor;
  361. flt32 fNoiseLowScale = (flt32)gg_stFirstPathParam.byNoiseLowScale / 10;
  362. flt32 fNoiseShapeSinrRatio = 1;
  363. flt32 fThresholdSnr = 0; // 门限snr
  364. flt32 fPeakThreshold = 0; // 峰值门限
  365. // 计算峰值门限
  366. if (fSnr < 10)
  367. {
  368. fThresholdSnr = fSnr > fNoiseLowScale ? fSnr : fNoiseLowScale;
  369. fNoiseShapeSinrRatio += (10 - fThresholdSnr) / (flt32)byNoiseSignalFactor;
  370. }
  371. fPeakThreshold = ((flt32)fNoiseLowScale / fNoiseShapeSinrRatio) * fNoise;
  372. *pfPeakThreshold = (uint32)fPeakThreshold; // 选峰门限
  373. return;
  374. }
  375. // 选最大值的左侧峰
  376. // pfData:定位数据
  377. // fPeakThreshold:选峰门限
  378. // wMinValueIndex:最小值索引
  379. // wMaxValueIndex:最大值索引
  380. // pwPeakList:峰列表(返回参数)
  381. // pwPeakListLen:峰列表长度(返回参数)
  382. void lct_firstpath_select_left_peak(flt32 *pfData, flt32 fPeakThreshold, uint16 wMinValueIndex, uint16 wMaxValueIndex, uint16 *pwPeakList, uint16 *pwPeakListLen)
  383. {
  384. flt32 fLeftData1 = 0;
  385. flt32 fLeftData2 = 0;
  386. flt32 fLeftData3 = 0;
  387. flt32 fCenterData = 0; // 峰值
  388. flt32 fRightData1 = 0;
  389. flt32 fRightData2 = 0;
  390. flt32 fRightData3 = 0;
  391. uint16 wAheadPeakIndex = 0; // 前一个峰值索引
  392. flt32 fAheadPeakValue = 0; // 前一个峰值值
  393. uint16 wPeakPeakDistance = 0; // 峰间距
  394. uint8 byDistanceGap = gg_stFirstPathParam.byPeakPeakDistance; // 选峰间隔
  395. uint16 wCounter = 0;
  396. uint16 wTmpIndex = 0;
  397. // 从最大峰向左选峰
  398. fAheadPeakValue = pfData[wMaxValueIndex];
  399. wAheadPeakIndex = wMaxValueIndex;
  400. for (int16 i = (wMaxValueIndex - byDistanceGap); i > wMinValueIndex; i--)
  401. {
  402. if ((i - 3) >= 0)
  403. {
  404. fLeftData3 = pfData[i - 3];
  405. fLeftData2 = pfData[i - 2];
  406. fLeftData1 = pfData[i - 1];
  407. fCenterData = pfData[i];
  408. fRightData1 = pfData[i + 1];
  409. fRightData2 = pfData[i + 2];
  410. fRightData3 = pfData[i + 3];
  411. wPeakPeakDistance = wAheadPeakIndex - i; // 峰间距
  412. if (fCenterData > fPeakThreshold && fCenterData > fLeftData1 && fCenterData > fLeftData2 && fCenterData > fLeftData3 && fCenterData > fRightData1 && fCenterData > fRightData2 && fCenterData > fRightData3 && fCenterData > 0.15 * fAheadPeakValue && wPeakPeakDistance < 1000)
  413. {
  414. fAheadPeakValue = fCenterData;
  415. wAheadPeakIndex = i;
  416. pwPeakList[wCounter] = i;
  417. i -= (byDistanceGap + 1); // 调整峰值索引到下一个峰开始位置
  418. wCounter++;
  419. }
  420. }
  421. }
  422. // 保存最大峰值索引
  423. pwPeakList[wCounter] = wMaxValueIndex; // 最大值是锚点索引或者前一次第一径索引
  424. wCounter++;
  425. // 对峰值索引队列重新排序(从小到大)
  426. for (uint16 k = 0; k < wCounter; k++)
  427. {
  428. for (uint16 m = k + 1; m < wCounter; m++)
  429. {
  430. if (pwPeakList[m] < pwPeakList[k])
  431. {
  432. wTmpIndex = pwPeakList[k];
  433. pwPeakList[k] = pwPeakList[m];
  434. pwPeakList[m] = wTmpIndex;
  435. }
  436. }
  437. }
  438. // 保存峰值列表长度
  439. *pwPeakListLen = wCounter;
  440. return;
  441. }
  442. // 选跟踪峰
  443. // pfData:定位数据
  444. // wMaxValueIndex:最大值索引
  445. // wTrackIndex:跟踪径索引
  446. // pwPeakList:峰列表(返回参数)
  447. // pwPeakListLen:峰列表长度(返回参数)
  448. void lct_firstpath_sel_track_peak(flt32 *pfData, uint16 wMaxValueIndex, uint16 wTrackIndex, uint16 *pwPeakList, uint16 *pwPeakListLen)
  449. {
  450. uint16 wStartIndex = 0;
  451. uint16 wStopIndex = 0;
  452. uint16 wGuardWidth = gg_stFirstPathParam.wFirstPathTrackPeakGuardWidth; // 跟踪峰保护带宽
  453. uint16 wTrackWindowWidth = gg_stFirstPathParam.wFirstPathTrackWindowWidth; // 跟踪窗口宽度
  454. flt32 fLeftData1 = 0;
  455. flt32 fLeftData2 = 0;
  456. flt32 fLeftData3 = 0;
  457. flt32 fCenterData = 0; // 峰值
  458. flt32 fRightData1 = 0;
  459. flt32 fRightData2 = 0;
  460. flt32 fRightData3 = 0;
  461. uint8 byDistance = gg_stFirstPathParam.byPeakPeakDistance;
  462. uint16 wCounter = 0;
  463. uint16 wTmpIndex = 0;
  464. // 计算左侧选峰结束索引
  465. if ((wTrackIndex - wGuardWidth - wTrackWindowWidth) > 0)
  466. {
  467. wStartIndex = wTrackIndex - wGuardWidth - wTrackWindowWidth;
  468. }
  469. else
  470. {
  471. wStartIndex = 0;
  472. }
  473. // 从跟踪索引向左选峰
  474. for (int16 i = wTrackIndex; i > wStartIndex; i--)
  475. {
  476. if ((i - 3) >= 0 && (i + 3) < PUB_SLOT_FRAME_LEN)
  477. {
  478. fLeftData3 = pfData[i - 3];
  479. fLeftData2 = pfData[i - 2];
  480. fLeftData1 = pfData[i - 1];
  481. fCenterData = pfData[i];
  482. fRightData1 = pfData[i + 1];
  483. fRightData2 = pfData[i + 2];
  484. fRightData3 = pfData[i + 3];
  485. if (fCenterData > fLeftData1 && fCenterData > fLeftData2 && fCenterData > fLeftData3 && fCenterData > fRightData1 && fCenterData > fRightData2 && fCenterData > fRightData3)
  486. {
  487. pwPeakList[wCounter] = i;
  488. i -= (byDistance + 1); // 调整峰值索引到下一个峰开始位置
  489. wCounter++;
  490. }
  491. }
  492. }
  493. // 计算向右侧选峰的结束索引
  494. if ((wTrackIndex + wGuardWidth + wTrackWindowWidth + 1) < PUB_SLOT_FRAME_LEN)
  495. {
  496. wStopIndex = wTrackIndex + wGuardWidth + wTrackWindowWidth + 1;
  497. }
  498. else
  499. {
  500. wStopIndex = PUB_SLOT_FRAME_LEN;
  501. }
  502. // 向右侧选峰
  503. for (int16 j = (wTrackIndex + byDistance); j < wStopIndex; j++)
  504. {
  505. if ((j + 3) < PUB_SLOT_FRAME_LEN)
  506. {
  507. fLeftData3 = pfData[j - 3];
  508. fLeftData2 = pfData[j - 2];
  509. fLeftData1 = pfData[j - 1];
  510. fCenterData = pfData[j];
  511. fRightData1 = pfData[j + 1];
  512. fRightData2 = pfData[j + 2];
  513. fRightData3 = pfData[j + 3];
  514. if (fCenterData > fLeftData1 && fCenterData > fLeftData2 && fCenterData > fLeftData3 && fCenterData > fRightData1 && fCenterData > fRightData2 && fCenterData > fRightData3)
  515. {
  516. pwPeakList[wCounter] = j;
  517. j += (byDistance - 1); // 调整峰值索引到下一个峰左侧侧位置
  518. wCounter++;
  519. }
  520. }
  521. }
  522. // 对峰值列表重新排序(从小到大)
  523. for (uint16 k = 0; k < wCounter; k++)
  524. {
  525. for (uint16 m = k + 1; m < wCounter; m++)
  526. {
  527. if (pwPeakList[m] < pwPeakList[k])
  528. {
  529. wTmpIndex = pwPeakList[k];
  530. pwPeakList[k] = pwPeakList[m];
  531. pwPeakList[m] = wTmpIndex;
  532. }
  533. }
  534. }
  535. // 过滤在最大值索引右侧的峰,包括最大值
  536. for (uint16 p = 0; p < wCounter; p++)
  537. {
  538. wTmpIndex = pwPeakList[p];
  539. if (wTmpIndex >= wMaxValueIndex)
  540. {
  541. wCounter = p;
  542. break;
  543. }
  544. }
  545. // 保存峰值列表长度
  546. *pwPeakListLen = wCounter;
  547. return;
  548. }
  549. // 计算锚点索引
  550. // pwPeakList:峰队列
  551. // wPeakListLen:峰队列长度
  552. // pfData:定位数据
  553. // fSnr:本帧的信噪比
  554. // pwAnchorIndex:锚点索引(返回参数)
  555. void lct_firstpath_cal_anchor_index(uint16 *pwPeakList, uint16 wPeakListLen, flt32 *pfData, flt32 fSnr, uint16 *pwAnchorIndex)
  556. {
  557. flt32 fMaxValue = 0;
  558. uint16 wMaxValueIndex = 0;
  559. uint8 byAnchorFactor = gg_stFirstPathParam.byAnchorFactor; // 锚点因子
  560. flt32 fAnchorThreshold = ((flt32)gg_stFirstPathParam.byAnchorThreshold) / 100; // 锚点默认门限值
  561. uint16 wAnchorIndex = 0; // 锚点索引
  562. uint16 wTempIndex = 0;
  563. uint32 fTempValue = 0;
  564. uint8 byExistFlag = 0;
  565. // 计算锚点门限值
  566. wMaxValueIndex = pwPeakList[wPeakListLen - 1];
  567. fMaxValue = pfData[wMaxValueIndex];
  568. // 信噪比较小,则抬升锚点门限
  569. if (fSnr < 10)
  570. {
  571. fSnr = fSnr > 1.5 ? fSnr : 1.5;
  572. fAnchorThreshold += (10 - fSnr) / byAnchorFactor; // 抬升锚点门限
  573. }
  574. // 计算锚点门限
  575. if (fMaxValue < 5000)
  576. {
  577. fAnchorThreshold = 0.45 * fMaxValue;
  578. }
  579. else
  580. {
  581. fAnchorThreshold = fMaxValue * fAnchorThreshold;
  582. }
  583. // 计算锚点索引
  584. if (wPeakListLen <= 1)
  585. { // 只有一个峰
  586. *pwAnchorIndex = pwPeakList[0];
  587. }
  588. else
  589. { // 有多个峰,则从多个峰中选择锚点
  590. for (int16 i = 0; i < wPeakListLen; i++)
  591. {
  592. wTempIndex = pwPeakList[i];
  593. fTempValue = pfData[wTempIndex];
  594. if (fTempValue > fAnchorThreshold)
  595. {
  596. wAnchorIndex = wTempIndex;
  597. byExistFlag = 1; // 找到了
  598. break;
  599. }
  600. }
  601. if (byExistFlag)
  602. { // 找到了锚点
  603. *pwAnchorIndex = wAnchorIndex;
  604. }
  605. else
  606. { // 未找到锚点,最大峰为锚点
  607. *pwAnchorIndex = pwPeakList[wPeakListLen - 1];
  608. }
  609. }
  610. return;
  611. }
  612. // 计算二次选峰门限
  613. // pfLocationData:定位数据
  614. // wMaxValueIndex:帧内最大值索引
  615. // wAnchorIndex:帧内锚点索引
  616. // fThreshold:一次选峰门限
  617. // 返回值:二次选峰门限
  618. flt32 lct_firstpath_recal_peak_value_threshold(flt32 *pfLocationData, uint16 wMaxValueIndex, uint16 wAnchorIndex, flt32 fThreshold)
  619. {
  620. int16 wIndexGap = 0;
  621. flt32 fAnchorValue = 0;
  622. flt32 fOutThreshold = fThreshold;
  623. fAnchorValue = pfLocationData[wAnchorIndex]; // 锚点值
  624. // 根据最大峰和锚点间距调整二次选峰门限
  625. if (wAnchorIndex != wMaxValueIndex)
  626. {
  627. wIndexGap = wMaxValueIndex - wAnchorIndex;
  628. // 严重多径
  629. if (wIndexGap > 2000)
  630. {
  631. if (0.35 * fAnchorValue > fThreshold)
  632. {
  633. fOutThreshold = 0.35 * fAnchorValue;
  634. }
  635. }
  636. else if (wIndexGap > 1500)
  637. {
  638. if (0.30 * fAnchorValue > fThreshold)
  639. {
  640. fOutThreshold = 0.30 * fAnchorValue;
  641. }
  642. }
  643. else if (wIndexGap > 1000)
  644. {
  645. if (0.25 * fAnchorValue > fThreshold)
  646. {
  647. fOutThreshold = 0.25 * fAnchorValue;
  648. }
  649. }
  650. else
  651. {
  652. if (0.15 * fAnchorValue > fThreshold)
  653. {
  654. fOutThreshold = 0.15 * fAnchorValue;
  655. }
  656. }
  657. }
  658. // 根据锚点幅度再次调整门限(小信号)
  659. if (fAnchorValue < 3000)
  660. {
  661. fOutThreshold = 0.35 * fAnchorValue;
  662. }
  663. return fOutThreshold;
  664. }
  665. // 根据锚点二次选锋,只选锚点左侧的峰
  666. // pwPeakList:峰值索引列表
  667. // wPeakListLen:峰值索引列表长度
  668. // wAnchorIndex:锚点
  669. // pwPeakIndexListLen:峰值索引列表长度(返回参数)
  670. // 返回值,1:成功,0:失败
  671. void lct_firstpath_select_peak_by_anchor(uint16 *pwPeakList, uint16 wPeakListLen, uint16 wAnchorIndex, flt32 *pfData, flt32 fThresholdWithAnchor, uint16 *pwPeakListLen)
  672. {
  673. uint16 wCounter = 0;
  674. uint16 wTempIndex = 0;
  675. flt32 fPeakValue = 0;
  676. // 选锋
  677. for (uint16 i = 0; i < wPeakListLen; i++)
  678. {
  679. wTempIndex = pwPeakList[i];
  680. fPeakValue = pfData[wTempIndex];
  681. if (fPeakValue > fThresholdWithAnchor && wTempIndex <= wAnchorIndex)
  682. {
  683. pwPeakList[wCounter] = wTempIndex;
  684. wCounter++;
  685. }
  686. }
  687. // 保存最大值
  688. if (wAnchorIndex < pwPeakList[wPeakListLen - 1])
  689. {
  690. pwPeakList[wCounter] = pwPeakList[wPeakListLen - 1];
  691. wCounter++;
  692. }
  693. // 队列长度
  694. *pwPeakListLen = wCounter;
  695. return;
  696. }
  697. // 通过噪声门限计算第一径点集
  698. // pfData:定位数据
  699. // wMaxValueIndex:最大值索引
  700. // fPeakValueThreshold:选峰门限
  701. // pwPeakList:峰值索引列表
  702. // wPeakListLen:峰值索引列表长度
  703. // byTrackFlag:跟踪标志(0:不跟踪,1:跟踪)
  704. // pwFirstPathLen:第一径长度(返回参数)
  705. void lct_firstpath_cal_first_path_by_peak_value_threshold(flt32 *pfData, uint16 wMaxValueIndex, flt32 fPeakValueThreshold, uint16 *pwPeakList, uint16 wPeakListLen, uint8 byTrackFlag, uint16 *pwFirstPathLen)
  706. {
  707. uint16 awList[PUB_SLOT_FRAME_LEN];
  708. uint16 wPeakIndex = 0;
  709. flt32 fTmpValue = 0;
  710. uint16 wCounter = 0;
  711. memset(awList, 0, sizeof(uint16) * PUB_SLOT_FRAME_LEN);
  712. // 遍历峰值索引队列,精选第一径
  713. for (uint16 i = 0; i < wPeakListLen; i++)
  714. {
  715. wPeakIndex = pwPeakList[i];
  716. fTmpValue = pfData[wPeakIndex];
  717. if (fTmpValue > fPeakValueThreshold)
  718. {
  719. pwPeakList[wCounter] = wPeakIndex;
  720. wCounter++;
  721. }
  722. }
  723. // 存在第一径
  724. if (wCounter > 0)
  725. {
  726. *pwFirstPathLen = wCounter; // 更新队列长度
  727. }
  728. // 不存在第一径
  729. else
  730. {
  731. // 不跟踪第一径
  732. if (byTrackFlag <= 0)
  733. {
  734. pwPeakList[0] = wMaxValueIndex; // 将最大值作为第一径
  735. *pwFirstPathLen = 1;
  736. }
  737. // 跟踪第一径
  738. else
  739. {
  740. pwPeakList[0] = PUB_SLOT_FRAME_LEN; // 索引默认值,标识跟踪失败
  741. *pwFirstPathLen = 0; // 标识跟踪失败
  742. }
  743. }
  744. return;
  745. }
  746. // 根据CFAR规则计算第一径
  747. // pfData:定位数据
  748. // wMaxValueIndex:最大值索引
  749. // pwPeakList:峰值索引列表(输入输出参数)
  750. // wPeakListLen:峰值索引列表长度
  751. // byTrackFlag:跟踪标志(0:不跟踪,1:跟踪)
  752. // pwFirstPathLen:第一径长度(返回参数)
  753. void lct_firstpath_cal_first_path_by_cfar(flt32 *pfData, uint16 wMaxValueIndex, uint16 *pwPeakList, uint16 wPeakListLen, uint8 byTrackFlag, uint16 *pwFirstPathLen)
  754. {
  755. // 左侧因子
  756. flt32 fCfarLeftFactor = ((flt32)gg_stFirstPathParam.byCfarLeftFactor) / 100;
  757. flt32 fLeftValueThres = 0; // 左侧门限
  758. flt32 fLeftMax = 0; // 左侧最大值
  759. flt32 fLeftTemp = 0;
  760. flt32 fSignalValue = 0; // 信号值
  761. uint16 wSignalIndex = 0; // 队列索引
  762. uint8 byErrorFlag = 0; // 是否满足cfar规格检查, 0:满足,1:不满足
  763. uint16 wCounter = 0; // 符合检查规则的峰值计数器
  764. // 遍历第一径队列,以cfar规则检查第一径
  765. for (uint16 k = 0; k < wPeakListLen; k++)
  766. {
  767. byErrorFlag = 0;
  768. wSignalIndex = pwPeakList[k]; // 第一径在信号队列中的索引
  769. // 检查该队列左边是否足够进行cfar判断
  770. if ((wSignalIndex - 2 * PUBLIC_LCT_CFAR_LEN) < 0)
  771. {
  772. byErrorFlag = 1;
  773. }
  774. // 左侧满足检测要求
  775. if (!byErrorFlag)
  776. {
  777. fSignalValue = pfData[wSignalIndex]; // 当前信号值
  778. // 选择左边最大值
  779. fLeftMax = 0;
  780. for (uint16 i = (wSignalIndex - 2 * PUBLIC_LCT_CFAR_LEN); i < (wSignalIndex - PUBLIC_LCT_CFAR_LEN); i++)
  781. {
  782. fLeftTemp = pfData[i];
  783. if (fLeftTemp > fLeftMax)
  784. {
  785. fLeftMax = fLeftTemp;
  786. }
  787. }
  788. fLeftValueThres = fLeftMax * fCfarLeftFactor; // cfar门限
  789. if (fSignalValue > fLeftValueThres)
  790. {
  791. pwPeakList[wCounter] = wSignalIndex;
  792. wCounter++;
  793. }
  794. }
  795. }
  796. // 存在第一径
  797. if (wCounter > 0)
  798. {
  799. // 将最大值插入第一径队列
  800. if (pwPeakList[wCounter - 1] != wMaxValueIndex)
  801. {
  802. pwPeakList[wCounter] = wMaxValueIndex;
  803. wCounter++;
  804. }
  805. *pwFirstPathLen = wCounter; // 更新队列长度
  806. }
  807. // 不存在第一径
  808. else
  809. {
  810. // 当前是计算径
  811. if (byTrackFlag <= 0)
  812. {
  813. pwPeakList[0] = wMaxValueIndex; // 将最大值作为第一径
  814. *pwFirstPathLen = 1;
  815. }
  816. // 当前是跟踪径
  817. else
  818. {
  819. pwPeakList[0] = PUB_SLOT_FRAME_LEN; // 索引默认值,标识跟踪失败
  820. *pwFirstPathLen = 0; // 标识跟踪失败
  821. }
  822. }
  823. return;
  824. }
  825. // 根据sinc规则计算第一径
  826. // pfData:定位数据
  827. // wMaxValueIndex:最大值索引
  828. // fNoise:噪声
  829. // pwPeakList:峰值索引列表
  830. // wPeakListLen:峰值索引列表长度
  831. // byTrackFlag:跟踪标志(0:不跟踪,1:跟踪)
  832. // pwFirstPathLen:第一径长度(返回参数)
  833. void lct_firstpath_cal_first_path_by_sinc(flt32 *pfData, uint16 wMaxValueIndex, flt32 fNoise, uint16 *pwPeakList, uint16 wPeakListLen, uint8 byTrackFlag, uint16 *pwFirstPathLen)
  834. {
  835. flt32 *pfSincDataModel = g_afSincFilterDataList; // sinc模型
  836. uint8 bySincFactor = gg_stFirstPathParam.bySincFactor; // sinc因子
  837. flt32 fSnr = 0;
  838. flt32 fSincFactor = 0; // sinc门限因子
  839. flt32 fSincThreshold = 0; // sinc门限
  840. uint16 wSincValueIndex = 0;
  841. int16 wPeakPeakGap = 0; // 峰间距
  842. flt32 fPeakValue = 0; // 第一径峰值
  843. uint16 wPeakValuelIndex = 0; // 第一径峰值索引
  844. uint16 wTempIndex = 0;
  845. flt32 fTempValue = 0;
  846. uint16 awInvalidPeakValueList[PUB_SLOT_FRAME_LEN]; // 无效峰队列
  847. uint16 wInvalidPeakCounter = 0; // 无效峰计算器
  848. uint16 wInvalidPeakValuelIndex = 0; // 无效峰值索引
  849. uint8 byExistFlag = 0; // 存在标识
  850. uint16 wCounter = 0;
  851. // 保存sinc门限的测试用变量
  852. flt32 afSincDataTestList[2 * PUB_SLOT_FRAME_LEN + 1];
  853. memset(afSincDataTestList, 0, sizeof(flt32) * (2 * PUB_SLOT_FRAME_LEN + 1));
  854. memset(awInvalidPeakValueList, 0, sizeof(uint16) * PUB_SLOT_FRAME_LEN);
  855. // 根据信噪比调整信号门限
  856. // fSnr = (flt32)pfData[wMaxValueIndex] / fNoise;
  857. // if (fSnr < 10)
  858. // {
  859. // bySincFactor = bySincFactor * 0.95;
  860. // }
  861. // 遍历队列,以sinc规格重新计算第一径
  862. for (uint16 i = 0; i < wPeakListLen; i++)
  863. {
  864. // 生成sinc门限因子
  865. wPeakValuelIndex = pwPeakList[i]; // 当前峰值索引
  866. fPeakValue = pfData[wPeakValuelIndex]; // 当前峰值
  867. fSincFactor = fPeakValue * bySincFactor / 100; // sinc因子
  868. // 将sinc门限保存到文件
  869. // if (i >= 0) {
  870. // // 计算sinc门限索引
  871. // wStartIndex = 16000 - wPeakValuelIndex;
  872. // for (uint16 sincIndex = 0; sincIndex < 16000; sincIndex++) {
  873. // afSincDataTestList[sincIndex] = pfSincDataModel[wStartIndex] * fSincFactor;
  874. // wStartIndex++;
  875. // }
  876. // // 保存sinc门限到文件
  877. // char filePath[256];
  878. // char fileIndex[8];
  879. // memset(filePath, 0, 256);
  880. // memset(fileIndex, 0, 8);
  881. // char* fileName = "sincthres";
  882. // itoa(i, fileIndex, 10);
  883. // char* fileTail = ".txt";
  884. // char* filePathHead = "E:\\05item\\ips\\location\\output\\sincthres\\";
  885. // strcat(filePath, filePathHead);
  886. // strcat(filePath, fileName);
  887. // strcat(filePath, fileIndex);
  888. // strcat(filePath, fileTail);
  889. // util_write_real_number_to_txt_file(filePath, 16000, afSincDataTestList);
  890. // }
  891. // sinc检查
  892. for (uint16 j = 0; j < wPeakListLen; j++)
  893. {
  894. wTempIndex = pwPeakList[j];
  895. fTempValue = pfData[wTempIndex];
  896. if (wTempIndex != wPeakValuelIndex)
  897. {
  898. ////计算sinc滤波器的索引
  899. // 被检查峰在当前峰的左侧
  900. wSincValueIndex = 0;
  901. if (wPeakValuelIndex > wTempIndex)
  902. {
  903. wPeakPeakGap = wPeakValuelIndex - wTempIndex; // 两峰间距
  904. wSincValueIndex = PUB_SLOT_FRAME_LEN - wPeakPeakGap;
  905. // // 如果是遮挡峰,则降低主峰左侧700-1200点区间内的检查门限,以正确选出遮挡峰
  906. // if ((wPeakValuelIndex - wTempIndex) > 700 && (wPeakValuelIndex - wTempIndex) <= 1200 && i == (wPeakListLen - 1)) {
  907. // fSincThreshold = pfSincDataModel[wSincValueIndex] * fSincFactor * 0.6; // 门限
  908. // } else {
  909. // fSincThreshold = pfSincDataModel[wSincValueIndex] * fSincFactor; // 门限
  910. // }
  911. }
  912. // 被检查峰在当前峰的右侧
  913. else
  914. {
  915. wPeakPeakGap = wTempIndex - wPeakValuelIndex; // 两峰间距
  916. wSincValueIndex = PUB_SLOT_FRAME_LEN + wPeakPeakGap; // 检查峰在右侧
  917. }
  918. // 修正选峰门限。峰间隔超过1500,说明存在严重的多径现象
  919. if (wPeakPeakGap > 1500)
  920. {
  921. fSincThreshold = pfSincDataModel[wSincValueIndex] * fSincFactor * 0.90; // sinc门限
  922. }
  923. else
  924. {
  925. fSincThreshold = pfSincDataModel[wSincValueIndex] * fSincFactor; // sinc门限
  926. }
  927. // 当前峰不合法
  928. if (fTempValue <= fSincThreshold)
  929. {
  930. awInvalidPeakValueList[wInvalidPeakCounter] = wTempIndex;
  931. wInvalidPeakCounter++;
  932. }
  933. }
  934. }
  935. }
  936. // 存在无效峰
  937. if (wInvalidPeakCounter > 0)
  938. {
  939. wCounter = 0;
  940. // 遍历有效峰队列
  941. for (uint16 k = 0; k < wPeakListLen; k++)
  942. {
  943. byExistFlag = 0;
  944. wPeakValuelIndex = pwPeakList[k]; // 峰值索引;
  945. // 遍历无效峰队列
  946. for (uint16 m = 0; m < wInvalidPeakCounter; m++)
  947. {
  948. wInvalidPeakValuelIndex = awInvalidPeakValueList[m];
  949. if (wPeakValuelIndex == wInvalidPeakValuelIndex)
  950. {
  951. byExistFlag = 1;
  952. break;
  953. }
  954. }
  955. if (!byExistFlag)
  956. { // 在无效峰值队列总没有找到,则保存该峰值索引
  957. pwPeakList[wCounter] = wPeakValuelIndex;
  958. wCounter++;
  959. }
  960. }
  961. // 更新队列长度
  962. if (wCounter > 0)
  963. {
  964. *pwFirstPathLen = wCounter;
  965. }
  966. else
  967. {
  968. *pwFirstPathLen = 1;
  969. if (byTrackFlag == 0)
  970. {
  971. pwPeakList[0] = wMaxValueIndex; // 最大值索引
  972. }
  973. else if (byTrackFlag == 1)
  974. { // 跟踪径计算
  975. pwPeakList[0] = 0; // 索引默认值,标识跟踪失败
  976. }
  977. }
  978. }
  979. // 没有无效峰
  980. else
  981. {
  982. *pwFirstPathLen = wPeakListLen;
  983. }
  984. return;
  985. }
  986. // 检查锚点是否是合法峰
  987. // pwPeakList:峰值索引队列
  988. // wPeakListLen:峰值索引队列长度
  989. // wAnchorIndex:锚点索引
  990. // wMaxValueIndex:最大值索引
  991. // pwAnchorIndex:锚点索引,返回值
  992. // 返回值
  993. void lct_firstpath_check_anchor_index(uint16 *pwPeakList, uint16 wPeakListLen, uint16 wAnchorIndex, uint16 wMaxValueIndex, uint16 *pwAnchorIndex, uint16 *pwPeakListLen)
  994. {
  995. uint16 wTempIndex = 0;
  996. uint8 byExistFlag = 0;
  997. // int32 dwGap = 0;
  998. uint16 wCounter = wPeakListLen;
  999. uint16 wTemp = 0;
  1000. // 遍历队列检查峰值索引是否包含锚点
  1001. for (uint16 i = 0; i < wPeakListLen; i++)
  1002. {
  1003. wTempIndex = pwPeakList[i];
  1004. if (wTempIndex == wAnchorIndex)
  1005. {
  1006. byExistFlag = 1;
  1007. break;
  1008. }
  1009. }
  1010. // // 锚点在峰值索引队列中
  1011. // if (byExistFlag)
  1012. // {
  1013. // *pwAnchorIndex = wAnchorIndex;
  1014. // }
  1015. // // 锚点不在峰值索引队列中
  1016. // else
  1017. // {
  1018. // dwGap = abs(wMaxValueIndex - wAnchorIndex);
  1019. // // 相差了3.5米
  1020. // if (dwGap > 500)
  1021. // {
  1022. // *pwAnchorIndex = wAnchorIndex; // 最大值与锚点间间隔大于440
  1023. // // 把锚点重新加入队列
  1024. // pwPeakList[wPeakListLen] = wAnchorIndex;
  1025. // wCounter++;
  1026. // // 对峰值列表重新排序(从小到大)
  1027. // for (uint16 k = 0; k < wCounter; k++)
  1028. // {
  1029. // for (uint16 m = k + 1; m < wCounter; m++)
  1030. // {
  1031. // if (pwPeakList[m] < pwPeakList[k])
  1032. // {
  1033. // wTemp = pwPeakList[k];
  1034. // pwPeakList[k] = pwPeakList[m];
  1035. // pwPeakList[m] = wTemp;
  1036. // }
  1037. // }
  1038. // }
  1039. // }
  1040. // // 相差不到3米
  1041. // else
  1042. // {
  1043. // *pwAnchorIndex = wMaxValueIndex; // 最大值索引当成锚点
  1044. // }
  1045. // }
  1046. // 锚点不在峰值队列中
  1047. if (!byExistFlag)
  1048. {
  1049. // 把锚点重新加入队列
  1050. pwPeakList[wPeakListLen] = wAnchorIndex;
  1051. wCounter++;
  1052. // 对峰值队列重新排序(从小到大)
  1053. for (uint16 k = 0; k < wCounter; k++)
  1054. {
  1055. for (uint16 m = k + 1; m < wCounter; m++)
  1056. {
  1057. if (pwPeakList[m] < pwPeakList[k])
  1058. {
  1059. wTemp = pwPeakList[k];
  1060. pwPeakList[k] = pwPeakList[m];
  1061. pwPeakList[m] = wTemp;
  1062. }
  1063. }
  1064. }
  1065. }
  1066. *pwAnchorIndex = wAnchorIndex;
  1067. *pwPeakListLen = wCounter;
  1068. return;
  1069. }
  1070. // 检测第一径各峰是否能关联到锚点
  1071. // pdwData:定位数据
  1072. // pwPeakList:峰值队列
  1073. // wPeakListLen:峰值队列长度
  1074. // pwOriginalList:原始峰值队列
  1075. // wOriginalListLen:原始峰值队列长度
  1076. // wAnchorIndex:锚点
  1077. // wMaxValueIndex:最大值索引
  1078. // pwFirstPathIndex:第一径索引
  1079. // 返回值,1:成功,0:失败
  1080. void lct_firstpath_check_first_path_contact(flt32 *pfData, uint16 *pwPeakList, uint16 wPeakListLen, uint16 *pwOriginalList, uint16 wOriginalListLen, uint16 wAnchorIndex, uint16 wMaxValueIndex, uint16 *pwFirstPathIndex)
  1081. {
  1082. uint8 byContactFactor = gg_stFirstPathParam.byFirstPathContactFactor;
  1083. uint16 wContactDistance = gg_stFirstPathParam.wFirstPathContactDistance;
  1084. uint16 wPeakValueIndex = 0; // 峰值索引
  1085. // 第一峰
  1086. flt32 fFirstpeakValue = 0;
  1087. uint16 wFirstPeakIndex = 0;
  1088. // 第二峰
  1089. flt32 fSecondPeakValue = 0;
  1090. uint16 wSecondPeakIndex = 0;
  1091. flt32 fSecondpeakThreshold = 0; // 选择第二峰的门限
  1092. uint8 bySelectFlag = 0; // 关联锚点标识,1:关联成功,0:关联失败
  1093. // 依次检查第一径是否能关联到锚点
  1094. if (wPeakListLen > 1)
  1095. { // 有两个点或以上
  1096. for (uint16 i = 0; i < wPeakListLen - 1; i++)
  1097. {
  1098. wPeakValueIndex = pwPeakList[i];
  1099. wFirstPeakIndex = pwPeakList[i];
  1100. fFirstpeakValue = pfData[wFirstPeakIndex]; // 第一峰峰值
  1101. fSecondpeakThreshold = (fFirstpeakValue / 100) * byContactFactor;
  1102. for (uint16 k = 0; k < wOriginalListLen; k++)
  1103. {
  1104. wSecondPeakIndex = pwOriginalList[k];
  1105. if (wSecondPeakIndex > wFirstPeakIndex)
  1106. {
  1107. fSecondPeakValue = pfData[wSecondPeakIndex]; // 第二峰峰值
  1108. // 第二峰有效
  1109. if (fSecondPeakValue > fSecondpeakThreshold)
  1110. {
  1111. // 第二峰与第一峰间的距离“满足”系统要求
  1112. if ((wSecondPeakIndex - wFirstPeakIndex) <= wContactDistance)
  1113. {
  1114. // 关联成功
  1115. if ((wSecondPeakIndex == wAnchorIndex) || (wSecondPeakIndex == wMaxValueIndex))
  1116. {
  1117. *pwFirstPathIndex = wPeakValueIndex; // 保存真正的第一径索引
  1118. bySelectFlag = 1;
  1119. break;
  1120. }
  1121. else
  1122. { // 关联失败,继续向后查找
  1123. wFirstPeakIndex = wSecondPeakIndex;
  1124. fFirstpeakValue = fSecondPeakValue;
  1125. fSecondpeakThreshold = (fFirstpeakValue / 100) * byContactFactor;
  1126. }
  1127. }
  1128. else
  1129. { // 第二峰与第一峰间的距离“不满足”系统要求
  1130. bySelectFlag = 0;
  1131. break;
  1132. }
  1133. }
  1134. }
  1135. }
  1136. if (bySelectFlag)
  1137. {
  1138. break;
  1139. }
  1140. }
  1141. if (!bySelectFlag)
  1142. { // 没有关联成功
  1143. *pwFirstPathIndex = wAnchorIndex; // 锚点为第一径
  1144. }
  1145. }
  1146. else
  1147. { // 只有一个峰
  1148. *pwFirstPathIndex = pwPeakList[wPeakListLen - 1];
  1149. }
  1150. return;
  1151. }
  1152. /******************************************************上面是计算径*********************************************/
  1153. /******************************************************下面是跟踪径*********************************************/
  1154. // 计算"跟踪径"
  1155. // pfData:原始信号
  1156. // wTrackIndex:跟踪索引
  1157. // fNoise:噪声
  1158. // fSelPeakThreshold:选峰门限
  1159. // wAnchorIndex:锚点索引
  1160. // pstTrackPath:跟踪径(返回参数)
  1161. void lct_firstpath_cal_trackpath(flt32 *pfData, uint16 wTrackIndex, flt32 fNoise, flt32 fSelPeakThreshold, uint16 wAnchorIndex, uint16 wMaxValueIndex, FIRST_PATH_T *pstTrackPath)
  1162. {
  1163. uint16 awPeakList[2 * PUBLIC_LCT_TRACK_WINDOW_WIDTH + 1]; // 峰值索引队列
  1164. uint16 wPeakListLen = 0; // 峰值索引队列长度
  1165. memset(awPeakList, 0, sizeof(uint16) * (2 * PUBLIC_LCT_TRACK_WINDOW_WIDTH + 1));
  1166. // 选跟踪峰,不超过最大峰值索引
  1167. lct_firstpath_sel_track_peak(pfData, wMaxValueIndex, wTrackIndex, awPeakList, &wPeakListLen);
  1168. // 补偿峰值增益
  1169. lct_firstpath_compensate_peak_gain(pfData, awPeakList, wPeakListLen);
  1170. // 将最大值添加到峰值队列中
  1171. awPeakList[wPeakListLen] = wMaxValueIndex;
  1172. wPeakListLen++;
  1173. //// 基于门限规则计算第一径
  1174. lct_firstpath_cal_first_path_by_peak_value_threshold(pfData, wMaxValueIndex, fSelPeakThreshold, awPeakList, wPeakListLen, 1, &wPeakListLen);
  1175. // 基于CFAR规则检查第一径
  1176. lct_firstpath_cal_first_path_by_cfar(pfData, wMaxValueIndex, awPeakList, wPeakListLen, 1, &wPeakListLen);
  1177. // 基于SINC规则检查第一径
  1178. lct_firstpath_cal_first_path_by_sinc(pfData, wMaxValueIndex, fNoise, awPeakList, wPeakListLen, 1, &wPeakListLen);
  1179. // 跟踪失败
  1180. if (wPeakListLen <= 1)
  1181. {
  1182. pstTrackPath->byTrackSuccessFlag = 0;
  1183. }
  1184. // 跟踪径成功
  1185. else
  1186. {
  1187. pstTrackPath->byTrackSuccessFlag = 1;
  1188. pstTrackPath->wFirstPathIndex = awPeakList[0];
  1189. pstTrackPath->fSnr = pfData[awPeakList[0]] / fNoise;
  1190. }
  1191. return;
  1192. }
  1193. // // 选择跟踪窗口中的峰
  1194. // // pfData:定位数据
  1195. // // fPeakValueThreshold:选峰门限
  1196. // // wTrackIndex:跟踪索引
  1197. // // wMaxValueIndex:最大值索引
  1198. // // pwPeakList:峰值索引队列
  1199. // // pwPeakListLen:峰值索引队列长度
  1200. // void lct_firstpath_trackpath_select_peak(flt32 *pfData, flt32 fPeakValueThreshold, uint16 wTrackIndex, uint16 wMaxValueIndex, uint16 *pwPeakList, uint16 *pwPeakListLen)
  1201. // {
  1202. // uint16 wGuardWidth = gg_stFirstPathParam.wFirstPathTrackPeakGuardWidth; // 跟踪峰保护带宽
  1203. // uint16 wTrackWindowWidth = gg_stFirstPathParam.wFirstPathTrackWindowWidth; // 跟踪窗口宽度
  1204. // uint16 wStartIndex = 0;
  1205. // uint16 wStopIndex = 0;
  1206. // uint16 wListLen = 0;
  1207. // // 计算开始引
  1208. // if ((wTrackIndex - wGuardWidth - wTrackWindowWidth) >= 0)
  1209. // {
  1210. // wStartIndex = wTrackIndex - wGuardWidth - wTrackWindowWidth;
  1211. // }
  1212. // else
  1213. // {
  1214. // wStartIndex = 0;
  1215. // }
  1216. // // 计算结束索引
  1217. // if ((wTrackIndex + wGuardWidth + wTrackWindowWidth + 1) < PUB_SLOT_FRAME_LEN)
  1218. // {
  1219. // wStopIndex = wTrackIndex + wGuardWidth + wTrackWindowWidth + 1;
  1220. // }
  1221. // else
  1222. // {
  1223. // wStopIndex = PUB_SLOT_FRAME_LEN;
  1224. // }
  1225. // // 选左侧峰
  1226. // // 选右侧峰
  1227. // // 从定位数据中,在跟踪径左右两侧选峰
  1228. // lct_firstpath_select_peak(pfData, fPeakValueThreshold, wMaxValueIndex, 1, wTrackIndex, wStartIndex, wStopIndex, pwPeakList, &wListLen);
  1229. // // 跟踪径两侧未选到峰
  1230. // if (!wListLen)
  1231. // {
  1232. // pwPeakList[0] = wTrackIndex;
  1233. // wListLen++;
  1234. // }
  1235. // *pwPeakListLen = wListLen;
  1236. // return;
  1237. // }
  1238. // 补偿跟踪窗口内的峰值增益
  1239. // pfData:定位数据
  1240. // pwPeakList:峰值索引队列
  1241. // pwPeakListLen:峰值索引队列长度
  1242. void lct_firstpath_compensate_peak_gain(flt32 *pfData, uint16 *pwPeakList, uint16 wPeakListLen)
  1243. {
  1244. uint16 wGuardWidth = gg_stFirstPathParam.wFirstPathTrackPeakGuardWidth; // 跟踪峰保护带宽
  1245. uint16 wFindWidth = gg_stFirstPathParam.wFirstPathTrackNoiseFindWidth; // 补偿增益时噪声选择窗口宽度
  1246. uint8 byPeakGainFactor = gg_stFirstPathParam.byFirstPathTrackPeakGainFactor; // 增益补偿因子
  1247. flt32 fPeakRatio = 0; // 峰值比例
  1248. uint16 wPeakValueIndex = 0;
  1249. flt32 fPeakValue = 0;
  1250. uint16 wStartIndex = 0;
  1251. uint16 wStopIndex = 0;
  1252. flt32 fNoiseValue = 0;
  1253. flt32 fTmpValue = 0;
  1254. // 遍历峰值队列,计算峰值补偿增益
  1255. for (uint16 i = 0; i < wPeakListLen; i++)
  1256. {
  1257. wPeakValueIndex = pwPeakList[i];
  1258. fPeakValue = pfData[wPeakValueIndex];
  1259. fNoiseValue = 0;
  1260. // 计算开始索引
  1261. if ((wPeakValueIndex - wGuardWidth - wFindWidth) >= 0)
  1262. {
  1263. wStartIndex = wPeakValueIndex - wGuardWidth - wFindWidth;
  1264. }
  1265. else
  1266. {
  1267. wStartIndex = 0;
  1268. }
  1269. // 计算结束索引
  1270. if ((wStartIndex + wFindWidth) <= (wPeakValueIndex - wGuardWidth))
  1271. {
  1272. wStopIndex = wStartIndex + wFindWidth;
  1273. }
  1274. else
  1275. {
  1276. wStopIndex = wPeakValueIndex - wGuardWidth;
  1277. }
  1278. // 查找噪声(wStartIndex 到 wStopIndex范围内的最大值)
  1279. for (uint16 i = wStartIndex; i < wStopIndex; i++)
  1280. {
  1281. fTmpValue = pfData[i];
  1282. if (fTmpValue > fNoiseValue)
  1283. {
  1284. fNoiseValue = fTmpValue;
  1285. }
  1286. }
  1287. // 计算增益因子
  1288. fPeakRatio = (fPeakValue / fNoiseValue * byPeakGainFactor) / 100;
  1289. if (fPeakRatio > 1.2)
  1290. {
  1291. fPeakRatio = 1.2;
  1292. }
  1293. else if (fPeakRatio < 0.5)
  1294. {
  1295. fPeakRatio = 0.5;
  1296. }
  1297. // 补偿增益
  1298. pfData[wPeakValueIndex] = fPeakValue * fPeakRatio;
  1299. }
  1300. return;
  1301. }
  1302. // 镜像当前第一径数据,以便一下次计算时使用
  1303. void lct_firstpath_mirror_first_path_data(LCT_FIRSTPATH_LIST_T *pstFirstPathList, LCT_FIRSTPATH_LIST_T *pstAheadFirstPathList)
  1304. {
  1305. uint8 byCounter = pstFirstPathList->byBtsNum;
  1306. // 镜像第一径数据
  1307. for (uint8 i = 0; i < byCounter; i++)
  1308. {
  1309. memcpy(&pstAheadFirstPathList->astFirstPath[i], &pstFirstPathList->astFirstPath[i], sizeof(LCT_FIRSTPATH_T));
  1310. }
  1311. pstAheadFirstPathList->byBtsNum = byCounter;
  1312. return;
  1313. }
  1314. // 反向镜像第一径数据(用前一次的第一径数据填充当前一次第一径数据)
  1315. void lct_firstpath_demirror_first_path_data(LCT_FIRSTPATH_LIST_T *pstFirstPathList, LCT_FIRSTPATH_LIST_T *pstAheadFirstPathList)
  1316. {
  1317. uint8 byCounter = 0;
  1318. byCounter = pstAheadFirstPathList->byBtsNum;
  1319. // 镜像第一径数据
  1320. for (uint8 i = 0; i < byCounter; i++)
  1321. {
  1322. memcpy(&pstFirstPathList->astFirstPath[i], &pstAheadFirstPathList->astFirstPath[i], sizeof(LCT_FIRSTPATH_T));
  1323. pstFirstPathList->astFirstPath[i].dwCalPathIndex += PUB_SIGNAL_SAMPLE_RATIO;
  1324. pstFirstPathList->astFirstPath[i].dwTrackPathIndex += PUB_SIGNAL_SAMPLE_RATIO;
  1325. }
  1326. pstFirstPathList->byBtsNum = byCounter;
  1327. return;
  1328. }
  1329. // 从上一次第一径数据中获得当前需要跟踪的索引
  1330. uint16 lct_firstpath_get_trackpath(LCT_FIRSTPATH_LIST_T *pstAheadFirstPathList, uint32 dwBuildId, uint32 dwLayerId, uint32 dwBtsId, uint8 byFreqIndex, uint8 bySlot)
  1331. {
  1332. uint8 byCounter = 0;
  1333. uint32 dwTmpBuildId = 0;
  1334. uint32 dwTmpLayerId = 0;
  1335. uint32 dwTmpBtsId = 0;
  1336. uint8 byTmpFreqIndex = 0;
  1337. uint8 byTmpSlot = 0;
  1338. uint16 wTrackIndex = 0;
  1339. byCounter = pstAheadFirstPathList->byBtsNum;
  1340. for (uint8 i = 0; i < byCounter; i++)
  1341. {
  1342. dwTmpBuildId = pstAheadFirstPathList->astFirstPath[i].dwBuildId;
  1343. dwTmpLayerId = pstAheadFirstPathList->astFirstPath[i].dwLayerId;
  1344. dwTmpBtsId = pstAheadFirstPathList->astFirstPath[i].dwBtsId;
  1345. byTmpFreqIndex = pstAheadFirstPathList->astFirstPath[i].byFreqIndex;
  1346. byTmpSlot = pstAheadFirstPathList->astFirstPath[i].bySlot;
  1347. // 上一次第一径参数中有该基站
  1348. if ((dwTmpBuildId == dwBuildId) && (dwTmpLayerId == dwLayerId) && (dwTmpBtsId == dwBtsId) && (byTmpFreqIndex == byFreqIndex) && (byTmpSlot == bySlot))
  1349. {
  1350. if (pstAheadFirstPathList->astFirstPath[i].wFrameTrackIndex)
  1351. {
  1352. wTrackIndex = pstAheadFirstPathList->astFirstPath[i].wFrameTrackIndex; // 上一次帧内跟踪索引
  1353. }
  1354. else
  1355. {
  1356. wTrackIndex = pstAheadFirstPathList->astFirstPath[i].wFrameCalIndex; // 上一次帧内计算索引
  1357. }
  1358. break;
  1359. }
  1360. }
  1361. return wTrackIndex;
  1362. }
  1363. // 拷贝前一次第一径数据,本次bit表征值为0,则沿用前一次的第一径数据
  1364. // pstFirstPath:第一径数据
  1365. // pstAheadFirstPathList:前一次第一径数据
  1366. // dwSyncOffset:同步偏移
  1367. void lct_firstpath_copy_ahead_first_path(LCT_FIRSTPATH_T *pstFirstPath, uint32 dwLocationIndex, uint8 byCalSlot, LCT_FIRSTPATH_LIST_T *pstAheadFirstPathList)
  1368. {
  1369. uint8 byBtsNum = 0;
  1370. LCT_FIRSTPATH_T stAheadFirstPath = {0};
  1371. byBtsNum = pstAheadFirstPathList->byBtsNum;
  1372. for (uint8 i = 0; i < byBtsNum; i++)
  1373. {
  1374. stAheadFirstPath = pstAheadFirstPathList->astFirstPath[i];
  1375. if (pstFirstPath->dwBuildId == stAheadFirstPath.dwBuildId && pstFirstPath->dwLayerId == stAheadFirstPath.dwLayerId && pstFirstPath->dwBtsId == stAheadFirstPath.dwBtsId && pstFirstPath->byFreqIndex == stAheadFirstPath.byFreqIndex && pstFirstPath->bySlot == stAheadFirstPath.bySlot)
  1376. {
  1377. // 跟踪径有效,则用跟踪径
  1378. if (stAheadFirstPath.wFrameTrackIndex > 0)
  1379. {
  1380. pstFirstPath->wFrameCalIndex = stAheadFirstPath.wFrameTrackIndex;
  1381. pstFirstPath->wFrameTrackIndex = stAheadFirstPath.wFrameTrackIndex;
  1382. pstFirstPath->dwCalPathIndex = dwLocationIndex + byCalSlot * PUB_SLOT_FRAME_LEN + stAheadFirstPath.wFrameTrackIndex;
  1383. pstFirstPath->dwTrackPathIndex = dwLocationIndex + byCalSlot * PUB_SLOT_FRAME_LEN + stAheadFirstPath.wFrameTrackIndex;
  1384. if (stAheadFirstPath.fTrackPathIndexSnr <= 0)
  1385. {
  1386. pstFirstPath->fCalPathIndexSnr = 3.5;
  1387. pstFirstPath->fTrackPathIndexSnr = 3.5;
  1388. }
  1389. else
  1390. {
  1391. pstFirstPath->fCalPathIndexSnr = stAheadFirstPath.fTrackPathIndexSnr;
  1392. pstFirstPath->fTrackPathIndexSnr = stAheadFirstPath.fTrackPathIndexSnr;
  1393. }
  1394. }
  1395. // 跟踪径无效,则用计算径
  1396. else
  1397. {
  1398. pstFirstPath->wFrameCalIndex = stAheadFirstPath.wFrameCalIndex;
  1399. pstFirstPath->wFrameTrackIndex = stAheadFirstPath.wFrameCalIndex;
  1400. pstFirstPath->dwCalPathIndex = dwLocationIndex + byCalSlot * PUB_SLOT_FRAME_LEN + stAheadFirstPath.wFrameCalIndex;
  1401. pstFirstPath->dwTrackPathIndex = dwLocationIndex + byCalSlot * PUB_SLOT_FRAME_LEN + stAheadFirstPath.wFrameCalIndex;
  1402. if (stAheadFirstPath.fCalPathIndexSnr <= 0)
  1403. {
  1404. pstFirstPath->fCalPathIndexSnr = 3.5;
  1405. pstFirstPath->fTrackPathIndexSnr = 3.5;
  1406. }
  1407. else
  1408. {
  1409. pstFirstPath->fCalPathIndexSnr = stAheadFirstPath.fCalPathIndexSnr;
  1410. pstFirstPath->fTrackPathIndexSnr = stAheadFirstPath.fCalPathIndexSnr;
  1411. }
  1412. }
  1413. break;
  1414. }
  1415. }
  1416. }
  1417. // 所有基站拷贝前一次第一径数据,本次bit表征值为0,则沿用前一次的第一径数据
  1418. // pstLocationDataList:定位数据队列
  1419. // pstAheadFirstPathList:前一次第一径数据队列
  1420. // pstFirstPathList:第一径数据队列(返回参数)
  1421. void lct_firstpath_copy_ahead_first_path_for_all_bts(PUB_LOCATION_DATA_T *pstLocationDataList, LCT_FIRSTPATH_LIST_T *pstAheadFirstPathList, LCT_FIRSTPATH_LIST_T *pstFirstPathList)
  1422. {
  1423. uint8 byBtsNum = 0;
  1424. LCT_FIRSTPATH_T *pstAheadFirstPath = NULL;
  1425. LCT_FIRSTPATH_T *pstFirstPath = NULL;
  1426. PUB_LOCATION_DATA_T *pstLctData = NULL;
  1427. uint8 byIndex = 0;
  1428. byBtsNum = pstAheadFirstPathList->byBtsNum;
  1429. for (uint8 i = 0; i < byBtsNum; i++)
  1430. {
  1431. pstAheadFirstPath = &pstAheadFirstPathList->astFirstPath[i];
  1432. byIndex = pstAheadFirstPath->byFreqIndex;
  1433. pstLctData = &pstLocationDataList[byIndex];
  1434. pstFirstPath = &pstFirstPathList->astFirstPath[i];
  1435. memcpy(pstFirstPath, pstAheadFirstPath, sizeof(LCT_FIRSTPATH_T));
  1436. // 跟踪径有效,则用跟踪径
  1437. if (pstAheadFirstPath->wFrameTrackIndex > 0)
  1438. {
  1439. pstFirstPath->wFrameCalIndex = pstAheadFirstPath->wFrameTrackIndex;
  1440. pstFirstPath->wFrameTrackIndex = pstAheadFirstPath->wFrameTrackIndex;
  1441. pstFirstPath->dwCalPathIndex = pstLctData->dwLocationIndex + pstLctData->byCalSlot * PUB_SLOT_FRAME_LEN + pstAheadFirstPath->wFrameTrackIndex;
  1442. pstFirstPath->dwTrackPathIndex = pstLctData->dwLocationIndex + pstLctData->byCalSlot * PUB_SLOT_FRAME_LEN + pstAheadFirstPath->wFrameTrackIndex;
  1443. if (pstAheadFirstPath->fTrackPathIndexSnr <= 0)
  1444. {
  1445. pstFirstPath->fCalPathIndexSnr = 3.5;
  1446. pstFirstPath->fTrackPathIndexSnr = 3.5;
  1447. }
  1448. else
  1449. {
  1450. pstFirstPath->fCalPathIndexSnr = pstAheadFirstPath->fTrackPathIndexSnr;
  1451. pstFirstPath->fTrackPathIndexSnr = pstAheadFirstPath->fTrackPathIndexSnr;
  1452. }
  1453. }
  1454. // 跟踪径无效,则用计算径
  1455. else
  1456. {
  1457. pstFirstPath->wFrameCalIndex = pstAheadFirstPath->wFrameCalIndex;
  1458. pstFirstPath->wFrameTrackIndex = pstAheadFirstPath->wFrameCalIndex;
  1459. pstFirstPath->dwCalPathIndex = pstLctData->dwLocationIndex + pstLctData->byCalSlot * PUB_SLOT_FRAME_LEN + pstAheadFirstPath->wFrameCalIndex;
  1460. pstFirstPath->dwTrackPathIndex = pstLctData->dwLocationIndex + pstLctData->byCalSlot * PUB_SLOT_FRAME_LEN + pstAheadFirstPath->wFrameCalIndex;
  1461. if (pstAheadFirstPath->fCalPathIndexSnr <= 0)
  1462. {
  1463. pstFirstPath->fCalPathIndexSnr = 3.5;
  1464. pstFirstPath->fTrackPathIndexSnr = 3.5;
  1465. }
  1466. else
  1467. {
  1468. pstFirstPath->fCalPathIndexSnr = pstAheadFirstPath->fCalPathIndexSnr;
  1469. pstFirstPath->fTrackPathIndexSnr = pstAheadFirstPath->fCalPathIndexSnr;
  1470. }
  1471. }
  1472. }
  1473. pstFirstPathList->byBtsNum = byBtsNum;
  1474. return;
  1475. }
  1476. // 重新计算绝对索引
  1477. uint32 lct_firstpath_recal_absolute_index(uint32 dwOldIndex)
  1478. {
  1479. uint32 dwNewIndex = 0;
  1480. if (dwOldIndex >= 0 && dwOldIndex < PUB_SLOT_FRAME_LEN)
  1481. {
  1482. dwNewIndex = dwOldIndex;
  1483. }
  1484. else if (dwOldIndex >= PUB_SLOT_FRAME_LEN && dwOldIndex < 2 * PUB_SLOT_FRAME_LEN)
  1485. {
  1486. dwNewIndex = dwOldIndex - PUB_SLOT_FRAME_LEN;
  1487. }
  1488. else if (dwOldIndex >= 2 * PUB_SLOT_FRAME_LEN && dwOldIndex < 3 * PUB_SLOT_FRAME_LEN)
  1489. {
  1490. dwNewIndex = dwOldIndex - 2 * PUB_SLOT_FRAME_LEN;
  1491. }
  1492. else if (dwOldIndex >= 3 * PUB_SLOT_FRAME_LEN && dwOldIndex < 4 * PUB_SLOT_FRAME_LEN)
  1493. {
  1494. dwNewIndex = dwOldIndex - 3 * PUB_SLOT_FRAME_LEN;
  1495. }
  1496. else
  1497. {
  1498. dwNewIndex = 0;
  1499. }
  1500. return dwNewIndex;
  1501. }
  1502. // 复位预测方向数据有效标识符
  1503. void lct_firstpath_reset_direction_valid_flag(LCT_FIRSTPATH_PREDICTION_DIRECTION_DATA_T *pstPredictionDirectionDataList)
  1504. {
  1505. LCT_FIRSTPATH_PREDICTION_DIRECTION_DATA_T *pstData = NULL;
  1506. for (uint8 i = 0; i < PUB_SYS_CARRIER_NUM; i++)
  1507. {
  1508. pstData = &pstPredictionDirectionDataList[i];
  1509. pstData->byValidFlag = 0;
  1510. }
  1511. return;
  1512. }
  1513. // 保存第一径数据
  1514. // pstLctData:定位数据
  1515. // pstFirstPathData:第一径数据
  1516. // pstPredictionDirectionDataList:预测方向数据队列,返回参数
  1517. void lct_firstpath_save_first_path_data(PUB_LOCATION_DATA_T *pstLctData, LCT_FIRSTPATH_T *pstFirstPathData, LCT_FIRSTPATH_PREDICTION_DIRECTION_DATA_T *pstPredictionDirectionDataList)
  1518. {
  1519. uint8 byFreqIndex = 0;
  1520. LCT_FIRSTPATH_PREDICTION_DIRECTION_DATA_T *pstResultData = NULL;
  1521. uint32 dwBackupIndex = 0;
  1522. byFreqIndex = pstLctData->byFreqIndex; // 频率索引
  1523. pstResultData = &pstPredictionDirectionDataList[byFreqIndex]; // 预测方向的数据
  1524. dwBackupIndex = pstResultData->dwFirstPathBackupIndex; // 数据备份索引
  1525. flt32 fAmpl = 0;
  1526. if (dwBackupIndex < LCT_FIRST_PATH_BACKUP_NUM)
  1527. {
  1528. pstResultData->dwFirstPathBackupIndex++;
  1529. pstResultData->astFirstPathBackupList[dwBackupIndex].dwFrameNo = pstLctData->dwFrameNo - 1; // 帧号
  1530. pstResultData->astFirstPathBackupList[dwBackupIndex].fMaxAmplValue = pstFirstPathData->fMaxAmplValue; // 幅度
  1531. pstResultData->astFirstPathBackupList[dwBackupIndex].dwCalPathIndex = pstFirstPathData->dwCalPathIndex; // 计算径
  1532. pstResultData->astFirstPathBackupList[dwBackupIndex].dwTrackPathIndex = pstFirstPathData->dwTrackPathIndex; // 跟踪经
  1533. }
  1534. else
  1535. {
  1536. // 移动队列
  1537. memmove(pstResultData->astFirstPathBackupList, &pstResultData->astFirstPathBackupList[1], sizeof(LCT_FIRSTPATH_BACKUP_T) * (LCT_FIRST_PATH_BACKUP_NUM - 1));
  1538. // 保存数据
  1539. dwBackupIndex = LCT_FIRST_PATH_BACKUP_NUM - 1;
  1540. pstResultData->astFirstPathBackupList[dwBackupIndex].dwFrameNo = pstLctData->dwFrameNo - 1; // 帧号
  1541. pstResultData->astFirstPathBackupList[dwBackupIndex].fMaxAmplValue = pstFirstPathData->fMaxAmplValue; // 幅度
  1542. pstResultData->astFirstPathBackupList[dwBackupIndex].dwCalPathIndex = pstFirstPathData->dwCalPathIndex; // 计算径
  1543. pstResultData->astFirstPathBackupList[dwBackupIndex].dwTrackPathIndex = pstFirstPathData->dwTrackPathIndex; // 跟踪经
  1544. }
  1545. pstResultData->dwCoordX = pstFirstPathData->dwCoordX;
  1546. pstResultData->dwCoordY = pstFirstPathData->dwCoordY;
  1547. pstResultData->dwCoordZ = pstFirstPathData->dwCoordZ;
  1548. // 计算径
  1549. pstResultData->dwCalPathIndex = pstFirstPathData->dwCalPathIndex;
  1550. // 有效标识符置1
  1551. pstResultData->byValidFlag = 1;
  1552. }
  1553. // 预测移动方向
  1554. // pstPredictionDirectionDataList:预测方向的数据队列
  1555. void lct_firstpath_prediction_move_direction(LCT_FIRSTPATH_PREDICTION_DIRECTION_DATA_T *pstPredictionDirectionDataList)
  1556. {
  1557. LCT_FIRSTPATH_PREDICTION_DIRECTION_DATA_T *pstPredictionData = NULL;
  1558. uint8 byLen = 0;
  1559. LCT_FIRSTPATH_BACKUP_T *pstCurrentData = NULL; // 当前数据
  1560. LCT_FIRSTPATH_BACKUP_T *pstAheadData = NULL; // 前一帧数据
  1561. uint32 dwFrameGap = 0;
  1562. uint8 byAheadTendency = 0;
  1563. uint8 byCurrentTendency = 0;
  1564. for (uint8 i = 0; i < PUB_SYS_CARRIER_NUM; i++)
  1565. {
  1566. pstPredictionData = &pstPredictionDirectionDataList[i];
  1567. byAheadTendency = pstPredictionData->byDirectionTendency; // 保存上一次趋势
  1568. pstPredictionData->byDirectionTendency = 0; // 方向趋势复位
  1569. // 遍历方向数据队列
  1570. byLen = pstPredictionData->dwFirstPathBackupIndex;
  1571. if (byLen >= LCT_FIRST_PATH_BACKUP_NUM)
  1572. {
  1573. pstCurrentData = &pstPredictionData->astFirstPathBackupList[byLen - 1];
  1574. pstAheadData = pstPredictionData->astFirstPathBackupList;
  1575. dwFrameGap = pstCurrentData->dwFrameNo - pstAheadData->dwFrameNo;
  1576. if (dwFrameGap == 8) // 数据有效
  1577. {
  1578. // 第一径维度靠近该基站
  1579. if ((pstCurrentData->dwCalPathIndex <= pstAheadData->dwCalPathIndex) || (pstCurrentData->dwTrackPathIndex <= pstAheadData->dwTrackPathIndex))
  1580. {
  1581. pstPredictionData->byDirectionTendency = 1; // 靠近
  1582. // 上一次是靠近该基站
  1583. if (byAheadTendency == 1)
  1584. {
  1585. pstPredictionData->byDirectionTendency = 1; // 靠近
  1586. }
  1587. // 上一次是远离该基站
  1588. else if (byAheadTendency == 2)
  1589. {
  1590. // 幅度维度靠近该基站
  1591. if (pstCurrentData->fMaxAmplValue >= (0.85 * pstAheadData->fMaxAmplValue))
  1592. {
  1593. pstPredictionData->byDirectionTendency = 1; // 靠近
  1594. }
  1595. else
  1596. {
  1597. pstPredictionData->byDirectionTendency = 2; // 远离
  1598. }
  1599. }
  1600. }
  1601. // 第一径维度远离该基站
  1602. else
  1603. {
  1604. pstPredictionData->byDirectionTendency = 2; // 远离
  1605. // 上一次是靠近该基站
  1606. if (byAheadTendency == 1)
  1607. {
  1608. // 幅度维度靠近该基站
  1609. if (pstCurrentData->fMaxAmplValue >= (0.9 * pstAheadData->fMaxAmplValue))
  1610. {
  1611. pstPredictionData->byDirectionTendency = 1; // 靠近
  1612. }
  1613. else
  1614. {
  1615. pstPredictionData->byDirectionTendency = 2; // 远离
  1616. }
  1617. }
  1618. // 上一次是远离该基站
  1619. else if (byAheadTendency == 2)
  1620. {
  1621. pstPredictionData->byDirectionTendency = 2; // 远离
  1622. }
  1623. }
  1624. }
  1625. }
  1626. }
  1627. }