Schmitt trigger... Possible?

Effects, Recipes, Interfacing with other software, etc.
Forum rules
If you require help using Audacity, please post on the forum board relevant to your operating system:
Windows
Mac OS X
GNU/Linux and Unix-like
Flavioweb
Posts: 22
Joined: Fri Nov 04, 2016 8:23 pm
Operating System: Linux Debian

Schmitt trigger... Possible?

Post by Flavioweb » Fri Nov 04, 2016 8:31 pm

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?

steve
Site Admin
Posts: 80679
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: Schmitt trigger... Possible?

Post by steve » Fri Nov 04, 2016 8:52 pm

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.
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

Flavioweb
Posts: 22
Joined: Fri Nov 04, 2016 8:23 pm
Operating System: Linux Debian

Re: Schmitt trigger... Possible?

Post by Flavioweb » Fri Nov 04, 2016 9:01 pm

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.
Attachments
Waves-01.jpg
Waves-01.jpg (41.59 KiB) Viewed 1246 times

cyrano
Posts: 2629
Joined: Fri Apr 17, 2015 11:54 pm
Operating System: macOS 10.13 High Sierra

Re: Schmitt trigger... Possible?

Post by cyrano » Fri Nov 04, 2016 9:17 pm

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.

steve
Site Admin
Posts: 80679
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: Schmitt trigger... Possible?

Post by steve » Fri Nov 04, 2016 9:18 pm

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?
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

cyrano
Posts: 2629
Joined: Fri Apr 17, 2015 11:54 pm
Operating System: macOS 10.13 High Sierra

Re: Schmitt trigger... Possible?

Post by cyrano » Fri Nov 04, 2016 9:19 pm

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?

cyrano
Posts: 2629
Joined: Fri Apr 17, 2015 11:54 pm
Operating System: macOS 10.13 High Sierra

Re: Schmitt trigger... Possible?

Post by cyrano » Fri Nov 04, 2016 9:20 pm

And it would even be easier in hardware. Like two diodes...

Flavioweb
Posts: 22
Joined: Fri Nov 04, 2016 8:23 pm
Operating System: Linux Debian

Re: Schmitt trigger... Possible?

Post by Flavioweb » Fri Nov 04, 2016 9:31 pm

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...

steve
Site Admin
Posts: 80679
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: Schmitt trigger... Possible?

Post by steve » Fri Nov 04, 2016 9:40 pm

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:

Code: Select all

(abs-env (mult 0.8 (hzosc 20)))
sine.png
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
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
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
firsttrack003.png (8.55 KiB) Viewed 1245 times
and a zoomed in view:
firsttrack004.png
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
firsttrack005.png (8.38 KiB) Viewed 1245 times
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

steve
Site Admin
Posts: 80679
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: Schmitt trigger... Possible?

Post by steve » Fri Nov 04, 2016 9:46 pm

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:

Code: Select all

(clip (mult *track* ny:all) 0.5)
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.
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

Post Reply