---
# System prepended metadata

title: IIR Filter experimental report

---

# IIR Filter experimental report

## Screenshot:
![](https://i.imgur.com/qiEQCfG.png)
![](https://i.imgur.com/wdRVJeB.png)
![](https://i.imgur.com/XwX4efw.png)
![](https://i.imgur.com/Nk0nWWw.png)


## Code: 
```typescript
import { notchFilter, bandpassFilter } from '@neurosity/pipes'
import { from } from 'rxjs'
import { useChart } from '@/common/charts'

const recordingDataTime = [] as number[]
const recordingData = {} as { [channel: number]: number[] }

const deviceSamplingRate = 1000
const amplitude = 10
const numChannels = 2
for (let i = 0; i < numChannels; i += 1) {
  recordingData[i] = []
}
// generate 60Hz sine wave
const generateSineWave = () => {
  const duration = 1 // sec
  const numSamples = (deviceSamplingRate * duration) / numChannels
  const sineWaveFreq = 60 // sine wave Hz
  const signal = []
  for (let i = 0; i < duration; i += duration / numSamples) {
    signal.push({
      timestamp: i,
      data: [
        amplitude * Math.sin(sineWaveFreq * 2 * Math.PI * i),
        amplitude * Math.sin(sineWaveFreq * 2 * Math.PI * i),
      ],
    })
  }
  return signal
}
const signal$ = from(generateSineWave())

const options = {
  title: {
    text: '',
  },
  xAxis: {
    type: 'category',
    data: [] as number[],
  },
  yAxis: {
    type: 'value',
    min: -amplitude,
    max: amplitude,
  },
  series: {
    data: [] as number[],
    type: 'line',
  },
}

onMounted(async () => {
  const myChart = useChart(chartRef, options)
  const samples$ = signal$.pipe(
    bandpassFilter({
        nbChannels: numChannels,
        cutoffFrequencies: [100, 200],
        samplingRate: deviceSamplingRate / numChannels,
        order: 2,
    }),
    notchFilter({
        nbChannels: numChannels,
        cutoffFrequency: 60,
        samplingRate: deviceSamplingRate / numChannels,
        order: 2,
    }),
  )
  samples$.subscribe(chunk => {
    recordingDataTime.push(chunk.timestamp)
    for (let i = 0; i < numChannels; i += 1) {
      recordingData[i].push(chunk.data[i])
    }
  })
  myChart.setOption({
    xAxis: {
      data: recordingDataTime,
    },
    series: {
      data: recordingData[0], // only plot channel 0 data for convenience
    },
  })
})
```

