True sample and hold

For general discussion related FlowStone
Post Reply
BobF
Posts: 598
Joined: Mon Apr 20, 2015 9:54 pm

True sample and hold

Post by BobF »

Hello gang,

Does any one have a real sample and hold or could design one for me. That is one that samples (captures, grabs) the voltage of a continuously varying analog signal and holds (locks, freezes) its value at a constant level for a specified minimum period of time. This is the definition of a analog hardware sample and hold. I need a Flowstone version that does exactly the same thing.

Many thanks in advance if you have one or the possibilits of designing one!

Later then, BobF.....
RJHollins
Posts: 1573
Joined: Thu Mar 08, 2012 7:58 pm

Re: True sample and hold

Post by RJHollins »

Are you thinking something like a VCA ? [voltage control amplifier].

This 'sample/hold' value ... are you talking volume ? If so ... PEAK level? RMS ?
BobF
Posts: 598
Joined: Mon Apr 20, 2015 9:54 pm

Re: True sample and hold

Post by BobF »

Hi RJHOLLINS,

No! For now look up some definitions of a analog sample and hold. I will TRY to come up with a better explanation later if no one figures it out.

Thanks, BobF.....
User avatar
martinvicanek
Posts: 1334
Joined: Sat Jun 22, 2013 8:28 pm

Re: True sample and hold

Post by martinvicanek »

This will sample (and hold) the input value when the trigger goes from <=0 to >0:

Code: Select all

streamin in;   streamout out;
streamin sampleTrigger;

float prevTrigger;
float update;

update = (sampleTrigger>0)&(prevTrigger<=0);
out = out + (in - out)&update;
prevTrigger = sampleTrigger;
User avatar
martinvicanek
Posts: 1334
Joined: Sat Jun 22, 2013 8:28 pm

Re: True sample and hold

Post by martinvicanek »

And this one will hold for a specified time (=number of samples):

Code: Select all

streamin in;   streamout out;
streamin sampleTrigger;
streamin duration;

float trigger;
float prevTrigger;
float time;
float update;

trigger = (sampleTrigger>0)&(prevTrigger<=0);
prevTrigger = sampleTrigger;

time = min(time + 1,duration);
time = time - time&trigger;

update = trigger | (time>=duration);
out = out + (in - out)&update;
tulamide
Posts: 2714
Joined: Sat Jun 21, 2014 2:48 pm
Location: Germany

Re: True sample and hold

Post by tulamide »

I was just working on this, because I thought this would make a perfect entry in dsp programming. It is relatively simple. Yet, my code wasn't nearly as effective as yours, Martin. Especially, I don't understand this line in your second code:

Code: Select all

out = out + (in - out)&update;

I can read it, but I don't get the human logic behind it. Could you elaborate, please? Just if you can spare a minute!
"There lies the dog buried" (German saying translated literally)
User avatar
martinvicanek
Posts: 1334
Joined: Sat Jun 22, 2013 8:28 pm

Re: True sample and hold

Post by martinvicanek »

That's essentially

if update then out = in
else out = out

How is that? The "update" vasiable is a bit pattern, either all 1 or all 0. In the first case the expression evaluates to

out = out + (in - out)&1 = out + in - out = in

In the second case we get

out = out + (in - out)&0 = out + 0 = out

The objective of using bit masking insead of an if-then-else structure is to avoid branching so the code can be better optimized by the compiler. Specifically for FS, bitmasks work in the poly section of a synth whereas if-then-else does not.
Last edited by martinvicanek on Sun Sep 25, 2016 2:44 pm, edited 1 time in total.
BobF
Posts: 598
Joined: Mon Apr 20, 2015 9:54 pm

Re: True sample and hold

Post by BobF »

Thanks a million Martin,

I will defiantly put these to the test later today.

Also thank you tulamide for taking a look at it..

I will let you all know later today or tomorrow if it all works for my application.

Again thanks all, BobF.....
tulamide
Posts: 2714
Joined: Sat Jun 21, 2014 2:48 pm
Location: Germany

Re: True sample and hold

Post by tulamide »

BobF, I am excited to see what you will come up with!

Martin, thank you for the explanation. I know about bitmasking and why it is used, but when actually reading your thoughts that led you to this code it makes much more sense. It is sooooooooooo damn difficult for me to think in bitmasks rather than in branching, and I don't know why. I mean it is just computer logic and I am around computers for ages. In fact as a kid I built my own circuits to understand the then new invention of an IC. I love logic, yet this dsp code seems to slip aways under my thoughts and always tries to fool me. :oops:
"There lies the dog buried" (German saying translated literally)
Post Reply