Page 1 of 3
Schmitt trigger... Possible?
Posted: Fri Nov 04, 2016 8:31 pm
by Flavioweb
I'm using Audacity 2.1.2 on OpenSuSe.
I want to know if there is a way to "emulate" a Schmitt trigger...
Someone can point me in the right direction?
Re: Schmitt trigger... Possible?
Posted: Fri Nov 04, 2016 8:52 pm
by steve
Audacity does not do real-time processing.
If you're not wanting this for real-time use, then please describe in detail what you are wanting to do.
Re: Schmitt trigger... Possible?
Posted: Fri Nov 04, 2016 9:01 pm
by Flavioweb
I don't want to do it in real time.
See the attachments...
I need to have bottom wave look like the top wave...
I thought to Schmitt trigger... but also other solutions are welcome.
Re: Schmitt trigger... Possible?
Posted: Fri Nov 04, 2016 9:17 pm
by cyrano
I think a gate could act as a Schmitt trigger. I'm not sure all gates are a real ST, but at least, some are.
But I'm wondering too what would be the use, as you can't get the result out of Audacity. And as Steve wrote, Audacity doesn't do real-time triggering, so the use would be even more limited.
For those not intimate with a Schmitt trigger, it's a level switch with hysteresis. And hysteresis means it'll switch from off to on at level X, but won't immediately switch off if the level dips below X again. Like most thermostats and most other automated switches operate in real life.
Re: Schmitt trigger... Possible?
Posted: Fri Nov 04, 2016 9:18 pm
by steve
That looks more like a comparator than a Schmitt trigger (
https://en.wikipedia.org/wiki/Schmitt_trigger).
I also notice that the upper waveform has a slower rise time than fall time. Is that important to the design?
It would help if you described in detail what you are wanting to do. What's the job? What's the context?
Re: Schmitt trigger... Possible?
Posted: Fri Nov 04, 2016 9:19 pm
by cyrano
From your drawing, a limiter would be closer.
So you basically want to create a sine with flat tops?
Wouldn't a programmable signal generator program be easier?
Re: Schmitt trigger... Possible?
Posted: Fri Nov 04, 2016 9:20 pm
by cyrano
And it would even be easier in hardware. Like two diodes...
Re: Schmitt trigger... Possible?
Posted: Fri Nov 04, 2016 9:31 pm
by Flavioweb
These signals come from "computer tapes".
They are analog, but I have to convert them to digital.
Square waves with, just to say, +0,5/-0,5 peaks where "sin" waves have "peaks".
More precisely, from +0.2 up i can set the "+0,5" peak, and from -0.2 down i can set the "-0,5" peak.
the "+/-0,2" value it's absolutely arbitrary...
This should make "square" a "sinus" or whatever wave...
Re: Schmitt trigger... Possible?
Posted: Fri Nov 04, 2016 9:40 pm
by steve
Out of interest I wrote a little demo. This also uses the Nyquist Prompt effect
http://manual.audacityteam.org/man/nyquist_prompt.html
Firstly a "comparator".
For this we will first generate 1 second 20 Hz sine tone, amplitude 0.8:

- sine.png (14.4 KiB) Viewed 1245 times
The next bit of code reads 44100 samples from the selected track (our sine tone) and compares each sample to a value of 0.0. If the sample value is greater than 0, the output is +0.8, otherwise it is -0.8.
Code: Select all
(setf ar (snd-fetch-array *track* 44100 44100))
(dotimes (i 44100 (snd-from-array 0 44100 ar))
(let ((input (aref ar i)))
(if (> input 0)
(setf (aref ar i) 0.8)
(setf (aref ar i) -0.8))))
The outout:

- firsttrack001.png (8.44 KiB) Viewed 1245 times
But what if we have a noisy signal?
Code: Select all
(abs-env
(sum (mult (hzosc 20) 0.5)(mult (noise) 0.1)))

- firsttrack002.png (13.24 KiB) Viewed 1245 times
Our comparator "jitters" as the waveform crosses 0.0 multiple times due to the noise:

- firsttrack003.png (8.55 KiB) Viewed 1245 times
and a zoomed in view:

- Zoomed in closer
- firsttrack004.png (8.48 KiB) Viewed 1245 times
So here we need a Schmitt trigger. In this case the output goes high when the input exceeds +0.2, and stays high until the input drops below -0.2.
Code: Select all
(setf ar (snd-fetch-array *track* 44100 44100))
(setf output 0)
(dotimes (i 44100 (snd-from-array 0 44100 ar))
(let ((input (aref ar i)))
(cond
((> input 0.2) (setf output 0.8))
((< input -0.2) (setf output -0.8)))
(setf (aref ar i) output)))
So now the output from our "dirty" sine wave looks like this:

- firsttrack005.png (8.38 KiB) Viewed 1245 times
Re: Schmitt trigger... Possible?
Posted: Fri Nov 04, 2016 9:46 pm
by steve
Flavioweb wrote:These signals come from "computer tapes".
They are analog, but I have to convert them to digital.
Square waves with, just to say, +0,5/-0,5 peaks where "sin" waves have "peaks".
More precisely, from +0.2 up i can set the "+0,5" peak, and from -0.2 down i can set the "-0,5" peak.
the "+/-0,2" value it's absolutely arbitrary...
This should make "square" a "sinus" or whatever wave...
If the input is not too "noisy", then a simple and fairly fast way is:
This will work on reasonably long tracks (should be OK with an hour long track) and will work with mono or stereo.
If you need the hysteresis of a Schmitt trigger, then something like my previous code could work as a starting point, but that code in it's current form is only suitable for fairly short mono tracks.