#include "fpga_offset_addr.h"
#include <math.h>
#include <csl.h>
#define FIRNUMBER 25
#define SIGNAL1F 1000
#define SIGNAL2F 4500
#define SAMPLEF 10000
#define PI 3.1415926
float InputWave();
float FIR();
void Show_wave1(Uint16 x,Uint16 y);
void Show_wave2(Uint16 x,Uint16 y);
float fHn[FIRNUMBER]={ 0.0,0.0,0.001,-0.002,-0.002,0.01,-0.009,
-0.018,0.049,-0.02,0.11,0.28,0.64,0.28,
-0.11,-0.02,0.049,-0.018,-0.009,0.01,
-0.002,-0.002,0.001,0.0,0.0
};
float fXn[FIRNUMBER]={ 0.0 };
float fInput,fOutput;
float fSignal1,fSignal2;
float fStepSignal1,fStepSignal2;
float f2PI;
int i;
float fIn[256],fOut[256];
int nIn,nOut;
Uint16 show_x1=0,show_x2=0,show_y=0;
Uint16 last_x1=0,now_x1=0;
Uint16 last_x2=0,now_x2=0;
void main()
{
nIn=0; nOut=0;
f2PI=2*PI;
fSignal1=0.0;
fSignal2=PI*0.1;
fStepSignal1=2*PI/30;
fStepSignal2=2*PI*1.4;
Sys_Init();
while ( 1 )
{
fInput=InputWave();
fIn[nIn]=fInput;
nIn++; nIn%=256;
fOutput=FIR();
fOut[nOut]=fOutput;
nOut++; /* break point */
if ( nOut>=256 )
{
nOut=0;
}
show_x1=(Uint16)(240+fInput*50);
show_x2=(Uint16)(80 +fOutput*50);
Show_wave1(show_x1,show_y);
Show_wave2(show_x2,show_y);
if(show_y < 480)
show_y=show_y + 1;
else
{
show_y=0;
Show_Init();
}
ddelay(1);
}
}
float InputWave()
{
for ( i=FIRNUMBER-1;i>0;i-- )
fXn[i]=fXn[i-1];
fXn[0]=sin((double)fSignal1)+cos((double)fSignal2)/6.0;
fSignal1+=fStepSignal1;
if ( fSignal1>=f2PI ) fSignal1-=f2PI;
fSignal2+=fStepSignal2;
if ( fSignal2>=f2PI ) fSignal2-=f2PI;
return(fXn[0]);
}
float FIR()
{
float fSum;
fSum=0;
for ( i=0;i<FIRNUMBER;i++ )
{
fSum+=(fXn[i]*fHn[i]);
}
return(fSum);
}
void Show_wave1(Uint16 x,Uint16 y)
{
Uint8 i = 0;
last_x1 = now_x1;
now_x1 = x;
if(last_x1 < now_x1)
{
for(i=last_x1;i<now_x1;i++)
{
DrawPixel(i, y);
}
}
else
{
for(i=last_x1;i>now_x1;i--)
{
DrawPixel(i, y);
}
}
}
void Show_wave2(Uint16 x,Uint16 y)
{
Uint8 i = 0;
last_x2 = now_x2;
now_x2 = x;
if(last_x2 < now_x2)
{
for(i=last_x2;i<now_x2;i++)
{
DrawPixel(i, y);
}
}
else
{
for(i=last_x2;i>now_x2;i--)
{
DrawPixel(i, y);
}
}
}
|