implementing (HPF)IIR filter

1 post / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi i want to implement the HPF of type IIR the equation as follows.
"y[n] = 0.996*y[n-1] + 0.996*x[n] - 0.996*x[n-1]"

in AVR465 application notes they wrote code for HPF(IIR)like below.

struct        SampleStructure {
                                signed int Fresh, Previous;
                                signed long Filtered,PreviousFiltered,Calibrated;
                              } Sample[3];



Then in ADC ISR like below

#pragma vector=ADC_vect
__interrupt void ADC_ISR(void)
{
  signed int	TempI;
  signed long 	TempL;

  PORTB=(PINB&DIRB)|DUTY;               // For duty cycle monitoring
  
  // Sampled data from ADC:   ADCW      Range=[0000...03FF]
  // Copy of sampled data:    Sample    Range=[0000...03FF]
  // Scaled copy of data:     Temp      Range=[00000000...0003FB01]
  // DC filtered data:        Filtered  Range=[FFFE0280...0001FD80]
  
  // Save copy of fresh sample. Current samples are inverted; invert back.
  // Index variable keeps track of sampled channel, as follows:
  //
  // ISR:          |XXX|  |XXX|  |XXX|  |XXX|  |XXX|  |XXX|  |XXX|  |XXX|  |
  // Index/MUX:    XXX|000000|111111|222222|000000|111111|222222|000000|1111
  // Sampling:     |XXXXXX|000000|111111|222222|000000|111111|222222|000000|
  // Processing:   |XXXXXX|XXXXXX|000000|111111|222222|000000|111111|222222|
  // --------------+------+------+------+------+------+------+------+------+--
  // Conversion:   N     N+1    N+2    N+3    N+4    N+5    N+6    N+7    N+8
  //
  Sample
.Previous=Sample
.Fresh; // x[n+1] <- x[n] if (0==Index) // x[n] <- DATA Sample
.Fresh=ADC; // save voltage sample as is else Sample
.Fresh=(0x03FF-ADC); // save inverted current sample // Apply filter for DC offset removal. Must use long data types for // precision! The transfer function is as follows: // // y[n] = 0.996*y[n-1] + 0.996*x[n] - 0.996*x[n-1] Sample
.PreviousFiltered=Sample
.Filtered; // y[n] <- y[n-1] TempL=255*(long)Sample
.Filtered; TempL=TempL>>8; TempI=Sample
.Fresh-Sample
.Previous; TempL=TempL+255*(long)TempI; Sample
.Filtered=TempL;

.

Is the HPF filter is correct in this coding?
could you please explain the HPF implementation coding

Thanks,
prabu.