I am facing problem in implementing IIR filter. I have determined the coefficient for the first order Butterworth filter using MATLAB FDATOOL with sampling frequency 2000 Hz and cutoff frequency 100 Hz and used it to filter the AC signal but it isn't working.
To implement this I took the adc sample in every 0.5ms and used following equation to get the filtered output.
y = x * a1 + x(n-1) * a2 + y(n-1) * b1;
Please help me regarding this. Any help will be appreciated.
Try the following:
In FDATool: File - Export - To Workspace. You'll get the SOS matrix and gain G.
Then [[b,a] = sos2tf(SOS,G);
Then output_data=filter(b,a,input_data);
As I stated before I am using MATLAB to get the filter coefficient only and using the same to filter the signal I am getting from AC line, which I am reading from ARM microcontroller, but instead of getting filtered signal, I am getting the signal with decreased amplitude. That's what "isn't working" means.
It seems the equation to be wrong
I dont know it exactly but try the following:
In FDATool: File - Export To Simulink Model. Before pressing the button "Realize Model" check the checkbox "Build model using basic elements".
You will see the diagram for your filter process and will be able to restore the right formula from this.
- - - Updated - - -
It seems the equation to be wrong
I dont know it exactly but try the following:
In FDATool: File - Export To Simulink Model. Before pressing the button "Realize Model" check the checkbox "Build model using basic elements".
You will see the diagram for your filter process and will be able to restore the right formula from this.