# Calculating amplitude difference between each two samples

If there’s one place for me to find out whether this is possible, this is it. So I’ll explain it as best as I can.

Audacity is my go-to program both for recording audio and processing.
I’ve seen the nyquist prompt and have checked out the list of commands, but unable to find (or understand) the one that would work in my case.

Basically, to simplify: Let’s say that the amplitude of an audio can go from 1 to 10.
I record at 44100 sample rate, a one second audio clip.

I would want to find a way to give a command to my audacity, that would:
Look at amplitude of sample #1, look at amplitude of sample #2 [Example: 3, 4]
Subtract the first sample’s amplitude from the second one (4-3)
return the value 1
and build a waveform out of it. In this case: It’s first sample would have value 1
Second sample of it would be the difference between (Original Sample #3 - Original Sample#2)

I did notice a diff(a,b) command but, I have no idea how I could use that. Not sure what’s a, not sure what’s b, not sure how to give it the info of what sample window size I’d be giving, etc.

I’m not a Nyquist expert, so outside of Nyquist, I suppose you could select the first Track, Edit > Invert, then select both tracks and Transport > Mix > …

Have I got this right - in the image below, I have numbered the samples for illustration purposes.

You want to create a waveform in which:

The 1st sample of the new waveform = value of sample “2” - value of sample “1”.
The 2nd sample of the new waveform = value of sample “3” - value of sample “2”.
The 3rd sample of the new waveform = value of sample “4” - value of sample “3”.
… and so on … Hmm…
Track 1 is Generate Chirp
Track 2 is Track 1 Inverted
Track 3 is Track 1 shifted to the right by one sample
Track 4 is Tracks 2 & 3 Mixed to a new track. Zoomed in: which can be done in the Nyquist Prompt with this code:

``````(let ((one (/ *sound-srate*))
shifted)
(setf shifted (sim (s-rest one)
(at-abs one (cue *track*))))
(diff shifted *track*))
``````

(sorry for the double account - the password reset system doesn’t seem to work!)

You definitely have gotten this right

This solution is so elegant, so simple, simply genius, thank you a lot to both of you…

Even more simple:

``````(diff (at-abs (/ *sound-srate*) (cue *track*))
*track*)
``````