Go Down

Topic: Signal rectification (Read 3666 times) previous topic - next topic

ThomsonPA

I have an input signal, for example with the values:

0, 20, 40, 20, 0, -20, -40, -20, 0
As you can see its a sine wave.
What I would like is the first half of the wave only, but struggling to code it.
So if it starts positive, only have the positive part (rest zero).

In the same way, if the signal is: 0, -20, -40, -20, 0, 20, 40, 20, 0.
Then I only want the first negative half.

There can be any number of values within the wave (freq.).

Can anyone suggest some codecode to help?

Grumpy_Mike

Quote
As you can see its a sine wave.

Can I?

Have you already got these numbers in the machine? If so a simple
Code: [Select]

if(number > 0) { // store the number

will do it.
What do you want to do with these numbers?

ThomsonPA

Plot it in time domain and yeah it is a sine wave, power of imagination ;)

Yeah I could store them, them, but the wave can have infinite values, so it almost needs to be in real time?

ThomsonPA

See the attached! :)

Grumpy_Mike

Quote
See the attached!

I see a massively large picture that is difficult to view with some wiggly lines on it. I do not see any answers to my questions.

Quote
Plot it in time domain and yeah it is a sine wave, power of imagination

Looks like a triangle to me.

The point is we have no idea about what you want to do or what equipment you have.

UnoDueTre


I have an input signal, for example with the values:

0, 20, 40, 20, 0, -20, -40, -20, 0
As you can see its a sine wave.



Irrespective of the waveform, I assume that the "negative" values are just those below a certain threshold but still positive with respect to ground and you are not actually feeding true negative signals to the ADC of your Arduino.

DVDdoug

#6
Dec 08, 2013, 08:44 pm Last Edit: Dec 08, 2013, 08:47 pm by DVDdoug Reason: 1
Quote
Yeah I could store them, them, but the wave can have infinite values, so it almost needs to be in real time?
The if-statement is your starting-point.   What you do based on the results of the if-statement is up to you.


Quote
so it almost needs to be in real time?

Where are the real time negative numbers coming from?   ..The ADC doesn't go negative.


Quote
So if it starts positive, only have the positive part (rest zero).


This will convert all of your negative numbers to zero:
Code: [Select]

if(number > 0)
     number = 0;



An if-statement is one way to throw-away the negative values.  For full-wave rectification (converting negative values to positive) you can use the absolute value function.



Quote
There can be any number of values within the wave (freq.).
Yes...    But without knowing the sample rate, there is no frequency...  There is only a sine wave (approximation) with no time scale.    i.e. CDs are sampled at 44.1kHz, so a 22,050Hz signal has two samples per cycle (one per half-cycle).   A 1kHz wave has about 44 samples per cycle.     If you play it back at the wrong sample rate, the speed & frequency will be wrong (like playing-back a record at the wrong speed),        WAV files have a sample-rate field in the header so they play back at the right speed/frequency.  Here is an  Introduction to Digital Audio..

Go Up