slr pm2.5 correction implementation

This commit is contained in:
samuelbles07
2024-11-02 11:02:36 +07:00
parent 641003f9d1
commit a98d77e0c3
6 changed files with 41 additions and 0 deletions

View File

@ -314,6 +314,36 @@ int PMSBase::pm25ToAQI(int pm02) {
return 500;
}
/**
* @brief SLR correction for PM2.5
*
* Reference: https://www.airgradient.com/blog/low-readings-from-pms5003/
*
* @param pm25 PM2.5 raw value
* @param pm003Count PM0.3 count
* @param scalingFactor Scaling factor
* @param intercept Intercept
* @return float Calibrated PM2.5 value
*/
float PMSBase::slrCorrection(float pm25, float pm003Count, float scalingFactor, float intercept) {
float calibrated;
float lowCalibrated = (scalingFactor * pm003Count) + intercept;
if (lowCalibrated < 31) {
calibrated = lowCalibrated;
} else {
calibrated = pm25;
}
// No negative value for pm2.5
if (calibrated < 0) {
return 0.0;
}
return calibrated;
}
/**
* @brief Correction PM2.5
*

View File

@ -39,6 +39,7 @@ public:
uint8_t getErrorCode(void);
int pm25ToAQI(int pm02);
float slrCorrection(float pm25, float pm003Count, float scalingFactor, float intercept);
float compensate(float pm25, float humidity);
private:

View File

@ -172,6 +172,10 @@ int PMS5003::getPm10ParticleCount(void) { return pms.getCount10(); }
*/
int PMS5003::convertPm25ToUsAqi(int pm25) { return pms.pm25ToAQI(pm25); }
float PMS5003::slrCorrection(float pm25, float pm003Count, float scalingFactor, float intercept) {
return pms.slrCorrection(pm25, pm003Count, scalingFactor, intercept);
}
/**
* @brief Correct PM2.5
*

View File

@ -42,6 +42,7 @@ public:
int getPm10ParticleCount(void);
int convertPm25ToUsAqi(int pm25);
float slrCorrection(float pm25, float pm003Count, float scalingFactor, float intercept);
float compensate(float pm25, float humidity);
int getFirmwareVersion(void);
uint8_t getErrorCode(void);

View File

@ -205,6 +205,10 @@ float PMS5003T::getRelativeHumidity(void) {
return pms.getHum() / 10.0f;
}
float PMS5003T::slrCorrection(float pm25, float pm003Count, float scalingFactor, float intercept) {
return pms.slrCorrection(pm25, pm003Count, scalingFactor, intercept);
}
/**
* @brief Correct PM2.5
*

View File

@ -45,6 +45,7 @@ public:
int convertPm25ToUsAqi(int pm25);
float getTemperature(void);
float getRelativeHumidity(void);
float slrCorrection(float pm25, float pm003Count, float scalingFactor, float intercept);
float compensate(float pm25, float humidity);
int getFirmwareVersion(void);
uint8_t getErrorCode(void);