Hi @Moto
@matt I don’t want to derail this thread and so this probably deserves its own thread, but could you detail some of your exploits in filter design with gpt4?
Prompt for GPT:
Can you design a biquad filter class in c# with a notch at a certain freq? Assume a ctor that takes sample freq and notch freq, and a Filter method that accepts an array of doubles and returns a double array. The Filter method should maintain state between subsequent calls. That is, I’ll be calling Filter with chunked data.
GPT says:
using System;
public class BiquadNotchFilter
{
private readonly double a0, a1, a2, b0, b1, b2;
private double z1, z2;
public BiquadNotchFilter(double sampleFreq, double notchFreq, double Q = 1.0)
{
double omega = 2 * Math.PI * notchFreq / sampleFreq;
double alpha = Math.Sin(omega) / (2 * Q);
b0 = 1;
b1 = -2 * Math.Cos(omega);
b2 = 1;
a0 = 1 + alpha;
a1 = -2 * Math.Cos(omega);
a2 = 1 - alpha;
// Normalize the coefficients
b0 /= a0;
b1 /= a0;
b2 /= a0;
a1 /= a0;
a2 /= a0;
// Initialize state variables
z1 = z2 = 0;
}
public double[] Filter(double[] input)
{
double[] output = new double[input.Length];
for (int i = 0; i < input.Length; i++)
{
double inSample = input[i];
double outSample = b0 * inSample + z1;
z1 = b1 * inSample + z2 - a1 * outSample;
z2 = b2 * inSample - a2 * outSample;
output[i] = outSample;
}
return output;
}
}
Note the z1 and z2, which means it maintaining state. I didnt’ test the filter, but it looks convincing.
Then I asked:
Can you run this filter in python and tell me the gain at 100 Hz?
GPT says (after some thinking):
The gain at 100 Hz for the biquad notch filter is approximately -0.043 dB. This indicates that the filter has minimal attenuation at this frequency, which is expected since the notch filter is designed to attenuate frequencies around the notch frequency (1000 Hz) rather than 100 Hz.
And what is the gain at 990 Hz?
The gain at 990 Hz for the biquad notch filter is approximately -33.48 dB. This indicates significant attenuation at this frequency, which is close to the notch frequency of 1000 Hz, demonstrating the effectiveness of the filter in attenuating frequencies near the notch frequency.
Again, I didn’t check the math. But there’s enough smarts happening that it should be easy to paste in a filter class generated by GPT and have compiled and run. Pretty cool! But, it will be some time before it can replace dedicated filter software.