Support

If you have a problem or need to report a bug please email : support@dsprobotics.com

There are 3 sections to this support area:

DOWNLOADS: access to product manuals, support files and drivers

HELP & INFORMATION: tutorials and example files for learning or finding pre-made modules for your projects

USER FORUMS: meet with other users and exchange ideas, you can also get help and assistance here

NEW REGISTRATIONS - please contact us if you wish to register on the forum

Users are reminded of the forum rules they sign up to which prohibits any activity that violates any laws including posting material covered by copyright

True sample and hold

For general discussion related FlowStone

True sample and hold

Postby BobF » Sat Sep 24, 2016 11:08 pm

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.....
BobF
 
Posts: 598
Joined: Mon Apr 20, 2015 9:54 pm

Re: True sample and hold

Postby RJHollins » Sun Sep 25, 2016 2:39 am

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

This 'sample/hold' value ... are you talking volume ? If so ... PEAK level? RMS ?
RJHollins
 
Posts: 1571
Joined: Thu Mar 08, 2012 7:58 pm

Re: True sample and hold

Postby BobF » Sun Sep 25, 2016 3:34 am

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.....
BobF
 
Posts: 598
Joined: Mon Apr 20, 2015 9:54 pm

Re: True sample and hold

Postby martinvicanek » Sun Sep 25, 2016 4:14 am

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: 1328
Joined: Sat Jun 22, 2013 8:28 pm

Re: True sample and hold

Postby martinvicanek » Sun Sep 25, 2016 4:29 am

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;
User avatar
martinvicanek
 
Posts: 1328
Joined: Sat Jun 22, 2013 8:28 pm

Re: True sample and hold

Postby tulamide » Sun Sep 25, 2016 4:51 am

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)
tulamide
 
Posts: 2714
Joined: Sat Jun 21, 2014 2:48 pm
Location: Germany

Re: True sample and hold

Postby martinvicanek » Sun Sep 25, 2016 9:13 am

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.
User avatar
martinvicanek
 
Posts: 1328
Joined: Sat Jun 22, 2013 8:28 pm

Re: True sample and hold

Postby BobF » Sun Sep 25, 2016 2:07 pm

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.....
BobF
 
Posts: 598
Joined: Mon Apr 20, 2015 9:54 pm

Re: True sample and hold

Postby tulamide » Sun Sep 25, 2016 11:12 pm

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)
tulamide
 
Posts: 2714
Joined: Sat Jun 21, 2014 2:48 pm
Location: Germany


Return to General

Who is online

Users browsing this forum: No registered users and 44 guests