Ejemplo n.º 1
0
Archivo: FSKModem.c Proyecto: EQ4/FSK
/*****************************************
功能:  解调 从InDataBuf开始Lenth 这么长的数据 里,用MobileType方式,解调出数据,存在OutDataBuf里
反回时,解到哪个点放在OutLenIndix里
本函数调用的函数清单: 无
调用本函数的函数清单: main
输入参数:  *InDataBuf    采样值地址
lenth        总长度
输出参数:  *OutDataBuf   数据保存的地方
*OutLenIndix  解到哪里
函数返回值说明:    0:出错,1:没有滤波  2:需要滤波
使用的资源 
******************************************/
int    Demodulate(BYTE *OutDataBuf, short *InDataBuf,
									  unsigned long lenth,unsigned long *OutLenIndix)
{
	BYTE LoopForSmooth = 0;// 0 是第一次,1是第二次
	BYTE DemodulationResult = 0;// 找同步头和解调的结果,1为成功,0为失败

	unsigned long lLowF = 0;
	unsigned long lHighF = 0;
	int MobileType = 3; // 表示频率5.5k,解调的频率是固定的

	for(LoopForSmooth = 0;LoopForSmooth < 2; LoopForSmooth++ )
	{
		if(LoopForSmooth == 1)//两次循环,先不滤波,解不出来再滤波。
		{
			printf("start Smoothing wave\n");//
			
			lLowF = (unsigned long)((float)(2000*2/(MobileType+1))*(float)(1.0/32.0 * (float)(MobileType+1)+15.0/16.0));
			lHighF = (unsigned long)((float)(15000*2/(MobileType+1))*(float)(1.0/16.0 * (float)(MobileType+1)+7.0/8.0));

			memcpy(InDataBuf,(char*)InDataBuf+lenth*2,lenth*2);
			SmoothingWave(InDataBuf,lenth, lLowF, lHighF, 44100);
			*OutLenIndix = 0;
		}
		DisInterference(InDataBuf,lenth,MobileType);//去扰
		DemodulationResult = FindHead(InDataBuf,lenth,OutLenIndix,MobileType);//找同步头
		if( DemodulationResult == 1)//如果找到了,则解
		{
			DemodulationResult = GetAllData(OutDataBuf,InDataBuf,lenth,OutLenIndix,MobileType);//解调
		}

		if(LoopForSmooth == 0)
		{
			if(DemodulationResult == 1)//continue;//第一次解不出来,滤波后再解
			{
				printf("with no need for Smoothing wave\n");//
				return 1;//第一次就解出来了,说明是没有滤波就解出来了
			}
		}
		else if(LoopForSmooth == 1)
		{
			if(DemodulationResult == 0)
			{
				return 0;//第二次还解不出来,出错了
			}
			else
			{
				printf("need Smoothing wave\n");//
				return 2;//第二次才解出来,说明需要滤波
			}
		}

	}
	return 0;//出错了
}
Ejemplo n.º 2
0
/*****************************************
 功能:  解调 从InDataBuf开始Lenth 这么长的数据 里,用MobileType方式,解调出数据,保存在OutDataBuf里
 反回时,解到哪个点放在OutLenIndix里,校验会在里面处理好
 本函数调用的函数清单: 无
 调用本函数的函数清单: main
 输入参数:  *InDataBuf    采样值地址
 lenth        总长度
 MmobileType  手机类型
 输出参数:  *OutDataBuf   数据保存的地方
 *OutLenIndix  解到哪里
 
 函数返回值说明:    0:出错,1:没有滤波  2:需要滤波
 使用的资源
 ******************************************/
int    CFSKModem::Demodulate(BYTE *OutDataBuf, short *InDataBuf,
                             unsigned long lenth,unsigned long *OutLenIndix,BYTE MobileType)
{
	BYTE LoopForSmooth = 0;// 0 是第一次,1是第二次
	BYTE DemodulationResult = 0;// 找同步头和解调的结果,1为成功,0为失败
    
	for(LoopForSmooth = 0;LoopForSmooth <2 ; LoopForSmooth++ )
	{
		if(LoopForSmooth == 1)//两次循环,先不滤波,解不出来再滤波。
		{
			unsigned long lLowF = 0;
			unsigned long lHighF = 0;
			lLowF = (unsigned long)((float)(2000*2/(MobileType+1))*(float)(1.0/32.0 * (float)(MobileType+1)+15.0/16.0));
			lHighF = (unsigned long)((float)(15000*2/(MobileType+1))*(float)(1.0/16.0 * (float)(MobileType+1)+7.0/8.0));
            
			memcpy(InDataBuf,(char*)InDataBuf+lenth*2,lenth*2);
			SmoothingWave(InDataBuf,lenth, lLowF, lHighF, FS);
			//	SmoothingWave(InDataBuf,lenth);
			*OutLenIndix = 0;
		}
        
		
		this->DisInterference(InDataBuf,lenth,MobileType);//去扰
		DemodulationResult = this->FindHead(InDataBuf,lenth,OutLenIndix,MobileType);//找同步头
		if( DemodulationResult == 1)//如果找到了,则解
		{
			DemodulationResult = this->GetAllData(OutDataBuf,InDataBuf,lenth,OutLenIndix,MobileType);//解调
		}
        
		if(LoopForSmooth == 0)
		{
			if(DemodulationResult == 1)//continue;//第一次解不出来,滤波后再解
			{
				return 1;//第一次就解出来了,说明是没有滤波就解出来了
			}
		}
		else if(LoopForSmooth == 1)
		{
			if(DemodulationResult == 1)
			{
				return 2;//第二次还解不出来,出错了
			}
			else
			{
				return DemodulationResult ;//第二次才解出来,说明需要滤波
			}
		}
        
	}
	return 0;//出错了
}