If you want to measure frequency, you need a reference frequency you can compare it to.
The usual way to do this is to set up two counter chains, one of which is clocked by your reference frequency Fref, and the other clocked by your unknown frequency Funk (input signal conditioning is an exercise left for the student). You let the two counters run for the same amount of time T, then read their values.
$$Count_{ref} = F_{ref} \cdot T$$
$$Count_{unk} = F_{unk} \cdot T$$
Combine the two equations by dividing them, and solve for Funk:
$$F_{unk} = \frac{Count_{unk}}{Count_{ref}} F_{ref}$$
That's the general concept, but in practice, the process is often simplified by using the reference counter itself to determine the time period T, which makes Countref a known constant, and Fref is also chosen to be a "nice round" number. This turns the multiplication and division into trivial operations, and the frequency can be read more or less directly from Countunk. For example, if Fref/Countref = 1 Hz, then Countunk = Funk directly.
There are many subtleties associated with optimizing the performance of this process that I won't get into here, but there's one trick that's often used when you want to measure relatively low frequencies (such as RPM) with high resolution without requiring a long time T. Instead of making T depend on Fref, making Countref constant, you make T depend on Funk, making Countunk a constant. Also, make Fref as high as you reasonably can. Now you need to do a division operation to get the answer, but you can get it in a fraction of a second with many digits of precision.
For U1 the peak voltage is 4V and so is the RMS as it is DC
For U2 the peak value is 2V and the RMS is \$\dfrac{2}{\sqrt{2}}\$ as its a sine wave.
A useful formula to know when adding two signals which do not share any frequencies in common is:
$$\text{RMS} = \sqrt{U1_{\text{RMS}}^2+U1_{\text{RMS}}^2} $$
Which in this case \$ RMS = \sqrt{4^2+\left( \dfrac{2}{\sqrt{2}}\right)^2} = \sqrt{18}\approx\ 4.243\$
The positive peak is just 4 + 2 = 6 V
The the minimum value is 4 - 2 = 2 V
So the peak to peak is 6 - 2 = 4 V as you would expect since adding a DC offset wont change the peak to peak.
Alternatively you can do this from first principles
$$RMS = \sqrt{\dfrac{1}{T} \cdot \int_0^T \left(U1(t)+U2(t)\right)^2dt}$$
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.