fixes filter on MPT-transition. Add a high quality filter wir anti-aliasing
This commit is contained in:
@@ -1,17 +1,16 @@
|
||||
package plot
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"image/color"
|
||||
"image/png"
|
||||
"math"
|
||||
"math/cmplx"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"image/png"
|
||||
|
||||
"image/color"
|
||||
|
||||
"github.com/mjibson/go-dsp/fft"
|
||||
"gonum.org/v1/plot"
|
||||
"gonum.org/v1/plot/font"
|
||||
@@ -22,7 +21,8 @@ import (
|
||||
)
|
||||
|
||||
// PlotIR plots the frequency response (magnitude in dB vs. frequency in Hz) of the IR to a PNG file
|
||||
func PlotIR(ir []float64, sampleRate int, irFileName string) error {
|
||||
// logoData is the embedded logo image data (can be nil if not available)
|
||||
func PlotIR(ir []float64, sampleRate int, irFileName string, logoData []byte) error {
|
||||
if len(ir) == 0 {
|
||||
return nil
|
||||
}
|
||||
@@ -62,9 +62,8 @@ func PlotIR(ir []float64, sampleRate int, irFileName string) error {
|
||||
}
|
||||
}
|
||||
fmt.Printf("[PlotIR] minDb in plotted range: %.2f dB at %.2f Hz\n", minDb, minDbFreq)
|
||||
irBaseName := filepath.Base(irFileName)
|
||||
p := plot.New()
|
||||
p.Title.Text = fmt.Sprintf("IR Frequency Response: %s", irBaseName)
|
||||
p.Title.Text = "IR Frequency Response"
|
||||
p.X.Label.Text = "Frequency (Hz)"
|
||||
p.Y.Label.Text = "Magnitude (dB)"
|
||||
p.X.Scale = plot.LogScale{}
|
||||
@@ -112,7 +111,7 @@ func PlotIR(ir []float64, sampleRate int, irFileName string) error {
|
||||
|
||||
// --- Time-aligned waveform plot ---
|
||||
p2 := plot.New()
|
||||
p2.Title.Text = fmt.Sprintf("IR Waveform: %s", irBaseName)
|
||||
p2.Title.Text = "IR Waveform"
|
||||
p2.X.Label.Text = "Time (ms)"
|
||||
p2.Y.Label.Text = "Amplitude"
|
||||
// Prepare waveform data (only first 10ms)
|
||||
@@ -142,16 +141,14 @@ func PlotIR(ir []float64, sampleRate int, irFileName string) error {
|
||||
dc := draw.New(img)
|
||||
|
||||
// Draw logo at the top left, headline to the right, IR filename below
|
||||
logoPath := "assets/logo.png"
|
||||
// Logo is embedded in the binary
|
||||
logoW := 2.4 * vg.Inch // doubled size
|
||||
logoH := 0.68 * vg.Inch // doubled size
|
||||
logoX := 0.3 * vg.Inch
|
||||
logoY := height + 0.2*vg.Inch // move logo down by an additional ~10px
|
||||
logoDrawn := false
|
||||
f, err := os.Open(logoPath)
|
||||
if err == nil {
|
||||
defer f.Close()
|
||||
logoImg, err := png.Decode(f)
|
||||
if len(logoData) > 0 {
|
||||
logoImg, err := png.Decode(bytes.NewReader(logoData))
|
||||
if err == nil {
|
||||
rect := vg.Rectangle{
|
||||
Min: vg.Point{X: logoX, Y: logoY},
|
||||
@@ -202,11 +199,11 @@ func PlotIR(ir []float64, sampleRate int, irFileName string) error {
|
||||
irNameWithoutExt := strings.TrimSuffix(irBase, filepath.Ext(irBase))
|
||||
plotFileName := filepath.Join(irDir, irNameWithoutExt+".png")
|
||||
|
||||
f, err = os.Create(plotFileName)
|
||||
plotFile, err := os.Create(plotFileName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer f.Close()
|
||||
_, err = vgimg.PngCanvas{Canvas: img}.WriteTo(f)
|
||||
defer plotFile.Close()
|
||||
_, err = vgimg.PngCanvas{Canvas: img}.WriteTo(plotFile)
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user