Differentiating Then Integrating To Eliminate An Offset

B

Bret Cahill

Guest
This is a pretty common tactic isn't it? In situations where a
discontinuity in the derivative is possible, undefined for a short
period, the wave could be clipped or somehow limited before the
integration.


Bret Cagill
 
On Thu, 27 Aug 2009 08:05:54 -0700 (PDT), Bret Cahill
<BretCahill@peoplepc.com> wrote:

This is a pretty common tactic isn't it? In situations where a
discontinuity in the derivative is possible, undefined for a short
period, the wave could be clipped or somehow limited before the
integration.
Of course, there is the "constant of integration" if you use a true
integrator, and all real integrators drift and pile up errors. And any
clipping or other nonlinear processing of the derivative injects a
permanent error into the integrator. No, it's not a common tactic.


The simple AC coupling/highpass circuit is just


IN---------capacitor------+-------------OUT
|
|
|
resistor
|
|
|
ground


which, of course, loses any useful DC component in the signal.

There's also the dc-restore circuit, where the resistor above is
replaced by a switch. Close the switch now and then when you know the
signal is "zero."

John
 
On Thu, 27 Aug 2009 11:03:40 -0700 (PDT), Bret Cahill
<BretCahill@aol.com> wrote:

This is a pretty common tactic isn't it? In situations where a
discontinuity in the derivative is possible, undefined for a short
period, the wave could be clipped or somehow limited before the
integration.

Of course, there is the "constant of integration" if you use a true
integrator,

That is what needs to be zero. The goal was to center the sine wave
on zero.

Another way was to average to the DC component and then subtract the
DC from the original signal. An averager circuit on SPICE seemed to
be pretty fast, less than a few cycles.

One big advantage with differention-integration, however, is the same
circuit could be used to eliminate square waves as well as DC.

Two different situations can be covered with one circuit -- much more
flexible.

and all real integrators drift and pile up errors.

From cycle to cycle?

And any
clipping or other nonlinear processing of the derivative injects a
permanent error into the integrator.

If it's over a short time, say, a few degrees, a comparator could
detect it and maybe substitute some plausible value over the duration
of the spike. If it's a short enough time the error might be small.

No, it's not a common tactic.

The simple AC coupling/highpass circuit is just

IN---------capacitor------+-------------OUT
|
|
|
resistor
|
|
|
ground

which, of course, loses any useful DC component in the signal.

Losing DC and lower frequency noise is the goal but it must be within
0.5% in just a few cycles.

That was the other appeal of of taking the derivative and integrating
-- a near zero time constant.

There's also the dc-restore circuit, where the resistor above is
replaced by a switch. Close the switch now and then when you know the
signal is "zero."

The signal will be zero pi/2 after the derivative is zero or
discontinous or exactly between the peaks. What's the name of the
circuit that determines the period for each half cycle then uses half
that time to predict when the signal will be zero?

That circuit must be as common as XXX movies about lesbian judges
harassing their female law clerks.


Bret Cahill

Any time you'd like to start being coherent, we're ready.

John
 
This is a pretty common tactic isn't it? In situations where a
discontinuity in the derivative is possible, undefined for a short
period, the wave could be clipped or somehow limited before the
integration.

Of course, there is the "constant of integration" if you use a true
integrator,
That is what needs to be zero. The goal was to center the sine wave
on zero.

Another way was to average to the DC component and then subtract the
DC from the original signal. An averager circuit on SPICE seemed to
be pretty fast, less than a few cycles.

One big advantage with differention-integration, however, is the same
circuit could be used to eliminate square waves as well as DC.

Two different situations can be covered with one circuit -- much more
flexible.

and all real integrators drift and pile up errors.
From cycle to cycle?

And any
clipping or other nonlinear processing of the derivative injects a
permanent error into the integrator.
If it's over a short time, say, a few degrees, a comparator could
detect it and maybe substitute some plausible value over the duration
of the spike. If it's a short enough time the error might be small.

No, it's not a common tactic.

The simple AC coupling/highpass circuit is just

IN---------capacitor------+-------------OUT
|
|
|
resistor
|
|
|
ground

which, of course, loses any useful DC component in the signal.
Losing DC and lower frequency noise is the goal but it must be within
0.5% in just a few cycles.

That was the other appeal of of taking the derivative and integrating
-- a near zero time constant.

There's also the dc-restore circuit, where the resistor above is
replaced by a switch. Close the switch now and then when you know the
signal is "zero."
The signal will be zero pi/2 after the derivative is zero or
discontinous or exactly between the peaks. What's the name of the
circuit that determines the period for each half cycle then uses half
that time to predict when the signal will be zero?

That circuit must be as common as XXX movies about lesbian judges
harassing their female law clerks.


Bret Cahill
 
John Larkin wrote:
On Thu, 27 Aug 2009 11:03:40 -0700 (PDT), Bret Cahill
BretCahill@aol.com> wrote:

This is a pretty common tactic isn't it? In situations where a
discontinuity in the derivative is possible, undefined for a short
period, the wave could be clipped or somehow limited before the
integration.
Of course, there is the "constant of integration" if you use a true
integrator,
That is what needs to be zero. The goal was to center the sine wave
on zero.

Another way was to average to the DC component and then subtract the
DC from the original signal. An averager circuit on SPICE seemed to
be pretty fast, less than a few cycles.

One big advantage with differention-integration, however, is the same
circuit could be used to eliminate square waves as well as DC.

Two different situations can be covered with one circuit -- much more
flexible.

and all real integrators drift and pile up errors.
From cycle to cycle?
And any
clipping or other nonlinear processing of the derivative injects a
permanent error into the integrator.
If it's over a short time, say, a few degrees, a comparator could
detect it and maybe substitute some plausible value over the duration
of the spike. If it's a short enough time the error might be small.

No, it's not a common tactic.
The simple AC coupling/highpass circuit is just

IN---------capacitor------+-------------OUT
|
|
|
resistor
|
|
|
ground

which, of course, loses any useful DC component in the signal.
Losing DC and lower frequency noise is the goal but it must be within
0.5% in just a few cycles.

That was the other appeal of of taking the derivative and integrating
-- a near zero time constant.

There's also the dc-restore circuit, where the resistor above is
replaced by a switch. Close the switch now and then when you know the
signal is "zero."
The signal will be zero pi/2 after the derivative is zero or
discontinous or exactly between the peaks. What's the name of the
circuit that determines the period for each half cycle then uses half
that time to predict when the signal will be zero?

That circuit must be as common as XXX movies about lesbian judges
harassing their female law clerks.


Bret Cahill


Any time you'd like to start being coherent, we're ready.

John
I wonder would a simple AC coupling with bias resistor set to 1/2 Vcc
(or whatever is the appropriate voltage) produce the desired symmetry?
 
John Larkin wrote:
On Thu, 27 Aug 2009 11:03:40 -0700 (PDT), Bret Cahill
BretCahill@aol.com> wrote:

This is a pretty common tactic isn't it? In situations where a
discontinuity in the derivative is possible, undefined for a short
period, the wave could be clipped or somehow limited before the
integration.
Of course, there is the "constant of integration" if you use a true
integrator,
That is what needs to be zero. The goal was to center the sine wave
on zero.

Another way was to average to the DC component and then subtract the
DC from the original signal. An averager circuit on SPICE seemed to
be pretty fast, less than a few cycles.

One big advantage with differention-integration, however, is the same
circuit could be used to eliminate square waves as well as DC.

Two different situations can be covered with one circuit -- much more
flexible.

and all real integrators drift and pile up errors.
From cycle to cycle?
And any
clipping or other nonlinear processing of the derivative injects a
permanent error into the integrator.
If it's over a short time, say, a few degrees, a comparator could
detect it and maybe substitute some plausible value over the duration
of the spike. If it's a short enough time the error might be small.

No, it's not a common tactic.
The simple AC coupling/highpass circuit is just

IN---------capacitor------+-------------OUT
|
|
|
resistor
|
|
|
ground

which, of course, loses any useful DC component in the signal.
Losing DC and lower frequency noise is the goal but it must be within
0.5% in just a few cycles.

That was the other appeal of of taking the derivative and integrating
-- a near zero time constant.

There's also the dc-restore circuit, where the resistor above is
replaced by a switch. Close the switch now and then when you know the
signal is "zero."
The signal will be zero pi/2 after the derivative is zero or
discontinous or exactly between the peaks. What's the name of the
circuit that determines the period for each half cycle then uses half
that time to predict when the signal will be zero?

That circuit must be as common as XXX movies about lesbian judges
harassing their female law clerks.


Bret Cahill


Any time you'd like to start being coherent, we're ready.

John
(I guess that is what you were suggesting)
 
Bret Cahill wrote:
This is a pretty common tactic isn't it? In situations where a
discontinuity in the derivative is possible, undefined for a short
period, the wave could be clipped or somehow limited before the
integration.
Numerical differentiation is notoriously unstable and almost always
needs great care to get it right for even slightly awkward functions.
What you propose seems like a very brutal way to lose accuracy.

It isn't clear whether you are talking analogue (which will be band
limited by the slew rate of the amplifier) or digital signals here.

Why not state the original problem and you might get a sensible answer.

Regards,
Martin Brown
 
On Aug 27, 3:32 pm, John Larkin
<jjlar...@highNOTlandTHIStechnologyPART.com> wrote:
On Thu, 27 Aug 2009 11:03:40 -0700 (PDT), Bret Cahill





BretCah...@aol.com> wrote:
This is a pretty common tactic isn't it?  In situations where a
discontinuity in the derivative is possible, undefined for a short
period, the wave could be clipped or somehow limited before the
integration.

Of course, there is the "constant of integration" if you use a true
integrator,

That is what needs to be zero.  The goal was to center the sine wave
on zero.

Another way was to average to the DC component and then subtract the
DC from the original signal.  An averager circuit on SPICE seemed to
be pretty fast, less than a few cycles.

One big advantage with differention-integration, however, is the same
circuit could be used to eliminate square waves as well as DC.

Two different situations can be covered with one circuit -- much more
flexible.

and all real integrators drift and pile up errors.

From cycle to cycle?

And any
clipping or other nonlinear processing of the derivative injects a
permanent error into the integrator.

If it's over a short time, say, a few degrees, a comparator could
detect it and maybe substitute some plausible value over the duration
of the spike.  If it's a short enough time the error might be small.

No, it's not a common tactic.

The simple AC coupling/highpass circuit is just

IN---------capacitor------+-------------OUT
                          |
                          |
                          |
                       resistor
                          |
                          |
                          |
                        ground

which, of course, loses any useful DC component in the signal.

Losing DC and lower frequency noise is the goal but it must be within
0.5% in just a few cycles.

That was the other appeal of of taking the derivative and integrating
-- a near zero time constant.

There's also the dc-restore circuit, where the resistor above is
replaced by a switch. Close the switch now and then when you know the
signal is "zero."

The signal will be zero pi/2 after the derivative is zero or
discontinous or exactly between the peaks.  What's the name of the
circuit that determines the period for each half cycle then uses half
that time to predict when the signal will be zero?

That circuit must be as common as XXX movies about lesbian judges
harassing their female law clerks.

Bret Cahill

Any time you'd like to start being coherent, we're ready.

John- Hide quoted text -

- Show quoted text -
John I wonder why you humor Mr. Cahill. If you didn't respond he
might go away?

George H.
 
This is a pretty common tactic isn't it?  In situations where a
discontinuity in the derivative is possible, undefined for a short
period, the wave could be clipped or somehow limited before the
integration.

Numerical differentiation is notoriously unstable and almost always
needs great care to get it right for even slightly awkward functions.
It's just an analog op ap circuit.

What you propose seems like a very brutal way to lose accuracy.

It isn't clear whether you are talking analogue (which will be band
limited by the slew rate of the amplifier) or digital signals here.

Why not state the original problem and you might get a sensible answer.
There are actually two situations. It would be desirable to get both
with one circuit so the operator doesn't need to remember to flip any
switches.

The first has some DC that needs to be subtracted and the other has a
square wave +/- V (same frequency + 90 degree phase angle) that also
needs to be subtracted.

The original solution for the DC situation was to just average the
signal to DC and then subract that from the original signal.

This seems to work on SPICE if not actual circuits.

The original solution for the square wave situation was to integrate.
When the first derivative was positive add the integral to the
original signal and when the first derivative was negative subtract
the integral.

But if the differentiation - integration approach can be made to work,
only one circuit is necessary.


Bret Cahill
 
On Aug 27, 8:05 am, Bret Cahill <BretCah...@peoplepc.com> wrote:
This is a pretty common tactic isn't it?
Differentiating requires very high gain at high frequency, and
amplifies broadband noise. Practical differentiators always
have a high-frequency cutoff, so are effectively high-pass
filters.
Integrators always benefit from a low-frequency cutoff, or
offset voltages would result in saturation of amplifiers, so are
effectively low-pass filters.

Combine them, you have a bandpass filter. Yes, that's one
way to attack an offset voltage problem.
 
On Aug 27, 8:15 pm, whit3rd <whit...@gmail.com> wrote:
On Aug 27, 8:05 am, Bret Cahill <BretCah...@peoplepc.com> wrote:

This is a pretty common tactic isn't it?

Differentiating requires very high gain at high frequency, and
amplifies broadband noise.  Practical differentiators always
have a high-frequency cutoff, so are effectively high-pass
filters.
Integrators always benefit from a low-frequency cutoff, or
offset voltages would result in saturation of amplifiers, so are
effectively low-pass filters.

Combine them, you have a bandpass filter.  Yes, that's one
way to attack an offset voltage problem.

"> Integrators always benefit from a low-frequency cutoff, or
offset voltages would result in saturation of amplifiers, so are
effectively low-pass filters."
Except if the integrators are inside a control loop. Then (at least
sometimes) it's better not to roll them off with a big resistor.

George H.
 
Bret Cahill wrote:
This is a pretty common tactic isn't it? In situations where a
discontinuity in the derivative is possible, undefined for a short
period, the wave could be clipped or somehow limited before the
integration.
Numerical differentiation is notoriously unstable and almost always
needs great care to get it right for even slightly awkward functions.

It's just an analog op ap circuit.

What you propose seems like a very brutal way to lose accuracy.

It isn't clear whether you are talking analogue (which will be band
limited by the slew rate of the amplifier) or digital signals here.

Why not state the original problem and you might get a sensible answer.

There are actually two situations. It would be desirable to get both
with one circuit so the operator doesn't need to remember to flip any
switches.

The first has some DC that needs to be subtracted
OK. John has already shown you how to AC couple and clamp to earth to
lose a DC bias. This is basic stuff. You might also need to use a zero
adjust trimmer on the opamp to get exactly zero output depending on your
tolerances.

and the other has a
square wave +/- V (same frequency + 90 degree phase angle) that also
needs to be subtracted.
What sort of frequencies? And is the wanted component a sine wave or a
mixture of frequencies in a broadband signal.

If you have the reference squarewave available why not add the right
amount to cancel it out? Otherwise you need a PLL to recover it and had
better hope the wanted signal doesn't mask the carrier.

What purpose does this thing have?
The original solution for the DC situation was to just average the
signal to DC and then subract that from the original signal.

This seems to work on SPICE if not actual circuits.
Seems likely.
The original solution for the square wave situation was to integrate.
When the first derivative was positive add the integral to the
original signal and when the first derivative was negative subtract
the integral.

But if the differentiation - integration approach can be made to work,
only one circuit is necessary.
Nonesense. If you differentiate a square wave and then integrate it
again you get another square wave (slightly degraded in the real world).
You demonstrate remarkable cluelessness.

\ / \ / \ / \ / \ integral
_ _ _ _
_| |_| |_| |_| |_ raw signal

_|_ _|_ _|_ _|_ _ derivative
| | | |


It is a general property of all reasonable functions that the integral
of the derivative looks like the function to within an additive
constant. What you propose simply will not work.

Regards,
Martin Brown
 
This is a pretty common tactic isn't it?  In situations where a
discontinuity in the derivative is possible, undefined for a short
period, the wave could be clipped or somehow limited before the
integration.
Numerical differentiation is notoriously unstable and almost always
needs great care to get it right for even slightly awkward functions.

It's just an analog op ap circuit.

What you propose seems like a very brutal way to lose accuracy.

It isn't clear whether you are talking analogue (which will be band
limited by the slew rate of the amplifier) or digital signals here.

Why not state the original problem and you might get a sensible answer..

There are actually two situations.  It would be desirable to get both
with one circuit so the operator doesn't need to remember to flip any
switches.

The first has some DC that needs to be subtracted

OK. John has already shown you how to AC couple and clamp to earth to
lose a DC bias. This is basic stuff. You might also need to use a zero
adjust trimmer on the opamp to get exactly zero output depending on your
tolerances.

and the other has a
square wave +/- V (same frequency + 90 degree phase angle) that also
needs to be subtracted.

What sort of frequencies?
0.5 - 1 Hz

And is the wanted component a sine wave or a
mixture of frequencies in a broadband signal.
Something pretty close to a sine wave. I only need to know that it's
well behaved.

If you have the reference squarewave available why not add the right
amount to cancel it out? Otherwise you need a PLL to recover it and had
better hope the wanted signal doesn't mask the carrier.
The magnitude isn't known directly.

What purpose does this thing have?

The original solution for the DC situation was to just average the
signal to DC and then subract that from the original signal.

This seems to work on SPICE if not actual circuits.

Seems likely.

The original solution for the square wave situation was to integrate.
When the first derivative was positive add the integral to the
original signal and when the first derivative was negative subtract
the integral.

But if the differentiation - integration approach can be made to work,
only one circuit is necessary.

Nonesense.
f(x) = DC + sinwx

f'(x) = wcoswx

Int.[f'(x)] = sinwx + const.

Set const. = zero to eliminate DC.

Consider that a square wave is just a DC signal that periodically
changes values. The derivative of a square wave is always zero except
for when it is changing values.

As mentioned above, when the derivative is undefined, a comparator
could trigger a circuit to substitute the last known value of the
derivative for the duration of the spike, maybe a few degrees -- 30 -
40 msec in my case.

For a 90 degree phase angle between the square wave and a sine curve
the last known value of the derivative would be very close to zero.

Integrate the patched derivative that to recover the original signal w/
o the square wave.

Some phase angle issues may appear and need treatment but one circuit
will work on square waves, any arbitrarily intermittent DC as well as
conventional DC.

If you differentiate a square wave and then integrate it
again you get another square wave (slightly degraded in the real world).
Try differentiating and integrating a square wave on SPICE and see
what happens.


Bret Cahill
 
Bret Cahill wrote:
This is a pretty common tactic isn't it? In situations where a
discontinuity in the derivative is possible, undefined for a short
period, the wave could be clipped or somehow limited before the
integration.
Numerical differentiation is notoriously unstable and almost always
needs great care to get it right for even slightly awkward functions.
It's just an analog op ap circuit.
What you propose seems like a very brutal way to lose accuracy.
It isn't clear whether you are talking analogue (which will be band
limited by the slew rate of the amplifier) or digital signals here.
Why not state the original problem and you might get a sensible answer.
There are actually two situations. It would be desirable to get both
with one circuit so the operator doesn't need to remember to flip any
switches.
The first has some DC that needs to be subtracted
OK. John has already shown you how to AC couple and clamp to earth to
lose a DC bias. This is basic stuff. You might also need to use a zero
adjust trimmer on the opamp to get exactly zero output depending on your
tolerances.

and the other has a
square wave +/- V (same frequency + 90 degree phase angle) that also
needs to be subtracted.
What sort of frequencies?

0.5 - 1 Hz

And is the wanted component a sine wave or a
mixture of frequencies in a broadband signal.

Something pretty close to a sine wave. I only need to know that it's
well behaved.

If you have the reference squarewave available why not add the right
amount to cancel it out? Otherwise you need a PLL to recover it and had
better hope the wanted signal doesn't mask the carrier.

The magnitude isn't known directly.

What purpose does this thing have?

The original solution for the DC situation was to just average the
signal to DC and then subract that from the original signal.

This seems to work on SPICE if not actual circuits.

Seems likely.

The original solution for the square wave situation was to integrate.
When the first derivative was positive add the integral to the
original signal and when the first derivative was negative subtract
the integral.

But if the differentiation - integration approach can be made to work,
only one circuit is necessary.

Nonesense.

f(x) = DC + sinwx

f'(x) = wcoswx

Int.[f'(x)] = sinwx + const.

Set const. = zero to eliminate DC.
AC coupling which you have already been shown is a lot simpler.
Consider that a square wave is just a DC signal that periodically
changes values. The derivative of a square wave is always zero except
for when it is changing values.
For an ideal infinite bandwidth square wave perhaps. Most real signals
tend to have finite bandwidth. YMMV.

It can also be expressed as a sum of its Fourier components by a well
known formula. So guess what. For any reasonable function even one that
is piecewise discontinuous you get back a scaled version of it limited
only by the slew rate of the original waveform and clipping on the
derivative spikes.
As mentioned above, when the derivative is undefined, a comparator
could trigger a circuit to substitute the last known value of the
derivative for the duration of the spike, maybe a few degrees -- 30 -
40 msec in my case.

For a 90 degree phase angle between the square wave and a sine curve
the last known value of the derivative would be very close to zero.

Integrate the patched derivative that to recover the original signal w/
o the square wave.

Some phase angle issues may appear and need treatment but one circuit
will work on square waves, any arbitrarily intermittent DC as well as
conventional DC.

If you differentiate a square wave and then integrate it
again you get another square wave (slightly degraded in the real world).

Try differentiating and integrating a square wave on SPICE and see
what happens.
I don't care what defects SPICE has simulating this problem I know what
the results will be in the real world.

Regards,
Martin Brown
 
This is a pretty common tactic isn't it?  In situations where a
discontinuity in the derivative is possible, undefined for a short
period, the wave could be clipped or somehow limited before the
integration.
Numerical differentiation is notoriously unstable and almost always
needs great care to get it right for even slightly awkward functions..
It's just an analog op ap circuit.
What you propose seems like a very brutal way to lose accuracy.
It isn't clear whether you are talking analogue (which will be band
limited by the slew rate of the amplifier) or digital signals here.
Why not state the original problem and you might get a sensible answer.
There are actually two situations.  It would be desirable to get both
with one circuit so the operator doesn't need to remember to flip any
switches.
The first has some DC that needs to be subtracted
OK. John has already shown you how to AC couple and clamp to earth to
lose a DC bias. This is basic stuff. You might also need to use a zero
adjust trimmer on the opamp to get exactly zero output depending on your
tolerances.

and the other has a
square wave +/- V (same frequency + 90 degree phase angle) that also
needs to be subtracted.
What sort of frequencies?

0.5 - 1 Hz

And is the wanted component a sine wave or a
mixture of frequencies in a broadband signal.

Something pretty close to a sine wave.  I only need to know that it's
well behaved.

If you have the reference squarewave available why not add the right
amount to cancel it out? Otherwise you need a PLL to recover it and had
better hope the wanted signal doesn't mask the carrier.

The magnitude isn't known directly.

What purpose does this thing have?

The original solution for the DC situation was to just average the
signal to DC and then subract that from the original signal.

This seems to work on SPICE if not actual circuits.

Seems likely.

The original solution for the square wave situation was to integrate.
When the first derivative was positive add the integral to the
original signal and when the first derivative was negative subtract
the integral.

But if the differentiation - integration approach can be made to work,
only one circuit is necessary.

Nonesense.

f(x) = DC + sinwx

f'(x) = wcoswx

Int.[f'(x)] = sinwx + const.

Set const. = zero to eliminate DC.

AC coupling which you have already been shown is a lot simpler.
The error must be below 0.5% in less than 4 - 6 cycles in one
situation

Also it would be nice to have one circuit for both situations.

Consider that a square wave is just a DC signal that periodically
changes values.  The derivative of a square wave is always zero except
for when it is changing values.

For an ideal infinite bandwidth square wave perhaps. Most real signals
tend to have finite bandwidth. YMMV.

It can also be expressed as a sum of its Fourier components by a well
known formula. So guess what. For any reasonable function even one that
is piecewise discontinuous you get back a scaled version of it limited
only by the slew rate of the original waveform and clipping on the
derivative spikes.
The area of the spikes is less than 1% on SPICE. They alternate +/-
to cancel each other out each cycle so there is no need to deal with
them before integration.

As mentioned above, when the derivative is undefined, a comparator
could trigger a circuit to substitute the last known value of the
derivative for the duration of the spike, maybe a few degrees  -- 30 -
40 msec in my case.

For a 90 degree phase angle between the square wave and a sine curve
the last known value of the derivative would be very close to zero.

Integrate the patched derivative that to recover the original signal w/
o the square wave.

Some phase angle issues may appear and need treatment but one circuit
will work on square waves, any arbitrarily intermittent DC as well as
conventional DC.

If you differentiate a square wave and then integrate it
again you get another square wave (slightly degraded in the real world).

Try differentiating and integrating a square wave on SPICE and see
what happens.

I don't care what defects SPICE has simulating this problem I know what
the results will be in the real world.
Nothing like a square wave will reappear after integration regardless
of the real world components.


Bret Cahill
 
This is a pretty common tactic isn't it?  In situations where a
discontinuity in the derivative is possible, undefined for a short
period, the wave could be clipped or somehow limited before the
integration.
Numerical differentiation is notoriously unstable and almost always
needs great care to get it right for even slightly awkward functions.
It's just an analog op ap circuit.
What you propose seems like a very brutal way to lose accuracy.
It isn't clear whether you are talking analogue (which will be band
limited by the slew rate of the amplifier) or digital signals here..
Why not state the original problem and you might get a sensible answer.
There are actually two situations.  It would be desirable to get both
with one circuit so the operator doesn't need to remember to flip any
switches.
The first has some DC that needs to be subtracted
OK. John has already shown you how to AC couple and clamp to earth to
lose a DC bias. This is basic stuff. You might also need to use a zero
adjust trimmer on the opamp to get exactly zero output depending on your
tolerances.

and the other has a
square wave +/- V (same frequency + 90 degree phase angle) that also
needs to be subtracted.
What sort of frequencies?

0.5 - 1 Hz

And is the wanted component a sine wave or a
mixture of frequencies in a broadband signal.

Something pretty close to a sine wave.  I only need to know that it's
well behaved.

If you have the reference squarewave available why not add the right
amount to cancel it out? Otherwise you need a PLL to recover it and had
better hope the wanted signal doesn't mask the carrier.

The magnitude isn't known directly.

What purpose does this thing have?

The original solution for the DC situation was to just average the
signal to DC and then subract that from the original signal.

This seems to work on SPICE if not actual circuits.

Seems likely.

The original solution for the square wave situation was to integrate.
When the first derivative was positive add the integral to the
original signal and when the first derivative was negative subtract
the integral.

But if the differentiation - integration approach can be made to work,
only one circuit is necessary.

Nonesense.

f(x) = DC + sinwx

f'(x) = wcoswx

Int.[f'(x)] = sinwx + const.
Set const. = zero to eliminate DC.
AC coupling which you have already been shown is a lot simpler.

The error must be below 0.5% in less than 4 - 6 cycles in one
situation

Also it would be nice to have one circuit for both situations.

Consider that a square wave is just a DC signal that periodically
changes values.  The derivative of a square wave is always zero except
for when it is changing values.
For an ideal infinite bandwidth square wave perhaps. Most real signals
tend to have finite bandwidth. YMMV.
It can also be expressed as a sum of its Fourier components by a well
known formula. So guess what. For any reasonable function even one that
is piecewise discontinuous you get back a scaled version of it limited
only by the slew rate of the original waveform and clipping on the
derivative spikes.

The area of the spikes is less than 1% on SPICE.  They alternate +/-
to cancel each other out each cycle so there is no need to deal with
them before integration.





As mentioned above, when the derivative is undefined, a comparator
could trigger a circuit to substitute the last known value of the
derivative for the duration of the spike, maybe a few degrees  -- 30 -
40 msec in my case.
For a 90 degree phase angle between the square wave and a sine curve
the last known value of the derivative would be very close to zero.

Integrate the patched derivative that to recover the original signal w/
o the square wave.

Some phase angle issues may appear and need treatment but one circuit
will work on square waves, any arbitrarily intermittent DC as well as
conventional DC.

If you differentiate a square wave and then integrate it
again you get another square wave (slightly degraded in the real world).

Try differentiating and integrating a square wave on SPICE and see
what happens.

I don't care what defects SPICE has simulating this problem I know what
the results will be in the real world.

Nothing like a square wave will reappear after integration regardless
of the real world components.
CORRECTION:

Unless the spikes are knocked out after the differentiation the square
wave will reappear on integration.


Bret Cahill
 
This is a pretty common tactic isn't it? In situations where a
discontinuity in the derivative is possible, undefined for a short
period, the wave could be clipped or somehow limited before the
integration.
Numerical differentiation is notoriously unstable and almost always
needs great care to get it right for even slightly awkward functions.
It's just an analog op ap circuit.
What you propose seems like a very brutal way to lose accuracy.
It isn't clear whether you are talking analogue (which will be band
limited by the slew rate of the amplifier) or digital signals here.
Why not state the original problem and you might get a sensible answer.
There are actually two situations. It would be desirable to get both
with one circuit so the operator doesn't need to remember to flip any
switches.
The first has some DC that needs to be subtracted
OK. John has already shown you how to AC couple and clamp to earth to
lose a DC bias. This is basic stuff. You might also need to use a zero
adjust trimmer on the opamp to get exactly zero output depending on your
tolerances.

and the other has a
square wave +/- V (same frequency + 90 degree phase angle) that also
needs to be subtracted.
What sort of frequencies?

0.5 - 1 Hz

And is the wanted component a sine wave or a
mixture of frequencies in a broadband signal.

Something pretty close to a sine wave. I only need to know that it's
well behaved.

If you have the reference squarewave available why not add the right
amount to cancel it out? Otherwise you need a PLL to recover it and had
better hope the wanted signal doesn't mask the carrier.

The magnitude isn't known directly.

What purpose does this thing have?

The original solution for the DC situation was to just average the
signal to DC and then subract that from the original signal.

This seems to work on SPICE if not actual circuits.

Seems likely.

The original solution for the square wave situation was to integrate.
When the first derivative was positive add the integral to the
original signal and when the first derivative was negative subtract
the integral.

But if the differentiation - integration approach can be made to work,
only one circuit is necessary.

Nonesense.

f(x) = DC + sinwx

f'(x) = wcoswx

Int.[f'(x)] = sinwx + const.

Set const. = zero to eliminate DC.

AC coupling which you have already been shown is a lot simpler.



Consider that a square wave is just a DC signal that periodically
changes values. The derivative of a square wave is always zero except
for when it is changing values.

For an ideal infinite bandwidth square wave perhaps. Most real signals
tend to have finite bandwidth. YMMV.

It can also be expressed as a sum of its Fourier components by a well
known formula. So guess what. For any reasonable function even one that
is piecewise discontinuous you get back a scaled version of it limited
only by the slew rate of the original waveform and clipping on the
derivative spikes.







As mentioned above, when the derivative is undefined, a comparator
could trigger a circuit to substitute the last known value of the
derivative for the duration of the spike, maybe a few degrees -- 30 -
40 msec in my case.

For a 90 degree phase angle between the square wave and a sine curve
the last known value of the derivative would be very close to zero.

Integrate the patched derivative that to recover the original signal w/
o the square wave.

Some phase angle issues may appear and need treatment but one circuit
will work on square waves, any arbitrarily intermittent DC as well as
conventional DC.

If you differentiate a square wave and then integrate it
again you get another square wave (slightly degraded in the real world).

Try differentiating and integrating a square wave on SPICE and see
what happens.

I don't care what defects SPICE has simulating this problem I know what
the results will be in the real world.
It's true on SPICE as well.

But I found an easy way to eliminate as much of the square wave as
necessary.

Take one or more derivatives until the amplitude of the spikes is >>
than the sine curve.

Then amplify just enough so almost all of each spike is clipped by the
limiting voltage but not the sine curve. (I don't know if this is
"clipping" is kosher or not.)

Then integrate back -- if necessary -- to recover the sine curve.


Bret Cahill
 
Take one or more derivatives until the amplitude of the spikes is
than the sine curve.

Then amplify just enough so almost all of each spike is clipped by the
limiting voltage but not the sine curve.  (I don't know if this is
"clipping" is kosher or not.)

Then integrate back -- if necessary -- to recover the sine curve.
If there is high frequency sine noise first use a low pass filter.


Bret Cahill
 

Welcome to EDABoard.com

Sponsor

Back
Top