Electronic – Detect the maximum of signal

signalxilinx system generator

enter image description here

I am trying to create a bloc with Xilinx system generator to detect the maximum of a sine wave. I used the strategy that:

$$ x(n-1)-x(n-2)>0$$

and

$$ x(n)-x(n-1)<0 $$

but I didn't find the maximum. The result is wrong, as shown in the image below:

What am I doing wrong? How can I detect the signal maximum?

enter image description here

Best Answer

Assuming I guessed right about which edges in your graph are rising edges and which are falling edges, it looks like your solution has found the maximum, but it's output is delayed by two cycles from when the maximum occurred. You should expect this delay because the new value of y (your output variable) can only be determined once x(n-2), x(n-1), and x(n) have all been produced. Therefore, y only responds to the maximum in cycle n+1.

You could get the response in cycle n if you used only combinatorial logic to compare x(n) with the prior values, and didn't wait for a flip-flop to capture the result.

P.S.: You'll also have a problem if your sampling happens to produce two exactly equal samples (to the resolution of your ADC) straddling the maximum point.

Related Topic