优化滤波
This commit is contained in:
parent
7c95bc442c
commit
8fa77c8f91
@ -432,9 +432,9 @@ void Calculation::envSpec(std::vector<float> & vecData, std::vector<float> & vec
|
||||
|
||||
void Calculation::GenerateSin(std::vector<float> & vecData)
|
||||
{
|
||||
double frequency = 160.0; // Frequency of the sine wave in Hz
|
||||
double sampling_rate = 3200.0; // Sampling rate in Hz (8 kHz)
|
||||
size_t num_samples = 8000; // Total number of samples (1 second of data)
|
||||
double frequency = 800.0; // Frequency of the sine wave in Hz
|
||||
double sampling_rate = 12800.0; // Sampling rate in Hz (8 kHz)
|
||||
size_t num_samples = 12800; // Total number of samples (1 second of data)
|
||||
double dt = 1.0 / sampling_rate; // Time step in seconds
|
||||
|
||||
// Vector to hold the sine wave data
|
||||
@ -447,18 +447,19 @@ void Calculation::GenerateSin(std::vector<float> & vecData)
|
||||
|
||||
}
|
||||
|
||||
void Calculation::Integration(std::vector<float> & vecData,std::vector<float>& retData)
|
||||
void Calculation::Integration(std::vector<float> & vecData,std::vector<float>& retData,double & resolution)
|
||||
{
|
||||
std::vector<float> realshiftfft;
|
||||
|
||||
std::vector<float> realshiftfft;
|
||||
std::vector<float> imageshiftfft;
|
||||
std::vector<float> realvalue,imagevalue;
|
||||
_FFT(vecData,realshiftfft,imageshiftfft);
|
||||
|
||||
for (int i = 0; i < 5; i++) {
|
||||
for (int i = 0; i < 5 / resolution; i++) {
|
||||
realshiftfft[i] = 0;
|
||||
imageshiftfft[i] = 0;
|
||||
}
|
||||
for (int i = 1000; i < realshiftfft.size(); i++) {
|
||||
for (int i = 1000 / resolution ; i < realshiftfft.size(); i++) {
|
||||
realshiftfft[i] = 0;
|
||||
imageshiftfft[i] = 0;
|
||||
}
|
||||
@ -468,8 +469,67 @@ void Calculation::Integration(std::vector<float> & vecData,std::vector<float>& r
|
||||
imagevalue.push_back((imageshiftfft.at(k-1)/(k*2*M_PI))*1000 * 2);//单位转换mm/s,*1000
|
||||
}
|
||||
|
||||
//_iFFT(realshiftfft,imageshiftfft,retData);
|
||||
_iFFT(realvalue,imagevalue,retData);
|
||||
|
||||
|
||||
}
|
||||
|
||||
/*void acceleration_to_velocity(int fs, int N, float *data, int min_freq, int max_freq, float *out_data) {
|
||||
fftwf_execute_dft_r2c(forward_plan[fft_plan_id(N)], data, forward_out);
|
||||
|
||||
float df = fs * 1.0f / N;
|
||||
int ni = round(min_freq / df);
|
||||
int na = round(max_freq / df);
|
||||
float dw = 2 * fcl_pi * df;
|
||||
|
||||
int double_id = get_idle_double_res();
|
||||
if (double_id < 0) {
|
||||
return;
|
||||
}
|
||||
float *w11 = get_double_res_ptr(double_id);
|
||||
|
||||
int len = 0;
|
||||
int max_f = round((0.5 * fs - df) / df);
|
||||
|
||||
for (int i = 0; i <= max_f; ++i) {
|
||||
w11[i] = i * dw;
|
||||
++len;
|
||||
}
|
||||
|
||||
for (int i = 0; i < max_f; ++i) {
|
||||
w11[len] = -2 * fcl_pi * (0.5 * fs - df) + i * dw;
|
||||
++len;
|
||||
}
|
||||
|
||||
forward_out[0][0] = forward_out[0][1] = forward_out[N - 1][0] = forward_out[N - 1][1] = 0;
|
||||
float tmp_real, tmp_imag;
|
||||
for (int i = 1; i < N - 1; ++i) {
|
||||
tmp_real = forward_out[i][1] / w11[i];
|
||||
tmp_imag = -forward_out[i][0] / w11[i];
|
||||
forward_out[i][0] = tmp_real; // real
|
||||
forward_out[i][1] = tmp_imag; // imag
|
||||
}
|
||||
|
||||
free_double_res(double_id);
|
||||
|
||||
for (int i = 0; i < N; ++i) {
|
||||
backward_in[i][0] = 0;
|
||||
backward_in[i][1] = 0;
|
||||
}
|
||||
|
||||
for (int i = ni - 1; i < na; ++i) {
|
||||
backward_in[i][0] = forward_out[i][0];
|
||||
backward_in[i][1] = forward_out[i][1];
|
||||
}
|
||||
|
||||
for (int i = N - na; i < N - ni + 1; ++i) {
|
||||
backward_in[i][0] = forward_out[i][0];
|
||||
backward_in[i][1] = forward_out[i][1];
|
||||
}
|
||||
|
||||
fftwf_execute_dft(backward_plan[fft_plan_id(N)], backward_in, backward_out);
|
||||
|
||||
for (int i = 0; i < N; ++i) {
|
||||
out_data[i] = backward_out[i][0] / N * 2 * 1000; // *1000 是单位换算, 跟python保持一致
|
||||
}
|
||||
}*/
|
@ -152,7 +152,7 @@ public:
|
||||
//包络图谱数据
|
||||
void envSpec(std::vector<float> & vecData, std::vector<float> & vecEnvSpecData,int StartFrequency,int EndFrequency);
|
||||
|
||||
void Integration(std::vector<float> & vecData,std::vector<float>& retData);
|
||||
void Integration(std::vector<float> & vecData,std::vector<float>& retData,double & resolution);
|
||||
};
|
||||
|
||||
|
||||
|
@ -501,11 +501,9 @@ std::string SqliteDB::GetData(const char *tablename, const char *column, const c
|
||||
print_light_green("%s\n", strSql.c_str());
|
||||
// if (SqlSwitch()) log_system->log_write_system("[info]","%s\n", strSql.c_str());
|
||||
sqlite3_stmt *stmt;
|
||||
g_tDbMutex.Lock();
|
||||
if (sqlite3_prepare_v2(mDBAcess, strSql.c_str(), -1, &stmt, 0) != SQLITE_OK) {
|
||||
print_error("sqlite3_prepare_v2:%s\n", sqlite3_errmsg(mDBAcess));
|
||||
sqlite3_finalize(stmt);
|
||||
g_tDbMutex.UnLock();
|
||||
return strRes;
|
||||
}
|
||||
int retStep = sqlite3_step(stmt);
|
||||
@ -514,7 +512,6 @@ std::string SqliteDB::GetData(const char *tablename, const char *column, const c
|
||||
strRes = columninfo != NULL ? columninfo : "";
|
||||
}
|
||||
sqlite3_finalize(stmt);
|
||||
g_tDbMutex.UnLock();
|
||||
return strRes;
|
||||
}
|
||||
|
||||
@ -736,14 +733,12 @@ int SqliteDB::UpdateTableData(const char* tablename, const char* updateColumn, c
|
||||
print_light_green("%s\n", strSql.c_str());
|
||||
// if (SqlSwitch()) log_system->log_write_system("[info]","%s\n", strSql.c_str());
|
||||
char *msg;
|
||||
g_tDbMutex.Lock();
|
||||
int iRet = sqlite3_exec(GetDbHandle(isDB2), strSql.c_str(), 0, 0, &msg);
|
||||
|
||||
if (iRet != SQLITE_OK) {
|
||||
print_error("sqlite3 error: code=%d msg=%s\n", iRet, msg);
|
||||
sqlite3_free(msg);
|
||||
}
|
||||
g_tDbMutex.UnLock();
|
||||
return iRet;
|
||||
}
|
||||
|
||||
|
@ -2490,6 +2490,11 @@ std::string JsonData::JsonCmd_Cgi_55(Param_55 ¶m)
|
||||
char whereCon[64] = {};
|
||||
sprintf(whereCon, "dataNodeNo='%s'",param.mDataNodeNo.c_str());
|
||||
vec_t res = sql_ctl->GetDataSingleLine(T_SENSOR_INFO(TNAME)," * ",whereCon);
|
||||
int SampleRate =0;
|
||||
double resolution = 0.0;
|
||||
SampleRate = atoi(res[23].c_str());
|
||||
print_info("sensor type %s\n",res[17].c_str());
|
||||
|
||||
char localtimestamp[32] = { 0 };
|
||||
std::string strWaveData = "";
|
||||
std::string filename = "/opt/data/" + param.mChannelId + ".dat";
|
||||
@ -2507,9 +2512,26 @@ std::string JsonData::JsonCmd_Cgi_55(Param_55 ¶m)
|
||||
while (inFile.read((char *)&fTemp, sizeof(fTemp))) {
|
||||
vecWave.push_back(fTemp);
|
||||
}
|
||||
if(res[17]=="01"){
|
||||
|
||||
// //积分
|
||||
pCalculation->Integration(vecWave, IntegrationWave);
|
||||
printf("@@@@@@@@@@@@@@@@@@@@sample_rate=%d\n",SampleRate);
|
||||
resolution = (((double)SampleRate/1000)*1024)/ 8192;
|
||||
|
||||
}else if(res[17]=="02"){
|
||||
string::size_type comper = param.mChannelId.find("Z");
|
||||
if (comper != string::npos) {
|
||||
resolution = (double)SampleRate/vecWave.size();
|
||||
//resolution = (((double)vecWave.size()/1000)*1024)/ (SampleRate * ((vecWave.size()/SampleRate)));
|
||||
printf("@@@@@@@@@@@@@@@@@@@@sample_rate=%d,resolution = %f\n",SampleRate,resolution);
|
||||
}else{
|
||||
SampleRate = 8000;
|
||||
printf("@@@@@@@@@@@@@@@@@@@@sample_rate=%d\n",SampleRate);
|
||||
resolution = (((double)SampleRate/1024)*1024)/ 8192;
|
||||
}
|
||||
}
|
||||
|
||||
//积分
|
||||
pCalculation->Integration(vecWave, IntegrationWave,resolution);
|
||||
|
||||
//测试正弦波
|
||||
// pCalculation->GenerateSin(vecWave);
|
||||
@ -2600,6 +2622,12 @@ std::string JsonData::JsonCmd_Cgi_56(Param_56 ¶m)
|
||||
char whereCon[64] = {};
|
||||
sprintf(whereCon, "dataNodeNo='%s'",param.mDataNodeNo.c_str());
|
||||
vec_t res = sql_ctl->GetDataSingleLine(T_SENSOR_INFO(TNAME)," * ",whereCon);
|
||||
int SampleRate =0;
|
||||
double resolution = 0.0;
|
||||
SampleRate = atoi(res[23].c_str());
|
||||
print_info("sensor type %s\n",res[17].c_str());
|
||||
|
||||
|
||||
if (access(filename.c_str(), 0) >= 0)
|
||||
{
|
||||
std::ifstream inFile(filename.c_str(),ios::in|ios::binary);
|
||||
@ -2620,7 +2648,8 @@ std::string JsonData::JsonCmd_Cgi_56(Param_56 ¶m)
|
||||
vecWave.push_back(fTemp);
|
||||
}
|
||||
//积分
|
||||
pCalculation->Integration(vecWave, IntegrationWave);
|
||||
resolution = (double)SampleRate/vecWave.size();
|
||||
pCalculation->Integration(vecWave, IntegrationWave,resolution);
|
||||
pCalculation->FFTSpec(IntegrationWave, fftWave);
|
||||
sampleRateReference = 1000;
|
||||
|
||||
@ -2635,6 +2664,20 @@ std::string JsonData::JsonCmd_Cgi_56(Param_56 ¶m)
|
||||
}
|
||||
i++;
|
||||
}
|
||||
if(res[17]=="01"){
|
||||
|
||||
printf("@@@@@@@@@@@@@@@@@@@@sample_rate=%d\n",SampleRate);
|
||||
resolution = (((double)SampleRate/1000)*1024)/ 8192;
|
||||
//resolution = (double)SampleRate/vecWave.size();
|
||||
|
||||
}else if(res[17]=="02"){
|
||||
string::size_type comper = param.mChannelId.find("Z");
|
||||
{
|
||||
SampleRate = 8000;
|
||||
printf("@@@@@@@@@@@@@@@@@@@@sample_rate=%d\n",SampleRate);
|
||||
resolution = (((double)SampleRate/1024)*1024)/ 8192;
|
||||
}
|
||||
}
|
||||
//测试正弦波
|
||||
//pCalculation->GenerateSin(vecWave);
|
||||
|
||||
@ -2650,10 +2693,9 @@ std::string JsonData::JsonCmd_Cgi_56(Param_56 ¶m)
|
||||
// }
|
||||
|
||||
// //积分
|
||||
|
||||
pCalculation->Integration(vecWave, IntegrationWave);
|
||||
pCalculation->FFTSpec(IntegrationWave, fftWave);
|
||||
sampleRateReference = 1024;
|
||||
pCalculation->Integration(vecWave, IntegrationWave,resolution);
|
||||
pCalculation->FFTSpec(IntegrationWave, fftWave);
|
||||
sampleRateReference = 1024;
|
||||
}
|
||||
/*for(int i = 0; i < fftWave.size();i++){
|
||||
fftWave[i] = fftWave[i]*2;
|
||||
@ -2708,27 +2750,9 @@ std::string JsonData::JsonCmd_Cgi_56(Param_56 ¶m)
|
||||
jsBody["timestamp"] = string(localtimestamp);
|
||||
jsBody["Data"] = strWaveData;
|
||||
|
||||
double resolution = 0.0;
|
||||
int SampleRate =0;
|
||||
print_info("sensor type %s\n",res[17].c_str());
|
||||
if(res[17]=="01"){
|
||||
SampleRate = atoi(res[23].c_str());
|
||||
printf("@@@@@@@@@@@@@@@@@@@@sample_rate=%d\n",SampleRate);
|
||||
resolution = (((double)SampleRate/1000)*1024)/ 8192;
|
||||
|
||||
}else if(res[17]=="02"){
|
||||
string::size_type comper = param.mChannelId.find("Z");
|
||||
if (comper != string::npos) {
|
||||
SampleRate = atoi(res[23].c_str());
|
||||
resolution = (double)SampleRate/vecWave.size();
|
||||
//resolution = (((double)vecWave.size()/1000)*1024)/ (SampleRate * ((vecWave.size()/SampleRate)));
|
||||
printf("@@@@@@@@@@@@@@@@@@@@sample_rate=%d,resolution = %f\n",SampleRate,resolution);
|
||||
}else{
|
||||
SampleRate = 8000;
|
||||
printf("@@@@@@@@@@@@@@@@@@@@sample_rate=%d\n",SampleRate);
|
||||
resolution = (((double)SampleRate/1024)*1024)/ 8192;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
print_info("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@the sample rate is %d,the resolution %f\n",SampleRate,resolution);
|
||||
char buf[32];
|
||||
|
@ -54,8 +54,12 @@ void CheckThread()
|
||||
// StatusPub();
|
||||
if (GlobalConfig::LinkCount > 30) {
|
||||
#ifdef IMX6UL_GATEWAY
|
||||
LOG_ERROR("MQTT connect failed,reboot\n");
|
||||
exit(0);
|
||||
char connect[10]={0x00};
|
||||
readStringValue("config", "connect",connect,(char*)GlobalConfig::Config_G.c_str());
|
||||
if(atoi(connect)){
|
||||
LOG_ERROR("MQTT connect failed,reboot\n");
|
||||
exit(0);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
std::string ipTemp = IpAddrInit();
|
||||
|
Loading…
x
Reference in New Issue
Block a user