feat: add system gain dB control to filter coefficients

This commit is contained in:
ws50529
2026-05-08 11:37:48 +08:00
parent 5568651cc3
commit 48eeb11d26
3 changed files with 34 additions and 15 deletions
+12 -6
View File
@@ -12,6 +12,7 @@ createApp({
"Bandpass (帶通)", "Notch (陷波器)", "1P1Z (一極一零)",
"2P2Z (二極二零)", "PID 控制器", "SOGI-Alpha (帶通)", "SOGI-Beta (低通)"
],
systemGainDB: 0.0,
params: {
fc: 1000.0, order: 1,
bp_f_low: 500.0, bp_f_high: 2000.0, bp_order: 1,
@@ -38,6 +39,9 @@ createApp({
}
},
computed: {
linearSystemGain() {
return Math.pow(10, this.systemGainDB / 20.0);
},
maxLogB() {
if (this.sense_b === '1%') return Math.log10(1.01);
if (this.sense_b === '2x') return Math.log10(2.0);
@@ -50,7 +54,7 @@ createApp({
},
fixedPointCoeffs() {
const scale = Math.pow(2, this.shiftBits);
const b_raw = this.parseCoeffs(this.b_str);
const b_raw = this.parseCoeffs(this.b_str).map(x => x * this.linearSystemGain);
const a_raw = this.parseCoeffs(this.a_str);
const b = b_raw.map((x, i) => ({ label: `b${i}`, val: Math.round(x * scale) }));
@@ -59,8 +63,8 @@ createApp({
return { b, a };
},
floatingCoeffs() {
const b = this.parseCoeffs(this.b_str).map((x, i) => ({ label: `b${i}`, val: x }));
const a = this.parseCoeffs(this.a_str).map((x, i) => ({ label: `a${i}`, val: x }));
const b = this.parseCoeffs(this.b_str).map((x, i) => ({ label: `b${i}`, val: parseFloat((x * this.linearSystemGain).toPrecision(6)) }));
const a = this.parseCoeffs(this.a_str).map((x, i) => ({ label: `a${i}`, val: parseFloat(x.toPrecision(6)) }));
return { b, a };
}
},
@@ -185,7 +189,7 @@ createApp({
this.loadingBode = true;
this.globalError = null;
try {
let b = this.parseCoeffs(this.b_str);
let b = this.parseCoeffs(this.b_str).map(val => val * this.linearSystemGain);
let a = this.parseCoeffs(this.a_str);
if (b.length === 0) b = [1.0];
if (a.length === 0) a = [1.0];
@@ -334,8 +338,9 @@ createApp({
this.loadingFilter = true;
this.globalError = null;
const formData = new FormData();
const final_b_str = this.parseCoeffs(this.b_str).map(val => val * this.linearSystemGain).join(', ');
formData.append('file', this.csvFile);
formData.append('b', this.b_str);
formData.append('b', final_b_str);
formData.append('a', this.a_str);
formData.append('col_idx', this.selectedColumn);
try {
@@ -373,8 +378,9 @@ createApp({
async downloadCsv() {
if (!this.csvFile) return;
const formData = new FormData();
const final_b_str = this.parseCoeffs(this.b_str).map(val => val * this.linearSystemGain).join(', ');
formData.append('file', this.csvFile);
formData.append('b', this.b_str);
formData.append('b', final_b_str);
formData.append('a', this.a_str);
formData.append('col_idx', this.selectedColumn);
try {