2
$\begingroup$

I've got this plot with two sine waves enter image description here

and what I need is follow: enter image description here

Amplitude values can diverge from time to time like here min 100 and max 700 but another time it's 300 600.

I guess I will not be able to get these nice phased waves from those on my picture.. But let's assume we have only one sampled sine wave. How to translate it to 001111110000011111 where 1s are for sine above "zero"(that's the main problem, every time it will be different point, like here it's around 400) and 0s for below zero. And another difficulty it would be nice to get this conversion on the go/online. Like I don't have whole sampled signal but only let's say 100 last values(10-60 these sine slopes).

Please, can you at least say what I should google? Thank you :)

UPDATE I've asked a little wrong.. How can I get zero line from signal like this? To apply suggested Sign[]. It's vary bad scenario sine wave.. In my case it's bouncing not around zero but some changing Y. It lasts around one value only few slopes.. enter image description here

ANSWER Well, that's up to how you want to treat the data. I suppose the simplest way is to take the Mean of the data streams, and treat that as the "zero" - so just subtract it from the stream and then do the Sign. Also take a look at Rescale, Clip, and Standardize - all can be used to good effect here, e.g. waveSquared[[All, 2]] = Sign@Standardize@waveSquared[[All, 2]];... – @rasher

Now it looks like this enter image description here

$\endgroup$
  • $\begingroup$ What do you mean by "on the go"? How are you getting the data? $\endgroup$ – Dr. belisarius May 26 '14 at 22:02
  • $\begingroup$ i.stack.imgur.com/RU1cg.png $\endgroup$ – rm -rf May 26 '14 at 22:12
  • $\begingroup$ @belisarius I'm just testing in mathematica and will be getting them from the sensor on the wheel to arduino. en.wikipedia.org/wiki/Rotary_encoder#Incremental_rotary_encoder $\endgroup$ – a_vasilkov May 26 '14 at 22:16
  • $\begingroup$ Would it not be better to deal with this in the electronics rather than try to postprocess the signal? For instance, capacitively couple the signals to remove the offset, threshold them (e.g. using a Schmitt trigger), and then use them as inputs to a comparator? $\endgroup$ – Oleksandr R. May 27 '14 at 0:11
3
$\begingroup$

Is something like this what you're after:

wave = Table[{x, Sin[x]}, {x, 0, 20, .01}];

waveSquared = wave;

waveSquared[[All, 2]] = Sign@waveSquared[[All, 2]];

ListLinePlot[{wave, waveSquared}]

enter image description here

$\endgroup$
  • $\begingroup$ Thank you. Yep. something like that.. Only I have not an ideal sine wave.. I've updated question post. $\endgroup$ – a_vasilkov May 26 '14 at 22:25
  • $\begingroup$ In my case it's bouncing not around zero but some changing Y. It lasts around one value only few slopes.. $\endgroup$ – a_vasilkov May 26 '14 at 22:32
  • $\begingroup$ Well, that's up to how you want to treat the data. I suppose the simplest way is to take the Mean of the data streams, and treat that as the "zero" - so just subtract it from the stream and then do the Sign. Also take a look at Rescale, Clip, and Standardize - all can be used to good effect here, e.g. waveSquared[[All, 2]] = Sign@Standardize@waveSquared[[All, 2]];... $\endgroup$ – ciao May 26 '14 at 22:32
  • $\begingroup$ Yep. It's exactly what I need. Thanks $\endgroup$ – a_vasilkov May 26 '14 at 22:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.