LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Filtering a Square Wave

In this case, I'd consider reading the signal in its native habitat.  After all, that's what the receiving end of this signal is going to see.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 11 of 24
(1,695 Views)

The interfering signal is almost exactly at the 5th harmonic of the pulse signal and is very nearly synchronous with the pulses.  I suspect that you can get reasonably good rise time measurements without worrying about removing the interfering signal.

 

Here is an example. It contains some unused code which I had tried but later discarded. I removed that last element from the data set because it is an outlier. I looked at the spectrum. It clearly shows the harmonic content of the pulses. The spectrum of the 7.5 kHz sine wave is essentially undistinguishable from the harmonics of the pulses. The for loop finds the indexes in the data array where the signal crosses the "10%" and "90%" thresholds. The thresholds are in quotes " " because the values used are "eyeball" estimates rather than trying to program a determination of the amplitude of the sine wave.  The constant 0.38 used in calculating the thresholds would be 0.45 (90% * 0.5) if no interference was present.

 

Note that the graph of the rise times has a distinctly periodic look to it.  That is probably the effect of the interference.

 

Lynn

0 Kudos
Message 12 of 24
(1,683 Views)

I also recommend Ott's book.

 

Sometimes the programmer needs to tell the manager that not every problem can be or should be solved in software.  "When the only tool you have is a hammer, every problem looks like a nail."

 

Lynn

0 Kudos
Message 13 of 24
(1,681 Views)

This is a very unique problem since, as Johnsold pointed out, your unwanted signal is (mainly) the exact 5th harmonic of your square wave fundamental. Since that harmonic is also a very important component of your signal you cannot just filter it out without significantly affecting your rise time. What you need to do is to remove 'just enough' of it to kill the unwanted component. I have attached a Vi that shows how you can do this. It requires some manual tweaking, but it could be done automatically if needed.The steps are:

1 - Find the fundamental frequency F0 of your signal

2 - Create a sine tone with frequency 5*F0 and adjustable amplitude and phase and subtract it from your input signal

3 - Adjust amplitude and phase values until you minimize the error signal

 

Remove Tone.jpg

 

Hope this works for you,

Alain

 

Message 14 of 24
(1,655 Views)

@LocalDSP wrote:

This is a very unique problem since, as Johnsold pointed out, your unwanted signal is (mainly) the exact 5th harmonic of your square wave fundamental....


I would love to throw a small cap across the input just to see if it would change the oscillations. It reminds me of superhetrodyne type effect. If the circuit just happens to be tuned to a harmonic frequency of the square wave we may be seeing the cicuit oscillating.

 

The other approach would skip adding a capacitor but changing the square wave signal is not a harmonic of the current frequency.

 

Ben   

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 15 of 24
(1,645 Views)

Alain,

 

I condsidered something similar to your approach but discarded it due to the phase variation between the pulse and the sine wave over the data set.  Extract Single Tone Information.vi uses FFT methods to determine the frequencies. The data set does not have suffcient samples to allow the FFT to resolve the sine wave from the harmonic of the pulses (df = 1.667 Hz) so the match is more likely to the pulse harmonic than to the sine wave.

 

Here is the result of extending your code to the entire data set. Compare the last 3 milliseconds of data to the first 3 as shown in your post above. Note that the sine amplitude is actually larger.

 

Last 3 ms.png

 

Here is an image of the graphs for the entire data set. Note the cyclical variation of the envelope of the Processed Signal. I suspect that the two and a half cycles represent the difference in frequency between the sine wave and the fifth harmonic of the pulse frequency.

 

Now look at the spectrum of the total signal. The fundamental of the pulse frequency shows a symmetrical peak at 1500 Hz. The sidebands at about +/-17 Hz are also symmetrical. The fifth harmonic at 7500 Hz is much messier.  The main peak has an unresolved component a few hertz higher. The sidebands do not appear to have the same kind of "bulge."  My guess is that the unresolved component represents the sine wave.  I have no idea of what generates the sidebands but suspect that they are not linked to the sinewave.

 

Pulse fundamental.png

 

Fifth harmonic.png

 

Lynn

Message 16 of 24
(1,629 Views)

Hi Lynn,

 

    I agree with you that the Extract Tone Information VI is not ideal for detecting signals that either drift in frequency or have close side-bands (like it's the case here). That is why I was 'cheating' and only analyzed a short portion of the signal where the apparent drift is negligible (or at least small)

 

    Since the goal was to measure the pulse rise time I was hoping a shorter signal portion would be enough, and if not the process could be repeated on small chunks for the entire signal. The detected frequency will vary from chunk to chunk (basically following the modulation frequency of 17 Hz, but the cancellation should be pretty good for each individual chunk.

 

    All this is work around and as Ben mentioned earlier the right approach is really to try to identify the root causes and fix them at the source.

 

Alain

Message 17 of 24
(1,624 Views)

Your approach will work well if repeated in segments, as you suggest.

 

Some of my comments were intended to educate the OP who stated that he head limited knowledge of filtering.

 

The OP has not responded with any information about the source of the signal/interference or details of the measurements, such as one rise time measurement or measurement of every pulse.

 

Without more information about what the goal is, anything further is purely speculative.

 

Lynn

Message 18 of 24
(1,590 Views)

@johnsold wrote:

...

 

Without more information about what the goal is, anything further is purely speculative.

 

Lynn


Ditto that!

 

While I spent little time analyzing the data offered for our inspection, ther near constnat amplitude over the data set of the "noise" makes me question how the data looks without the square wave.

 

That could tell a lot and offer direction.

 

Ben

 

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 19 of 24
(1,532 Views)

This has been a very educational case study and I greatly appreciate everyone's inputs.

 

To answer an earlier question, the measurements without the square wave look like a perfect sine wave (not really random noise) centered at 1.8 volts with an amplitude of a little less than .1 volts.  So about 1.7-1.9 Volts.  The frequency is exactly that of the data shown.  So it's clearly a system thing.  

 

We do have the signal wire and the filtered signal wire passing by a 220VAC motor unshielded.  The client has purchased some clip on shields and we're going to cover the signal wire in this to see if this further improves our signal.

Message 20 of 24
(1,516 Views)