Page 1 of 1

Comparator

Posted: Thu Jun 09, 2016 7:57 pm
by BobF
Hell gang,

I could really use some help from someone who knows code and could code me a simple stream comparator. What I need is this. Comparison of relative states of plus and minus inputs. If the in(+)is greater than in(-), the output is 1, if in(+) is less than in(-), the output is 0. Only two states 0 or 1. This does have to work with streams as I am comparing two waveforms and need a stream of 1's and 0's from the the two compared streams.
For those that know electronics, this is just a simple analog voltage comparator.

Well that's it. Hope someone can help. If so many thanks in advance.
Later then, BobF.....

Re: Comparator

Posted: Thu Jun 09, 2016 8:11 pm
by adamszabo
If I understood correctly you have two inputs? Then this should do it:

Code: Select all

streamin in1;
streamin in2;
streamout out;

out = (in1 > in2) & 1;


If in1 is greater than in2 it outputs 1, otherwise 0

Re: Comparator

Posted: Thu Jun 09, 2016 8:17 pm
by tulamide
Sadly I can't help with the code. But as I understand it, the absolute value is to be compared:

+0.6|-0.7

abs(0.7) > abs(0.6)

sign of the greater is negative, so output is 0


+0.6|-0.4

abs(0.6) > abs(0.4)

sign of the greater is positive, so output is 1

the abs function is pretty cpu heavy I've heard, so I don't know how to realize it with DSP.

Re: Comparator

Posted: Sun Jun 12, 2016 3:36 am
by BobF
Thanks, adamszabo and tulamide,

Sorry this is late. Just been busy like we all are.

Comments, tips, hits, suggestions, and so on are always very much appreciated.

Later then, BobF.....