kekon
Full Member level 3
- Joined
- Sep 19, 2002
- Messages
- 155
- Helped
- 5
- Reputation
- 10
- Reaction score
- 3
- Trophy points
- 1,298
- Location
- Poland, Białystok
- Activity points
- 1,493
I have a problem with converting analog low pass RC filter into digital one. My goal is to realize digital feedback loop compensation in software. To begin with, i decided to do some training with the simplest RC filter. The low pass filter is built with R = 1000Ω resistor and C = 1µF capacitor. First i wrote the transfer function as G(s) = 1 / (sRC + 1). Then using bilinear transformation i converted it into z transform as G(z) = (b0 + b1 * z^-1) / (1 + a1 * z^-1). b0 = b1 = 0.0155 and a1 = -1. To realize the filter in software i used the IIR Direct Form I
(https://ccrma.stanford.edu/~jos/fp3/Direct_Form_I.html)
The to simulate it i created a function in C# language (to simulate it in my PC before i use it in a microcontroller).
The "Filter" function calculates its output value follows:
(initially the Reg1 and Reg2 equal to 0).
The problem is that the OutputValue always stays at constant value (for example it is 31.744 for InputValue = 2048) . I have no idea what i'm doing wrong. With this analog low pass filter the output value achievies the input value after some time when constant voltage is applied to it. In case with my digital filter it seems as it works like a voltage divider,not a filter...
(https://ccrma.stanford.edu/~jos/fp3/Direct_Form_I.html)
The to simulate it i created a function in C# language (to simulate it in my PC before i use it in a microcontroller).
The "Filter" function calculates its output value follows:
Code C# - [expand] 1 2 3 4 5 6 7 8 9 10 double InputValue = 2048; double OutputValue; for (int i = 0; i < 20; i++) { OutputValue = InputValue * b0 + Reg1 * b1 + a1 * Reg2; Reg1 = InputValue; Reg2 = OutputValue; Console.WriteLine(OutputValue.ToString()); }
(initially the Reg1 and Reg2 equal to 0).
The problem is that the OutputValue always stays at constant value (for example it is 31.744 for InputValue = 2048) . I have no idea what i'm doing wrong. With this analog low pass filter the output value achievies the input value after some time when constant voltage is applied to it. In case with my digital filter it seems as it works like a voltage divider,not a filter...