# The Yamaha DX7 Envelope Generator, part four.

This is part four of a qualitative analysis of the DX7 Envelope Generator. The series begins here.

Part three is here

## Rising segments.

As we've seen, the rising segment of an envelope in a DX7 is not a pure exponential.

A really useful (and hackish) experiment is to divide the signal by a linear function, to poke with linear components. The envelope divided by (x - 86250)

What emerge is that, once divided by x, the segment is markedly linear. This is really good, as it seems to suggest that the segment is quadratic.

Let's go back at `raw2plot.c` and add a new column, that calculates the square root of the envelope. Patch is here. Square root of the envelope.

The linear behaviour of the square root is even more evident here.

Let's calculate the curve by finding the start and end samples of the segment. The maximum (1.0) is reached at sample 87427, while the signal appears to start (hard to tell given noise) at around 86275.

We have then that:

``s = (1.0 - 0.0) / (87427 - 86275) = .000868``

and

``env(t) = V * s^2 * x^2``

Let's try this against the signal:

``````\$ gnuplot
gnuplot>  plot [86000:88000][-.1:1] 'envtest0.plt' \
using 1:2 with lines, \
.8*.000868*.000868 *(x - 86275)*(x-86275)`````` Fitting of rising segment with a parabola.

It is a good fitting, apart from noise and some offset at the start.

As our goal is not a precise reproduction of the wave generated by the DX7 – this will likely require an analysis at the hardware level – but a characterisation of the envelope, this fits well enough.

## Putting it all together

We now have enough data to reconstruct the envelope of `ENV TEST#0`.

`envtest0.c` is a simple program that simulates the DX70 envelope at rate 50 using the equations we just found and recreates the original recording. Its output can be printed by gnuplot.  Comparison of `envtest0.c` output ("syntehtic") versus envelope of the recorded sound.

As you can see, the result is incredibly close. There's a lag of about 1000 samples (or 22usec) between on the start of segment three, which is probably due to an incorrect calculation of level 50.

## Conclusion

We finally found out more about the DX7 envelope, and we were able to recreate an envelope based on our measuring.

This is not all is needed to simulate completely the Envelope Generator of a DX7. Information lacking is:

1. How the parameters s and d change when rate changes.
2. What's the output value for all the levels.