# Lonberg-Marquardt algorithm for exponential function with FPGA

#### pooya_b

Joined Feb 25, 2021
59
Hi I want to write a program in Spartan 6 that using the Lonberg-Marquardt algorithm I can fit the following pan using the input data from a photodiode and get tc.
Y = a + (p * exp(-t / tc))

I wanted to know if anyone wrote this program and could give it to me or help me write the program.

#### DrBit

Joined Jan 26, 2021
6
What throughput do you want?
I.e. number of clocks per result?

#### pooya_b

Joined Feb 25, 2021
59
What throughput do you want?
I.e. number of clocks per result?
I want this fitting to be calculated every minute.
I have an analog-to-digital converter at a speed of 3 million samples per second, and the data I receive is about 700 microseconds, which means 2,000 samples, and I want to fit on these 2,000 samples.

#### pooya_b

Joined Feb 25, 2021
59

#### Papabravo

Joined Feb 24, 2006
18,099
Thank you very much, yes, you are right, I mistyped. Can you help me translate this code into VHDL?
Sadly no. I learned Matlab over 20 yeas ago, and I had a student version while I was in school, but the cost of the full package was not something I was willing to pay at the time. Then there were free alternatives like Scilab and Octave, so I never had the motivation to maintain my skills. I have used the two methods, gradient descent and Gauss-Newton, by themselves, but never in combination. The real show stopper is that I'm only vaguely familiar with VHDL, and not much better with Verilog.

Since the methods involve matrix manipulations I'm going to guess that you will benefit by considering multiple parallel MAC (Multiply ACumulate) units, such as would be available in a DSP (Digital Signal Processor).

Last edited:

#### pooya_b

Joined Feb 25, 2021
59
Sadly no. I learned Matlab over 20 yeas ago, and I had a student version while I was in school, but the cost of the full package was not something I was willing to pay at the time. Then there were free alternatives like Scilab and Octave, so I nevr had the motivation to maintain my skills. I have used the two methods, gradient descent and Gauss-Newton, by themselves, but never in combination. The real show stopper is that I'm only vaguely familiar with VHDL, and not much better with Verilog.

Since the methods involve matrix manipulations I'm going to guess that you will benefit by considering multiple parallel MAC (Multiply ACumulate) units, such as would be available in a DSP (Digital Signal Processor).
Thank you very much

#### DrBit

Joined Jan 26, 2021
6
I want this fitting to be calculated every minute.
I have an analog-to-digital converter at a speed of 3 million samples per second, and the data I receive is about 700 microseconds, which means 2,000 samples, and I want to fit on these 2,000 samples.
In this case writing VHDL is not recommended. I should write it in C++ and run it on a soft processor.
You could try Instant SoC. That compiles the C++ to VHDL and a RISC-V processor. Very easy to use.