地震检测系统

发布于:2022-12-16 ⋅ 阅读:(419) ⋅ 点赞:(0)

#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

 

本文含有隐藏内容,请 开通VIP 后查看

网站公告

今日签到

点亮在社区的每一天
去签到