⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ar_singal.cpp

📁 提供AR模型已产生AR过程信号。在高斯白噪声的基础上
💻 CPP
字号:
#include<iostream>
#include<cmath>
#include<fstream>
#include<cstdlib>

using namespace std;
void AR(double x[],double A[],int N,int p);

int main()
{
    double x[256],W[100];
    double A[4]={-1.352,1.338,-0.662,0.240};
    int i;
    double E,var,temp_r,temp_i,f;

    fstream infile;
    infile.open("data.txt",ios::in);
    for(i=0;i<256;i++)
    {
	infile>>x[i];
    }
    infile.close();

    AR(x,A,N,p);

    fstream outfile1;
    outfile1.open("AR_P4.txt",ios::out);
    for(i=0;i<256;i++)
    {
	outfile1<<x[i]<<endl;
    }
    outfile1.close();    

    var=0.0;

    fstream outfile2;
    outfile2.open("../data/PSD_AR(4).txt",ios::out);
    for(i=0;i<100;i++)
    {
	temp_r=1.0;
	temp_i=0.0;
        f=(double)i/200;
	for(j=1;i<IP;j++)
	{	    
	    temp_r+=Ar[j-1]*cos(2*pi*f*j)+Ai[j-1]*sin(2*pi*f*j);
	    temp_i+=-Ar[j-1]*sin(2*pi*f*j)+Ai[j-1]*cos(2*pi*f*j);
	}
	var=(1.0+temp_r)*(1.0+temp_r)+(temp_i*temp_i);
	W[i]=1.0/var;
	outfile2<<f<<'\t'<<W[i]<<endl;

    }
    outfile2.close();

    return 0;
}

void AR(double x[],double A[],int N,int p)
{
    double temp;
    for(i=0;i<N;i++)
    {
	temp=0.0;
	for(j=1;j<=p,j++)
	{
	    if((i-k)>=0)temp+=A[i]*x[i-k];	    
	}
	x[i]-=temp;
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -