Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/soypat/biquad
Lightweight Bilinear Transform (BLT) filter implementations for DSP in sensor fusion and audio.
https://github.com/soypat/biquad
bandpass-filter bilinear-transformation butterworth-filter chebyshev-filter digital-signal-processing dsp filter filtering filtering-algorithm highpass-filter lowpass-filter second-order-filter sensor-fusion
Last synced: about 1 month ago
JSON representation
Lightweight Bilinear Transform (BLT) filter implementations for DSP in sensor fusion and audio.
- Host: GitHub
- URL: https://github.com/soypat/biquad
- Owner: soypat
- License: bsd-2-clause
- Created: 2021-08-10T19:14:07.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-06-02T04:48:56.000Z (over 2 years ago)
- Last Synced: 2024-10-12T09:11:32.808Z (2 months ago)
- Topics: bandpass-filter, bilinear-transformation, butterworth-filter, chebyshev-filter, digital-signal-processing, dsp, filter, filtering, filtering-algorithm, highpass-filter, lowpass-filter, second-order-filter, sensor-fusion
- Language: Go
- Homepage:
- Size: 132 KB
- Stars: 0
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# biquad
Lightweight Bilinear Transform (BLT) filter implementations for DSP in sensor fusion and audio.This is mostly a toy library. For production ready filtering see [pctl](https://github.com/brandondube/pctl) by brandondube.
Below is an example of usage and the resulting plot:
```go
const (
pi = math.Pi
// working frequency. The frequency that matters (we wish to keep it)
f0 = 2.
fnoise = 4.
fs = 100. // Sampling frequency.
N = 100 // amount of sample points
ts = 1 / fs // sampling period
)
// We generate waveform data composed of a "working" frequency and a "noise" frequency
data := make([]float64, N)
for i := 0; i < N; i++ {
t := float64(i) * ts
data[i] = math.Sin(2*pi*f0*t) + math.Sin(2*pi*fnoise*t)
}
signal := biquad.MakeSignal(fs, data)
lp, err := biquad.NewLowPass(fs, f0, 1)
if err != nil {
panic(err)
}filtered, err := lp.Filter(signal)
if err != nil {
panic(err)
}
p := plot.New()
ls, _ := plotter.NewLine(signal)
lf, _ := plotter.NewLine(filtered)
lf.Dashes = []font.Length{0.1 * font.Centimeter, 0.1 * font.Centimeter}
p.Add(ls, lf)
p.Legend.Add("original signal", ls)
p.Legend.Add("filtered signal", lf)
err = p.Save(30*font.Centimeter, 15*font.Centimeter, "out.png")
if err != nil {
panic(err)
}
```
![Low Pass example usage](./_assets/example_lowpass.png)
> Low pass filter applied to a composite signal to effectively cancel out the higher frequency noise.## Bode plots
There is some semblance of a Bode plotter for discrete time (z transfer) functions under `bode.go`.This is the result of plotting the Bode of a notch filter:
![Notch filter Bode plot](./_assets/notch_f0=4.png)
> Notch filter Bode Plot.This API is not yet exposed because I'm still unsure of what exactly is being plotted (units). If you're interested please help out! I'll be looking at issues.
Below is the code for the Bode Plot:
```go
const (
fs = 100.
ts = 1 / fs
)
lp, err := NewNotch(fs, 4, 1)
if err != nil {
t.Fatal(err)
}
H := lp.getH()
plotBode("notch_f0=4.png", ts, H)
```