void CFreqSyncAcq::SetSearchWindow(_REAL rNewCenterFreq, _REAL rNewWinSize) { /* Set internal parameters */ rCenterFreq = rNewCenterFreq; rWinSize = rNewWinSize; /* Set flag to initialize the module to the new parameters */ SetInitFlag(); }
/* Implementation *************************************************************/ void CChannelEstimation::ProcessDataInternal(CParameter& ReceiverParam) { int i, j, k; int iModSymNum; _COMPLEX cModChanEst; _REAL rSNRAftTiInt; _REAL rCurSNREst; _REAL rOffsPDSEst; /* Check if symbol ID index has changed by the synchronization unit. If it has changed, reinit this module */ if ((*pvecInputData).GetExData().bSymbolIDHasChanged == TRUE) { SetInitFlag(); return; } /* Move data in history-buffer (from iLenHistBuff - 1 towards 0) */ for (j = 0; j < iLenHistBuff - 1; j++) { for (i = 0; i < iNumCarrier; i++) matcHistory[j][i] = matcHistory[j + 1][i]; } /* Write new symbol in memory */ for (i = 0; i < iNumCarrier; i++) matcHistory[iLenHistBuff - 1][i] = (*pvecInputData)[i]; /* Time interpolation *****************************************************/ /* Get symbol-counter for next symbol. Use the count from the frame synchronization (in OFDM.cpp). Call estimation routine */ rSNRAftTiInt = pTimeInt->Estimate(pvecInputData, veccPilots, ReceiverParam.matiMapTab[(*pvecInputData). GetExData().iSymbolID], ReceiverParam.matcPilotCells[(*pvecInputData). GetExData().iSymbolID], rSNREstimate); /* Debar initialization of channel estimation in time direction */ if (iInitCnt > 0) { iInitCnt--; /* Do not put out data in initialization phase */ iOutputBlockSize = 0; /* Do not continue */ return; } else iOutputBlockSize = iNumCarrier; /* Define DC carrier for robustness mode D because there is not pilot */ if (iDCPos != 0) veccPilots[iDCPos] = (CReal) 0.0; /* ------------------------------------------------------------------------- Use time-interpolated channel estimate for timing synchronization tracking */ TimeSyncTrack.Process(ReceiverParam, veccPilots, (*pvecInputData).GetExData().iCurTimeCorr, rLenPDSEst /* out */, rOffsPDSEst /* out */); /* Frequency-interploation ************************************************/ switch (TypeIntFreq) { case FLINEAR: /**********************************************************************\ * Linear interpolation * \**********************************************************************/ /* Set first pilot position */ veccChanEst[0] = veccPilots[0]; for (j = 0, k = 1; j < iNumCarrier - iScatPilFreqInt; j += iScatPilFreqInt, k++) { /* Set values at second time pilot position in cluster */ veccChanEst[j + iScatPilFreqInt] = veccPilots[k]; /* Interpolation cluster */ for (i = 1; i < iScatPilFreqInt; i++) { /* E.g.: c(x) = (c_4 - c_0) / 4 * x + c_0 */ veccChanEst[j + i] = (veccChanEst[j + iScatPilFreqInt] - veccChanEst[j]) / (_REAL) (iScatPilFreqInt) * (_REAL) i + veccChanEst[j]; } } break; case FDFTFILTER: /**********************************************************************\ * DFT based algorithm * \**********************************************************************/ /* --------------------------------------------------------------------- Put all pilots at the beginning of the vector. The "real" length of the vector "pcFFTWInput" is longer than the No of pilots, but we calculate the FFT only over "iNumCarrier / iScatPilFreqInt + 1" values (this is the number of pilot positions) */ /* Weighting pilots with window */ veccPilots *= vecrDFTWindow; /* Transform in time-domain */ veccPilots = Ifft(veccPilots, FftPlanShort); /* Set values outside a defined bound to zero, zero padding (noise filtering). Copy second half of spectrum at the end of the new vector length and zero out samples between the two parts of the spectrum */ veccIntPil.Merge( /* First part of spectrum */ veccPilots(1, iStartZeroPadding), /* Zero padding in the middle, length: Total length minus length of the two parts at the beginning and end */ CComplexVector(Zeros(iLongLenFreq - 2 * iStartZeroPadding), Zeros(iLongLenFreq - 2 * iStartZeroPadding)), /* Set the second part of the actual spectrum at the end of the new vector */ veccPilots(iNumIntpFreqPil - iStartZeroPadding + 1, iNumIntpFreqPil)); /* Transform back in frequency-domain */ veccIntPil = Fft(veccIntPil, FftPlanLong); /* Remove weighting with DFT window by inverse multiplication */ veccChanEst = veccIntPil(1, iNumCarrier) * vecrDFTwindowInv; break; case FWIENER: /**********************************************************************\ * Wiener filter * \**********************************************************************/ #ifdef UPD_WIENER_FREQ_EACH_DRM_FRAME /* Update filter coefficients once in one DRM frame */ if (iUpCntWienFilt > 0) { iUpCntWienFilt--; /* Get maximum delay spread and offset in one DRM frame */ if (rLenPDSEst > rMaxLenPDSInFra) rMaxLenPDSInFra = rLenPDSEst; if (rOffsPDSEst < rMinOffsPDSInFra) rMinOffsPDSInFra = rOffsPDSEst; } else { #else /* Update Wiener filter each OFDM symbol. Use current estimates */ rMaxLenPDSInFra = rLenPDSEst; rMinOffsPDSInFra = rOffsPDSEst; #endif /* Update filter taps */ UpdateWienerFiltCoef(rSNRAftTiInt, rMaxLenPDSInFra / iNumCarrier, rMinOffsPDSInFra / iNumCarrier); #ifdef UPD_WIENER_FREQ_EACH_DRM_FRAME /* Reset counter and maximum storage variable */ iUpCntWienFilt = iNumSymPerFrame; rMaxLenPDSInFra = (_REAL) 0.0; rMinOffsPDSInFra = rGuardSizeFFT; } #endif /* FIR filter of the pilots with filter taps. We need to filter the pilot positions as well to improve the SNR estimation (which follows this procedure) */ for (j = 0; j < iNumCarrier; j++) { /* Convolution */ veccChanEst[j] = _COMPLEX((_REAL) 0.0, (_REAL) 0.0); for (i = 0; i < iLengthWiener; i++) veccChanEst[j] += matcFiltFreq[j][i] * veccPilots[veciPilOffTab[j] + i]; } break; } /* Equalize the output vector ------------------------------------------- */ /* Write to output vector. Take oldest symbol of history for output. Also, ship the channel state at a certain cell */ for (i = 0; i < iNumCarrier; i++) { (*pvecOutputData)[i].cSig = matcHistory[0][i] / veccChanEst[i]; (*pvecOutputData)[i].rChan = SqMag(veccChanEst[i]); } /* ------------------------------------------------------------------------- Calculate symbol ID of the current output block and set parameter */ (*pvecOutputData).GetExData().iSymbolID = (*pvecInputData).GetExData().iSymbolID - iLenHistBuff + 1; /* SNR estimation ------------------------------------------------------- */ /* Modified symbol ID, check range {0, ..., iNumSymPerFrame} */ iModSymNum = (*pvecOutputData).GetExData().iSymbolID; while (iModSymNum < 0) iModSymNum += iNumSymPerFrame; for (i = 0; i < iNumCarrier; i++) { switch (TypeSNREst) { case SNR_PIL: /* Use estimated channel and compare it to the received pilots. This estimation works only if the channel estimation was successful */ /* Identify pilot positions. Use MODIFIED "iSymbolID" (See lines above) */ if (_IsScatPil(ReceiverParam.matiMapTab[iModSymNum][i])) { /* We assume that the channel estimation in "veccChanEst" is noise free (e.g., the wiener interpolation does noise reduction). Thus, we have an estimate of the received signal power \hat{r} = s * \hat{h}_{wiener} */ cModChanEst = veccChanEst[i] * ReceiverParam.matcPilotCells[iModSymNum][i]; /* Calculate and average noise and signal estimates --------- */ /* The noise estimation is difference between the noise reduced signal and the noisy received signal \tilde{n} = \hat{r} - r */ IIR1(rNoiseEst, SqMag(matcHistory[0][i] - cModChanEst), rLamSNREstFast); /* The received signal power estimation is just \hat{r} */ IIR1(rSignalEst, SqMag(cModChanEst), rLamSNREstFast); /* Calculate final result (signal to noise ratio) */ if (rNoiseEst != 0) rCurSNREst = rSignalEst / rNoiseEst; else rCurSNREst = (_REAL) 1.0; /* Bound the SNR at 0 dB */ if (rCurSNREst < (_REAL) 1.0) rCurSNREst = (_REAL) 1.0; /* Average the SNR with a two sided recursion */ IIR1TwoSided(rSNREstimate, rCurSNREst, rLamSNREstFast, rLamSNREstSlow); } break; case SNR_FAC: /* SNR estimation with initialization */ if (iSNREstInitCnt > 0) { /* Initial signal estimate. Use channel estimation from all cells. Apply averaging */ rSignalEst += (*pvecOutputData)[i].rChan; iSNREstInitCnt--; } else { /* Only right after initialization phase apply initial SNR value */ if (bWasSNRInit == TRUE) { /* Normalize average */ rSignalEst /= iNumCellsSNRInit; /* Apply initial SNR value */ rNoiseEst = rSignalEst / rSNREstimate; bWasSNRInit = FALSE; } /* Only use FAC cells for this SNR estimation method */ if (_IsFAC(ReceiverParam.matiMapTab[iModSymNum][i])) { /* Get tentative decision for current FAC cell (squared) */ CReal rCurErrPow = TentativeFACDec((*pvecOutputData)[i].cSig); /* Use decision together with channel estimate to get estimates for signal and noise */ IIR1(rNoiseEst, rCurErrPow * (*pvecOutputData)[i].rChan, rLamSNREstFast); IIR1(rSignalEst, (*pvecOutputData)[i].rChan, rLamSNREstFast); /* Calculate final result (signal to noise ratio) */ if (rNoiseEst != (_REAL) 0.0) rCurSNREst = rSignalEst / rNoiseEst; else rCurSNREst = (_REAL) 1.0; /* Bound the SNR at 0 dB */ if (rCurSNREst < (_REAL) 1.0) rCurSNREst = (_REAL) 1.0; /* The channel estimation algorithms need the SNR normalized to the energy of the pilots */ rSNREstimate = rCurSNREst / rSNRCorrectFact; } } break; } } }
void routine(){ START: if(SolarStatus()==1){ //if solar-panel is on solarcounter = 0; while (BatteryCharged()){ //if battery is charged if (ReadInitFlag()==0){ //check if its first initialisation of device GSM_ON(); //turn on GSM module SIM900_SEND(2); //send a configuration request message to server SetInitFlag(); //set initcheck flag } char c=0; while ((TEMP_INT==0)&&(c<=3)){ //check DHT11 sensor 3 times for reading if no data received getTempHum(); c++; } DayTEMP[tempcounter]=TEMP_INT; DayHUM[tempcounter]=RH_INT; tempcounter++; delay_1ms(1); sleep(); if (tempcounter==2){ days++; //increment days avgTempHum(); //calculate average temperature and humidity minmaxTempHum(); //calculate minimum and maximum temperature and humidity getConductivity(); //get conductivity value from sensor getWaterLevel(); //get water level from ultrasonic sensor ShiftData(); //shift gathered data by offset if ((WaterLevel-OFFSET) >= WATER_THRESHOLD){ //check if water level is too low SMS_data[0]=WARNING_PREFIX; //initiate message with warning char SMS_data[1]=WaterLevel; //put water level in text message SMS_data[2]=DATA_SUFFIX; //end message with suffix GSM_ON(); //turn on sim900 delay_1s(10); //wait for GSM to connect to network SIM900_SEND(1); //Send data message to server } } } if (!BatteryCharged()){ MonitorBattery(); } if (SolarStatus()==0) //if solar-panel is off goto OFF; goto START; } else { //when solar-panel is off OFF: SaveData(); //Sava sensor readings to memory tempcounter=0; //check if data transmission frequency is met if (days >= TRANSMIT_FREQ){ SMS_data[0]=DATA_PREFIX; //start message with prefix gatherData(); //read data from memory getCheckByte(); //calculate check byte GSM_ON(); //turn on sim900 delay_1s(10); //wait for GSM to connect to network SIM900_SEND(1); //Send data message to server days=0; } //reset days counter only after successful tranmsission //sleep for 6h for (char z=0; z<3; z++){ sleep(); } while (SolarStatus()==2){ //if solar-panel is off for (char z=0; z<5; z++){ delay_1s(60); } solarcounter++; if (solarcounter > SOLAR_THRESHOLD){ //turn on Fault LED goto START; } } } }