📄 digital filter tester.c
字号:
// filename Tester.C
// Jonathan W. Valvano, 12/16/02
// Digital filter tester
// PortS SCI Port0 serial I/O
// COP reset will be disabled by COPCTL=0;
// Copyright 2003 by Jonathan W. Valvano, valvano@uts.cc.utexas.edu
// You may use, edit, run or distribute this file
// as long as the above copyright notice remains
#include "HC12.h"
#include "SCI12.H"
//******************PUT YOUR FILTER HERE***********************
#define fs 240
unsigned char x[6]; // this MACQ needs twice
unsigned char y[6];
unsigned int n=3; // 3, 4, or 5
unsigned char Filter(unsigned char data){
n++;
if(n==6) n=3;
x[n] = x[n-3] = data; // two copies of new data
y[n] = (25*(x[n]+x[n-2])-18*y[n-2]+16)/32;
y[n-3] = y[n]; // two copies
return y[n];
}
//*************************************************************
const unsigned char SinTab[100]={ // input dX= 200
128,122,115,109,103,97,91,85,
80,74,69,64,60,55,51,47,44,40,38,35,33,31,30,29,28,28,28,29,30,31,
33,35,38,40,44,47,51,55,60,64,69,74,80,85,91,97,103,109,115,122,
128,134,141,147,153,159,165,171,176,182,187,192,196,201,205,209,
212,216,218,221,223,225,226,227,228,
228,228,227,226,225,223,221,218,216,212,209,205,201,196,192,187,
182,176,171,165,159,153,147,141,134
};
//*****************CRLF***************
// Output a CR,LF to go to a new line
void CRLF(void){
SCI_OutChar(CR);
SCI_OutChar(LF);
}
// t=count/fs (seconds)
// v(t)=128+200*sin(2*pi*f*t)
// i=100*(2*pi*f*t)/(2*pi)=(100*f*count)/fs
// i=i%100
// x = SinTab[i]
unsigned short count; // integer time
unsigned short i; // index into SinTab
unsigned short f; // frequency of test wave
unsigned char in,out;
void RunFilter(void){
i = (100*f*(long)count)/fs;
i = i%100; // to to 99
in = SinTab[i];
out = Filter(in); // call your filter
}
void Test(void){
unsigned short MinY,MaxY;
unsigned short Gain; // dY/dX in percent
unsigned short dY; // output amplitude
MaxY = 0;
MinY = 255;
for(count = 0; count < 500; count++){ // initialize filter
RunFilter();
}
for(count = 500; count < 1000; count++){ // run filter
RunFilter();
if(out>MaxY) MaxY=out;
if(out<MinY) MinY=out;
}
dY = MaxY-MinY; // amplitude of filter output
if(f == 0){
Gain = (100*MaxY)/128;
}
else{
Gain = dY/2; // 0 to 100, decimal fixed point 0.01
}
SCI_OutString("f = "); SCI_OutUDec(f);
SCI_OutString(" Hz Gain = ");
SCI_OutUDec(Gain/100); SCI_OutChar('.');
SCI_OutUDec((Gain%100)/10); // tenths digit
SCI_OutUDec(Gain%10); // hundredths digit
CRLF();
}
void main(void){ unsigned short freq;
COPCTL=0x00; // disable COP
SCI_Init(13);
SCI_OutString("Digital filter tester 12/16/02 -JWV"); CRLF();
f = 0; Test();
f = 10; Test();
f = 20; Test();
f = 30; Test();
f = 40; Test();
for(freq = 50; freq <= 70; freq++){
f = freq; Test();
}
f = 80; Test();
f = 90; Test();
f = 100; Test();
}
#include "SCI12A.C"
// SCI12.C uses gadfly synchronization
// SCI12a.C uses interrupt synchronization
extern void _start(); /* entry point in crt12.s */
#pragma abs_address:0xfffe
void (*reset_vectors[])() = { _start };
#pragma end_abs_address
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -