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

📄 correlate.cpp

📁 一个实现相关运算的源码
💻 CPP
字号:
#include "StdAfx.h"
#include "Correlate.h"
#include "TestDlg.h"


CCorrelate::CCorrelate(void)
{
	max=0;
	cor=NULL;

}

CCorrelate::~CCorrelate(void)
{
	if(cor!=NULL)
		delete [] cor;
}

////相关计算式
void CCorrelate::ccorr(int x[],int y[],int M)
{

	const int N=SIGNAL_LEN;			//x[]的实际长度	 M为 y[]的实际长度
	int L=M+N-1;				//相关(卷积)结果的实际长度
	int sum=0;					

	if(cor!=NULL)
		delete [] cor;
	cor=new float [L];

	for(int i1=0;i1<L;i1++)
	{
		cor[i1]=0;			//初始化cor[]
	}

	//x序列翻转
	for(int i2=0;i2<N/2;i2++)		
	{
		int temp=x[i2];
		x[i2]=x[N-i2-1];
		x[N-i2-1]=temp;
	}
	// x y 序列 补零
    for(int i=N;i<L;i++)
	{
		x[i]=0;
	}
	for(int j=M;j<L;j++)
    {
		y[j]=0;
	}

	//卷积运算
	for(int k=0;k<L;k++)
	{
		sum=0;
		for(int ii=0;ii<=k;ii++)
        sum+=x[ii]*y[k-ii];
        cor[k]=sum;
    }	

}

void CCorrelate::normolize(float data[],int len)
{
//	const int N=SIGNAL_LENTH;		len为序列长度
	for(int i=0;i<len;i++)
	{
		if(max<abs(data[i]))
		{
			max=abs(data[i]);
		}
	}

	for(int j=0;j<len;j++)
	{
		data[j]=(float)data[j]/max;
	}
	
}

⌨️ 快捷键说明

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