LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

filter

Hello Lynn,
 
1. The sampling frequency is 10kHz. The signal comes from a photo-sensor and is amplified by a op-amp.
The signal range is +/- 10V.
 
2. The results of the measurement are not to control something. It is just for information, just to be displayed.
I would like that the measured signal and the calculation results are displayed at the same time. But it is ok
that the user has to wait between the times that something is written to the screen.
 
So, a signal is measured. Next the calculations are done. Finally everything is written to the screen.
 
3. Yes, the DC level can vary. How much this is, I don't know. This can not be predicted. But it doesn't vary fast.
This can happen with a frequency of 1 or 2Hz. But mostly it varies with less than 1Hz. I need a continuous update.
 
What I want is that the measured signal is filtered with a very low -3dB frequency. So every change in signal is
filtered out accept for the DC level and some very slow variations. Then I multiply the filtered result with 0.9 and 1.1
So I create a window in wich the signal lies. When I compare the measured, unfiltered signal with this window and
the unfiltered signal has a higher frequency component with a sertain amplitude in it, than this will come outside of
the window. I want to count these "outside" signals.
 
Hope this clears some things.
 
Martijn
0 Kudos
Message 11 of 13
(877 Views)
Martijn,

I think I have an idea which may work for you. Rather than using a standard filter, use a running (or moving) average. You could average 10 or 100 seconds of data but update twice per second. You would still have a transient for the first 10 (or 100) seconds but after that the data could be updated as often as you want. The updates can occur at the rate you read samples from the DAQ (not the DAQ sampling rate). Your sampling rate is 10 kHz. If you read 5000 samples at a time, you would get two updates per second.

What version of LV are you using? I will try to put together an example showing what I am suggesting.

Another approach might be to use the regression routines to fit a straight line to a segment of the data. This would be a "DC" value which would reject the high frequency interference. It probably has no real advantage in your application over the moving average.

Lynn
Message 12 of 13
(865 Views)
Martin,

Your sample rate seems very high compared to the cutoff frequency of the filters.  If I understand correctly, your sample rate is 10kHz, and the cutoff frequency is either 0.1Hz, or 0.01Hz.  If the frequencies are normalized by the sampling rate, then Fs=1, Fc=1E-5 or 1E-6.  This is a tough design problem, and the filters can possibly become unstable or have numerical problems.  I think Lynn has a good idea here.  In some way, if you resample your data and prevent aliasing then the lower data rate can be subsequently filtered or stored, and the numerical behavior of the filters at the reduced data-rate is much more robust.  If you want to implement Lynn's approach, try using the Decimate (continuous).vi, with the averaging input set to True.  For more complete control over anti-aliasing with resampling, try using Rational Resample.vi, or Resample Waveforms (continuous).vi.  Since you will probably choose a simple resampling factor, I would probably suggest the Rational Resample.vi.  The output of any of the resampled signals can then be passed on to subsequent filtering if you want.  If you choose a large enough resampling factor, say 50,000, then the new sampling rate will be 0.2Hz, and the Nyquist rate will be 0.1 Hz.  No filtering needed.  If you then want to change the cutoff frequency you could use the resampled signal, and pass it through another filter.  Actually, the picture is a little more complicated, because the 'FIR filter specifications' input to the rational resample VI will specify the fraction of the new sample rate to pass, and this fraction is usually a little less that 0.5.  So for the above example, where the resampling factor is 50,000, the new Fs is 0.2 Hz.  Using default values for the 'FIR filter specifications' control, the actual bandwidth of the new signal would be 0.2*0.4536=0.09072Hz instead of 0.1Hz.

Even better would be to change the original HW sampling rate (with appropriate anti-aliasing filters), but that may not be an option.

If you find that you must use the original data rate, then you might try using the FIR Narrowband Filter.vi and FIR Narrowband Coefficients.vi.  These are specifically written to handle very low cutoff frequencies, very high cutoff frequencies (very close to F-Nyquist), or very narrow bandpass/stop cases, and be numerically robust.

For any filter, if you want it to settle using real data, then there is no substitute for waiting.  However, you can get the internal filter states to be much closer to their settled values by pre-filtering with data that is very similar to your real signal.  This can be tricky in the general case, but is much simpler for a DC signal.  Detect the DC level for the first part of your signal, and then generate a signal of this level to "settle" your filter.  Detecting the DC level could be done using the Basic Averaged DC-RMS.vi, or using the curve-fitting approach that Lynn suggested.  The fitting idea also has a benefit that you can get the confidence intervals of the fit, although that may not matter to you.

Hope this helps.

-Jim
Message 13 of 13
(846 Views)