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

📄 dsp.c

📁 使用C8051F实现脉搏及血氧饱和度测量 包括均值滤波
💻 C
字号:
#include "sample.h"
#define uchar unsigned char
#define uint unsigned int
#define FILTLEN 7
#define DELSTEP 7
#define DELGATE 50
unsigned int DataPos;
unsigned long DC_RED;
unsigned long DC_IRED;
unsigned char RED_MIN,RED_MAX;
unsigned char IRED_MIN,IRED_MAX;
xdata unsigned char SampleRed[SAMPLESIZE];
xdata unsigned char SampleIRed[SAMPLESIZE];
xdata unsigned char ProBuffer[SAMPLESIZE];

void itoa(uint i,uchar *c)
{
 	char l;
	if(i>=1000)
		l=3;
	else if(i>=100)
		l=2;
	else if(i>=10)
		l=1;
	else
		l=0;
	c[l+1]=0;
	while(l>=0)
	{
		c[l]=i%10+0x30;
		i/=10;
		l--;
	}
}

void Filter(uchar Data[SAMPLESIZE],uchar Min,uchar Max)	 //均值滤波
{
	uint i;
	float t;
	for	(i=0;i<FILTLEN/2;i++)
	{
		t=Data[i];
		t=(t-Min)*255/(Max-Min)+0.5;
		ProBuffer[i]=(uchar)t;

		t=Data[SAMPLESIZE-i-1];
		t=(t-Min)*255/(Max-Min)+0.5;
		ProBuffer[SAMPLESIZE-i-1]=(uchar)t;
	}
	for(i=FILTLEN/2;i<SAMPLESIZE-FILTLEN/2;i++)
	{
		t=Data[i-3]+Data[i-2]+Data[i-1]+Data[i]+Data[i+1]+Data[i+2]+Data[i+3];
		t/=FILTLEN;
		t=(t-Min)*255/(Max-Min)+0.5;
		ProBuffer[i]=(uchar)t;
	}
}
void Process(uchar OriData[SAMPLESIZE],uchar * Freq,uchar * Delta)
{							  
	xdata uint PeakPos[15],MinPos[15],MaxPos[15];
	uint i;
	float Time,DeltaTemp=0;
	int t;
	uchar j,Peak=0,PeakLen=0,MinValue=255,MaxValue=0;
	for	(i=DELSTEP;i<SAMPLESIZE;i++)
	{
		  t=ProBuffer[i-DELSTEP]-ProBuffer[i];
		  if(t>DELGATE)
		  {
		  	   if(Peak<t)
			   {
			   		Peak=t;
					PeakPos[PeakLen]=i;
				}
		  }
		  else if(Peak>0)
		  {
		  		Peak=0;
				PeakLen++;		
		  }
  	}
	//PeakLen--;
	Time=0;
	for(j=0;j<PeakLen-1;j++)
		Time+=PeakPos[j+1]-PeakPos[j];
	Time=12000.0/Time*(PeakLen-1)+0.5;
	*Freq=(uchar)Time;
	/////////////////////////////////////////////
	for(j=0;j<PeakLen-1;j++)
	{
	 	 MinPos[j]=0;
		 MaxPos[j]=0;
		 MinValue=255;
		 MaxValue=0;
		 for(i=PeakPos[j];i<PeakPos[j+1];i++)
		 {
		 	 if(ProBuffer[i]<MinValue)
			 {
			 	MinValue=ProBuffer[i];
				MinPos[j]=i;
			 }
			 if(ProBuffer[i]>MaxValue)
			 {
			 	MaxValue=ProBuffer[i];
				MaxPos[j]=i;
			 }
		 }
	}
	for(j=0;j<PeakLen-1;j++)
		DeltaTemp+=OriData[MaxPos[j]]-OriData[MinPos[j]];
	DeltaTemp=DeltaTemp/(PeakLen-1)+0.5;
	*Delta=(uchar)DeltaTemp;
}
	

⌨️ 快捷键说明

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