Linear equation matrix solver

Post any examples or modules that you want to share here
KG_is_back
Posts: 1196
Joined: Tue Oct 22, 2013 5:43 pm
Location: Slovakia

Linear equation matrix solver

Post by KG_is_back »

The name says it all. It solves linear matrices via Gaussian elimination. You input the number of equations N and the float array in form of [a,b,c,..,z,constant,a,b,...,z,constant,...] and output is solution for [a,b,...,z]. The Array must be of size N*(N+1) or will be resized to that size.
Known bugs:
-Precision is a little problem... sometimes x/x-y/y is not zero, So I had to round small numbers to zero in the algorithm.
-Only non-singular matrices can be solved. This is not really a bug, but a mathematic fact...

Please try it out and let me know what you think ;)
Attachments
linest2.fsm
(3.51 KiB) Downloaded 1238 times
Last edited by KG_is_back on Sun Feb 23, 2014 1:18 am, edited 1 time in total.
tester
Posts: 1786
Joined: Wed Jan 18, 2012 10:52 pm
Location: Poland, internet

Re: Linear equation matrix solver

Post by tester »

Ehm, I have no idea what for I could use it (at least right now), but I think you are doing a great job by assembling these "little things". :mrgreen: When the proper time comes - they get needed.
Need to take a break? I have something right for you.
Feel free to donate. Thank you for your contribution.
KG_is_back
Posts: 1196
Joined: Tue Oct 22, 2013 5:43 pm
Location: Slovakia

Re: Linear equation matrix solver

Post by KG_is_back »

I personally was doing it for implementing FIR to IIR converter implementing least squares method.
You provide it with test tone before and after the filter you wanna copy (or dirac and the IR), the algorithm handles y(0) as function of x(0), x(1),... and y(1),y(2),... and least squares method approximates the A and B coefficients. That requires solving quite big matrices, so there was no way around.
Unfortunately so far I've made it to work only for first order filter... for some reason it fails solving the matrix of higher order filters including biquad.
tester
Posts: 1786
Joined: Wed Jan 18, 2012 10:52 pm
Location: Poland, internet

Re: Linear equation matrix solver

Post by tester »

Is the issue related to accuracy?
If it's a matter of accuracy, then transforming it to ruby should help.
Need to take a break? I have something right for you.
Feel free to donate. Thank you for your contribution.
KG_is_back
Posts: 1196
Joined: Tue Oct 22, 2013 5:43 pm
Location: Slovakia

Re: Linear equation matrix solver

Post by KG_is_back »

tester wrote:Is the issue related to accuracy?
If it's a matter of accuracy, then transforming it to ruby should help.


I do not know... But Ruby double precision would improve the precision a lot - precision in digital formats is general problem of Gaussian elimination. It is often followed by different method to improve the precision.
KG_is_back
Posts: 1196
Joined: Tue Oct 22, 2013 5:43 pm
Location: Slovakia

Re: Linear equation matrix solver

Post by KG_is_back »

Found the bug... Now it's working properly, I updated the schematic in first post... Still, the precision is a little problem. If someone can make it in ruby it would be great - Gaussian elimination is not that hard to implement
User avatar
martinvicanek
Posts: 1334
Joined: Sat Jun 22, 2013 8:28 pm

Re: Linear equation matrix solver

Post by martinvicanek »

Neat! The bugfixed schematic now solves a test case that the first version didn't. Unfortunately I can't help you with Ruby but for those who are familiar with the language it should be straightforward to port some available code (e.g. Gauss-Jordan elimination, chapter 2.1 p.36ff of Numerical Recipes in C).
User avatar
martinvicanek
Posts: 1334
Joined: Sat Jun 22, 2013 8:28 pm

Re: Linear equation matrix solver

Post by martinvicanek »

KG_is_back wrote:FIR to IIR converter

:o I thought FIR filter design was harder than IIR filter design? Or are you after reverb modelling?
KG_is_back
Posts: 1196
Joined: Tue Oct 22, 2013 5:43 pm
Location: Slovakia

Re: Linear equation matrix solver

Post by KG_is_back »

martinvicanek wrote:
KG_is_back wrote:FIR to IIR converter

:o I thought FIR filter design was harder than IIR filter design? Or are you after reverb modelling?


Possibly... I what to create a plugin that would be able to approximate short FIR into IIR which is much more cpu friendly. (cab modeling etc.).

General equation of N-th order filter is: y(0)=x(0)*b0 + x(1)*b1 + ... x(n)*bn + (-a1)*y(1) + ... That is a linear equation with multiple variables (x,y - and their delayed versions). When you have a test tone (x) and tone passed through (y) least squares method can approximate the coefficients, so the effect on output match with original.
The equation can also be expand larger by c*htan(x) or d*(x^2) and other functions and now the system can approximate nonlinear devices too.

I already have a working prototype, but it is not ready to make public yet
User avatar
MegaHurtz
Posts: 105
Joined: Mon Aug 11, 2008 6:29 pm
Location: Eindhoven/Nederland

Re: Linear equation matrix solver

Post by MegaHurtz »

Havn't really heard of it before, but after a quick browse it seems to be a liniar transformation.
Which offcourse is not what it should be, right. So are you creating the non liniar version?

Edit: ^^ Yea :)
Begging for a convolution within a convolution.. Strange little paradox there, the way I see it after 5 mins is that the number of matreces also bound by a number of taps you use for it. Inproper defenition if infinite? But hey if its long its long I guess.
192k @ 8ms
Post Reply