地震检测系统

该程序读取输入文件中的传感器数据,通过计算短/长时间窗口的能量值比来检测地震活动。用户输入短窗口和长窗口的点数,当比值超过阈值1.5时,标记可能的地震事件。程序使用了`power_w`函数来统计能量值。
摘要由CSDN通过智能技术生成

#include<fstream>
#include<iostream>
#include<Windows.h>
#include<string>
#include<cmath>
using namespace std;

const double THRESHOLD = 1.5;

//计算短/长时间窗口能量数据的采样值。
double power_w(double arr[], int length, int n);

int main()
{
    string filename;
    ifstream fin;
    int num =0,short_windows=0,long_windows=0;
    double time_incr =0,*sensor=NULL,short_power=0,long_power=0;
    double ratio;
    cout << "Enter name of input file" << endl;
    cin >> filename;
    fin.open(filename.c_str());
    if (fin.fail())
    {
        cerr << "error opening input file" << endl;
        exit(-1);
    }
    else
    {
        fin >> num >> time_incr;
        cout << "num:" << num << " time_incr:" << time_incr << endl;

        if (num >= 0) 
        {
            sensor = new double[num];
            
            for (int i = 0; i < num; i++)
            {
                fin >> sensor[i];
            }
            cout << "Enter number of points for short-windows" << endl;
            cin >> short_windows;

            cout << "Enter number of points for long-windows" << endl;
            cin >> long_windows;

            //分析能量数据找出地震时间
            for (int i = long_windows - 1; i < num; i++)
            {
                short_power = power_w(sensor, i, short_windows);
                long_power = power_w(sensor, i, long_windows);
                ratio = short_power / long_power;

                if (ratio> THRESHOLD)
                {
                    cout << "Possible event at"<<time_incr*i << "seconds"<<endl;
                }

            }
            delete[] sensor;

        }
         


        fin.close();
    }

    

    system("pause");
    return 0;
}
//统计短/长事件窗口对应的能量值
double power_w(double arr[], int length, int n)
{
    double xsquare = 0;
    for (int i = 0; i < n; i++)
    {
        xsquare += pow(arr[length - i], 2);
    }
    return xsquare / n;
}

978217b1089a40bba6925e5507c9a9c9.png

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值