I've got an input signal that while sloping up, approximately bounces off an imaginary line. I'm looking for the equation to that imaginary line. I have a method, but is very brute force and it takes too long. I'm looking for ways to optimize my approach or hopefully learn about a completely different more efficient method. I've written a script in Octave that will do what I want, but it takes 3-10 seconds (with an input signal of 1800 samples) depending on how many iterations I run.
My brute force algorithm in Octave:
x = 0:1:1800; for i = 1:200 p = polyfit(x, input, 1); % p gives the slope and offset output= polyval(p, x); input = clip(input, output); endfor
the clip function clamps the input to the output. Clamps the input signal to the linear approximation.
for i = 1:length(input) if(input(i) > output(i)) input(i) = output(i); end endfor
To better explain what I'm looking for, I've included the rough image below. Of course, the red signal is the input and I'm looking for the equation of the blue line.
Thanks for taking a look.