# Digital filters in LabVIEW

I am very new in signal processing and using digital filters. I have to use a low-pass filter to analyze my data in LabVIEW and have a question about it. Any help and advice is appreciated.

I am trying to simplify my problem here:

Let’s say there is a digital sine wave (made by LabVIEW) with $V_{offset}=1 \ \mathrm{V}$, $V_{peak}=0.1 \ \mathrm{V}$, $f=10 \ \mathrm{kHz}$, $N=2000$ (number of samples), and sampling rate $f_s=200 \ \mathrm{kHz}$. Now, if I pass this signal through a low-pass filter with cutoff frequency $f_c=1 \ \mathrm{kHz}$, then the output should be a constant number equals the DC offset (here $1 \ \mathrm{V}$), is it true?

Another question is the concept of “cutoff freq” and “sampling freq” as the inputs of the filters in LabVIEW. Cutoff frequency as an input of a filter makes sense to me but what is that “sampling freq” ? Can anyone explain to me please? I am very confused. Is it the same rate at which the sine wave is created? For example in the attached code, what is the real cutoff frequency (with $f_l=200000$ and $f_l=1000$)?

I have attached the screenshots of the Front panel and Block diagram of my simple vi.

For your first question, generally, yes that is correct; if you filter a 10KHz sinewave that has a DC offset with a filter that has a cutoff frequency below the frequency of the sinewave, then the sinewave would be rejected. The amount of rejection specifically depends on the performance of the filter, but given you said you have a 1KHz cutoff frequency, the sinewave is significantly higher and therefore sufficiently rejected.

I see in your plot that the order of the filter is 5, which for a Butterworth filter as also shown would have a rejection of 20dB/decade *5 (where 5 is the order of your filter), or 100 dB per decade. Depending on other factors such as your digital dynamic range, this suggests that you would be able to filter your 10KHz sine wave up to 100 dB (10KHz is a decade above the cutoff frequency). The DC signal, which is below the cutoff frequency would pass through to the output, unless something in your system blocked DC or introduced other DC -offsets (which is possible). Also the filter itself can have gain or loss, so the actual DC output level if it did pass through can be modified by this gain or loss accordingly.

For your second question, sampling frequency is the sampling rate for the signals passing through this digital filter implementation. From the figure, you are using a sampling rate of 200KHz, and yes this would be the sampling rate of the sinewave that is created.

I hope this helped to clear up some of your questions.

• Quotation from you: “…something in your system blocked DC or introduced other DC -offsets (which is possible). Also the filter itself…”. Do you mean the fact that the filtered output is not constant is because of these issues? In other words: as we see the filtered signal becomes constant after ~600th point in the graph above (from 0th to ~600th we see huge variations), what is the reason for that? If the lowpass filter removes the AC part of the signal and passes the DC component, why don’t I have a clean constant 1 V instead of that variation at the beginning? – Simon Feb 15 '17 at 21:19
• The variations at the beginning are expected and called the "transient response" of the filter. Your plot is showing the step response. During a step transition at the input, the input is NOT DC, and requires a lot of frequency content to create such a step (case in point look at the Fourier transform or Fourier Series expansion for a step function). In simple terms, to change rapidly requires high frequencies. It is very easy to see and understand why you get such a transient response if you know the implementation structure for digital filters as well, but not sure that you are there yet. – Dan Boschen Feb 15 '17 at 21:25
• Further to clarify, since your signal settles at 1V, then you are clearly not blocking DC, nor does your filter have a scaling factor. Sorry to confuse you with that general comment. – Dan Boschen Feb 16 '17 at 2:16
• I am trying to understand what you say (and I appreciate that) but as you mentioned, it seems I am not at that stage yet. Can I ask if there is any way to make filter output cleaner and without variation? Based on what I have understood I think this variation at the beginning is kind of the “nature” of the filter (and unavoidable)(?) but I was wondering if there are some ways to make it better? For example I was told that IIR butterworth may reduce that variation (however, for I get the same result) – Simon Feb 16 '17 at 18:01
• The answer is of course yes, but we first have to define "better" in more quantified terms, as there often will be a trade space involved. Maybe you could describe your concern specifically with the transient response you see and what you are trying to do with the output of the filter (specifically). I am not sure there is going to be a simple answer that you would follow within this chat but we can try. Short of that, I recommend trying a "Bessel" filter if you have that option as it will have a smooth transient response, at the expense of not filtering out higher frequency noise as much. – Dan Boschen Feb 16 '17 at 18:05

The following is given in the spirit of Paul Newman's famous line from Butch Cassidy and the Sundance Kid:

there are no rules in a knife fight!

Based on the question and comments, I think the OP would simply like to ged rid of the sinewave, to the maximum extent feasible, and also minimize the transient response to the 1 V step. So @Dan Boschen's advice about the Bessel LPF is good, but there is still the transient response and the overshoot: for a 5th order Bessel LPF, it is 0.76%. Re-using some LPF filter data from a paper I published in 1986, I have taken some liberties with the OP's stated values and obtained some results that may be thought-provoking, if nothing else. So consider the following model:

In the model, the signal source is a 20 Hz sinewave, with 0.1 V amplitude and riding atop a 1 V DC offset. The Butterworth and Bessel LPFs are third order and have 1 Hz noise bandwidths. The RC LPF has a time constant that is given by the output of a linear ramp: the starting value is 4 ms and the end value, reached after 0.5 s, is 0.25 s. So the RC LPF has a small time constant at the beginning, to quickly deal with the step transient, and then the noise bandwidth (which equals 1/4RC) is 1 Hz for the last 75% of the simulation. To further reduce the sinewave ripple, the RC LPF is followed by a simple running integrator that averages over one sinewave period, i.e., 50 ms, in this model. So it does a 50 point running average.

The next figure compares the three filters:

The traces are color-coded, as shown in the figure. Clearly the time-variant RC LPF did OK. The next figure is an expanded scale version, with only the Bessel and time-variant RC LPF responses:

I have not played around with the ramp values or tried a non-linear ramp, so I have no clue what might happen. But I think there is a point to me made: the more you know about the specifics of a given problem, and the more clearly you understand what you actually want to know or accomplish, the more opportunities you have in regard to solving the problem. By the way, the third order Bessel LPF has 0.75% overshoot, almost the same as the 5th order filter.

So now modify the first figure by deleting the RC LPF and ramp and clipper, so the input goes directly to the running integrator. The results are shown in the next two figures:

Of course, this will not work properly if the sinewave frequency is not constant. Anyway, this was all just intended to point out that sometimes it may be useful to think outside the box a bit.