#include "RT_TCM_AE.h"
//para1:信号 para2:平滑数
RT_TCM_AE::RT_TCM_AE(vector<float>Ae_data, int filter_size, int Frequency, int cut_threshold) :PI(3.1416), Frequency_length(65536)
{
this->len = filter_size;
this->_Frequency = Frequency;
this->_cut_threshold = cut_threshold;
filter_res.clear();
raw_data.clear();
time_value.clear();
WPT_res.clear();
raw_data = Ae_data;
filter_sum = 0;
//设置频域及时频域分析时所需的数据长度,其必须是2的幂级数
//数据过长会导致计算频域、时频域特征时堆栈溢出
if (_Frequency < Frequency_length) {
for (int i = 15; i > 0; --i) {
if (pow(2, i) < _Frequency) {
Frequency_length = pow(2, i);
break;
}
}
}
}
///功能描述:无参构造函数:调用SVM类时初始化
///param [I] 无
///返回值: 无
///备注:无
RT_TCM_AE::RT_TCM_AE() :PI(3.1416) {
}
//均值滤波+峰值计算
void RT_TCM_AE::cal_Peak() {
int length = raw_data.size();
for (int i = 0; i < length; ++i) {
filter_res.push_back(this->next(raw_data[i]));
}
////峰值提取
vector<float>peak_points = calculate_Peak(filter_res);
// cout << "峰值点数为:" << peak_points.size() << " ";
Fluctuation = calcalate_FD(peak_points, 0.7, 1.3);
}
//均值滤波步骤
float RT_TCM_AE::next(float val) {
que.push(val);
filter_sum += val;
while(que.size() > len) {
filter_sum -= que.front();//超出窗口容量,先把队首元素获取,在sum里减去
que.pop();//再把队首元素弹出
}
return filter_sum / que.size();
}
//获取峰值波动特征
float RT_TCM_AE::get_FD() {
return Fluctuation;
}
vector<float> RT_TCM_AE::calculate_Peak(vector<float> smooth_data) {
int length = smooth_data.size();
vector<float>peak_ans;
float avg = -1;
float sum = 0;
for (int i = 0; i < length; ++i) {
sum += smooth_data[i];
}
avg = float(sum / length);
vector<int> coordinate_x;
for (int i = 1; i < length - 1; ++i) {
if (smooth_data[i] > smooth_data[i - 1] && smooth_data[i] > smooth_data[i + 1] && smooth_data[i] >= avg) {//
if (!coordinate_x.empty()&&(i - coordinate_x.back() < 2000)) {
if (smooth_data[i] > peak_ans.back()) {
peak_ans.pop_back(); coordinate_x.pop_back();
coordinate_x.push_back(i); peak_ans.push_back(smooth_data[i]);
}
else {
continue;
}
}
else {
coordinate_x.push_back(i); peak_ans.push_back(smooth_data[i]);
}
}
}
return peak_ans;
}
float RT_TCM_AE::calcalate_FD(vector<float> data, float low_hold, float high_hold) {
int brow = data.size();
int vebral = 0;
float val = 0;
for (int i = 0; i < brow - 1; ++i) {
val = data[i] / data[i + 1];
if (val<=low_hold || val >= high_hold) {
vebral+=1;
}
}
//cout<<"超出范围为"<< vebral<<" ";
float ans = float(vebral)/float(brow);
return ans;
}
//判断是否加工区域
bool RT_TCM_AE::stage_cutting() {
float process_value = 0;
float decision_threshold = 0.15;//设定加工下限阈值
int datasize = raw_data.size();
for (int j = 0; j < datasize; ++j) {
process_value += raw_data[j];
}
//计算均值
float average = process_value / (float)datasize;
return average > decision_threshold;
}
//获取时域特征
vector<float> RT_TCM_AE::getTime() {
return time_value;
}
//计算时域特征
void RT_TCM_AE::cal_Time() {
float process_value = 0;
float Rms_value = 0;
float max_value = -1;
int datasize = raw_data.size();
for (int j = 0; j < datasize; ++j) {
if (raw_data[j] > max_value)max_value = raw_data[j];
process_value += raw_data[j];
Rms_value += raw_data[j] * raw_data[j];
}
//计算均值
float average = process_value / (float)datasize;
//计算均方根
float rms = Rms_value / (float)datasize;
//计算峰值因子
float perk = max_value / rms;
time_value.push_back(average);
time_value.push_back(rms);
time_value.push_back(perk);
}
////频域分析
inline void RT_TCM_AE::swap(float &a, float &b)
{
float t;
t = a;
a = b;
b = t;
}
void RT_TCM_AE::bitrp(float xreal[], float ximag[], int n)
{
// 位反转置换 Bit-reversal Permutation
int i, j, a, b, p;
for (i = 1, p = 0; i < n; i *= 2)
{
p++;
}
for (i = 0; i < n; i++)
{
a = i;
b = 0;
for (j = 0; j < p; j++)
{
b = (b << 1) + (a & 1); // b = b * 2 + a % 2;
a >>= 1; // a = a / 2;
}
if (b > i)
{
swap(xreal[i], xreal[b]);
swap(ximag[i], ximag[b]);
}
}
}
void RT_TCM_AE::FFT(float xreal[], float ximag[], int n)
{
// 快速傅立叶变换,将复数 x 变换后仍保存在 x 中,xreal, ximag 分别是 x 的实部和虚部
float *wreal = new float[_Frequency / 2];
float *wimag = new float[_Frequency / 2];
//float wreal[frequency / 2], wimag[frequency / 2];
float treal, timag, ureal, uimag, arg;
int m, k, j, t, index1, index2;
bitrp(xreal, ximag, n);
// 计算 1 的前 n / 2 个 n 次方根的共轭复数 W'j = wreal [j] + i * wimag [j] , j = 0, 1, ... , n / 2 - 1
arg = -2 * PI / n;
treal = cos(arg);
timag = sin(arg);
wreal[0] = 1.0;
wimag[0] = 0.0;
for (j = 1; j < n / 2; j++)
{
wreal[j] = wreal[j - 1] * treal - wimag[j - 1] * timag;
wimag[j] = wreal[j - 1] * timag + wimag[j - 1] * treal;
}
for (m = 2; m <= n; m *= 2)
{
for (k = 0; k < n; k += m)
{
for (j = 0; j < m / 2; j++)
{
index1 = k + j;
index2 = index1 + m / 2;
t = n * j / m; // 旋转因子 w 的实部在 wreal [] 中的下标为 t
treal = wreal[t] * xreal[index2] - wimag[t] * ximag[index2];
timag = wreal[t] * ximag[index2] + wimag[t] * xreal[index2];
ureal = xreal[index1];
uimag = ximag[index1];
xreal[index1] = ureal + treal;
ximag[index1] = uimag + timag;
xreal[index2] = ureal - treal;
ximag[index2] = uimag - timag;
}
}
}
//清除一维数组内存
delete[] wreal;
wreal = nullptr;
delete[] wimag;
wimag = nullptr;
}
void RT_TCM_AE::cal_FFT()
{
//动态数据创建实数、复数
float *xreal = new float[_Frequency];
float *ximag = new float[_Frequency];
//
//float xreal[frequency] = {}, ximag[frequency] = {};
//float xreal[frequency] = {}, ximag[frequency] = {0};
int n, i= Frequency_length;
for (int j = 0; j < i; ++j) {
xreal[j]=raw_data[j];
ximag[j]=0;
}
n = i; // 要求 n 为 2 的整数幂
while (i > 1)
{
if (i % 2)
{
printf( "%d is not a power of 2! ", n);
exit(1);
}
i /= 2;
}
FFT(xreal, ximag, n);
//printf( "FFT: i real imag\n");
float sum = 0;
for (i = 0; i < n; i++)
{
sum += xreal[i];
//printf( "%4d %8.4f %8.4f\n", i, xreal[i], ximag[i]);
}
fft_energy = sum / (float)n;
//清除一维数组内存
delete[] xreal;
xreal = nullptr;
delete[] ximag;
ximag = nullptr;
}
float RT_TCM_AE::get_FFT() {
return fft_energy;
}
//计算小波包能量比结果
void RT_TCM_AE::cal_WPT() {
vector<double>signal;
int data_size = Frequency_length;
for (int i = 0;i < data_size; ++i) {
signal.push_back(raw_data[i]);
}
std::vector<double> reconstructed_signal;
reconstructed_signal.resize(signal.size());
// Load well-known wavelet coefficients.
Wavelet wavelet;
Wavelet::GetWaveletCoefficients(&wavelet, Wavelet::WaveletType::Daubechies, 5);
// Construct wavelet packet tree of height = 3.
// This tree has 4 wavelet levels, and 4 leaves.
WaveletPacketTree tree(4, &wavelet);
tree.SetRootSignal(&signal);
tree.Decompose();
// Reconstruct signal one wavelet level at a time.
//cout << "小波包叶子为:" << tree.GetWaveletLevelCount() << endl;
vector<double>energy;
for (size_t i = 0; i < tree.GetWaveletLevelCount(); i++) {
tree.Reconstruct(i);
auto root_signal = tree.GetRootSignal();
// Add the coefficients of wavelet level i to the reconstructed signal.
std::transform(reconstructed_signal.cbegin(), reconstructed_signal.cend(), root_signal->cbegin(), reconstructed_signal.begin(), std::plus<double>());
//root_signal:最后一层小波包重构信号
double sum = 0;
for_each(root_signal->cbegin(), root_signal->cend(), [&](double x) {
sum += x;
});
sum = sqrtf(sum);
energy.push_back(sum);
}
//for_each(energy.begin(), energy.end(), [](float x) {
// cout << x << " ";
//});
double all_sum = 0;
for_each(energy.begin(), energy.end(), [&](double x) {
all_sum += x;
});
WPT_res.push_back(energy[2]/all_sum*100);
WPT_res.push_back(energy[4] / all
onnx
- 粉丝: 1w+
- 资源: 5627
最新资源
- 滑膜控制下的差动制动防侧翻稳定性精准控制 通过上层滑膜控制产生横摆力矩,结合下层制动力矩分配策略,实现车辆防侧翻稳定控制 联合仿真验证其有效性,资料完备 ,基于滑膜控制的差动制动防侧翻稳定性控制,上
- "移相全桥电源系统仿真建模:全面解析Matlab Simulink仿真与参数设计学习资料集",2KW移相全桥整机Matlab Simulink仿真模型电源学习资料,报告mathcad参数设计,模型搭建
- 基于风光不确定性及信息间隙决策理论的碳捕集综合能源系统鲁棒调度优化策略研究,考虑风光不确定性和IGDT信息间隙决策的综合能源系统优化调度 参考文献:基于信息间隙决策理论的碳捕集电厂调度 非完全复献
- CRUISE纯电动车仿真模型与Simulink DLL联合仿真:电制动优先能量回收策略详解与搭建指南(附详细文档),CRUISE纯电动车仿真模型,simulink DLL联合仿真,实现电制动优先能量回
- 车辆紧急防避撞AEB控制算法实现原理与仿真步骤详解:制动模型、模糊控制、逆动力学及阻力计算,车辆紧急防避撞AEB控制,模型包含建立驾驶员制动模型来模拟制动过程,同时加入模糊控制实现期望减速度的计算,加
- 基于LQR算法的横摆角速度跟踪控制技术研究:四轮独立驱动与动力学模型应用,四轮独立驱动横摆角速度控制,LQR 基于LQR算法的 基于二自由度动力学方程,通过主动转向afs和直接横摆力矩dyc实现的横摆
- 西门子S7-1200与S7-1500的动态加密功能块程序管理:设定停机运行时间,专防不守信客户实用指南及发货清单 ,西门子S7-1200 1500动态加密功能块程序,可以设置停机运行时间,时间到达设备
- MATLAB环境下深度学习预测NASA涡扇发动机退化仿真数据集剩余寿命方法,MATLAB环境下一种基于深度学习的NASA涡扇发动机 化仿真数据集剩余使用寿命预测方法 算法运行环境为matlab r2
- 异步电机矢量控制的Simulink模型设计与实现,异步电机矢量控制simulink模型 ,核心关键词:异步电机;矢量控制;Simulink模型;控制策略;仿真模型;电力传动系统 ,"异步电机矢量控制的
- 基于动态窗口算法的AGV仿真避障:起点至目标点的实时路径规划与障碍物处理,基于动态窗口算法的AGV仿真避障 可设置起点目标点,设置地图,设置移动障碍物起始点目标点,未知静态障碍物 动态窗口方法(Dyn
- 基于三菱PLC的定长送料程序:触摸屏操作,伺服与步进驱动,精准点动与定位控制,定长送料程序,三菱PLC加显触摸屏 伺服或者步进都可以 点动 相对定位 绝对定位 ,定长送料程序; 三菱PLC; 显触摸
- 基于A*算法的三维路径规划算法在无人机中的MATLAB实现,基于A* 算法的无人机三维路径规划算法,MATLAB编程实现 ,核心关键词:A*算法; 无人机; 三维路径规划; MATLAB编程实现
- PID与LQR主动悬架模型对比:汽车平顺性仿真及源代码详解,【PID和LQR主动悬架模型对比】 分别建立了PID控制和LQR控制的的主动悬架模型,比较两种控制器的控制效果 以悬架主动力
- 一维光子晶体态密度案例解析与探讨:理论与实践结合的研究实践,一维光子晶体态密度案例 ,一维光子晶体; 态密度; 案例; 实验结果; 理论分析,一维光子晶体态密度案例:光子态密度的研究与应用
- 级联H桥并网系统性能测试:精准电流控制下的电压稳定性与畸变率优化,级联H桥并网 10KV 每相12个H桥,单个H桥直流电压为850V,采用电流闭环控制 为了测试系统控制性能效果,在1s时,控制输出
- 级联H桥三相逆变器:离散化仿真下的开闭环控制策略与电压电流双闭环控制实现,级联H桥 离网三相逆变器采用级联H桥多电平拓扑,每个H桥直流测电压为24V,5个H桥串联(电压,H桥个数可以自己调加),系统
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈