From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Signal Conditioning

cancel
Showing results for 
Search instead for 
Did you mean: 

Can´t implement a lowpass filter properly

Solved!
Go to solution

Hello Everybody,

 

First of all, sorry for my bad english!

 

Before posting this question, I´ve tried to search for answers in the forum and couldn´t find a helpful one for my case.

 

I´m new to LabView and I´m testing it for signal analysis.  I´m using an Agilent signal generator and a NI USB 4431 to acquire the signal.

 

Ok, here´s my problem. I can´t use a Butterworth filter (nor a Chebyshev or any type) to create a lowpass filter. I don´t know if I didn´t understand it´s parameters properly or if I´m setting something wrong. When I use the filter ExpressVI, I get the result I want, but when I use the Butterworth function, it doesn´t work.

 

Can someone please help me?

 

I´m sending the project I´ve designed, so you guys can see what I´ve done.

Here some explanations: The graph labeled "puro" is the pure signal I´m generating.

                                     The graph labeled "Spec. puro" is the power spectrum of the current signal

 

                                     The graph "filtrado" is the signal after passing through a lowpass in the express VI (which is working fine) and the graph "Spec filtrado" is it´s power spectrum.

 

                                    In the upper part of the loop is the Butterworth filter function. I´ve wired the pure data signal to its input and was expecting an output just as the express VI creates, but it is not even ploting anything at the graph.

 

 

lowpass.png

0 Kudos
Message 1 of 9
(19,744 Views)

Your English is much better than any attempt I might make in your native language!

 

We cannot trouble shoot an image, particularly with the Express VIs where all the important information is hidden after the configuration dialog window closes. The best way to get help with something like this is to run your VI. When you have typical data shown on the puro graph, stop the VI and go to the Edit menu and select Make Current Value Default. Save the VI and post it. There is a Choose File button below the word Attachments (in English versions of the web site) just below the text box for your message. Use that to attach the VI to your post.

 

It appears that you have the sampling frequency wired to the filter VI. Omitting that is a common error, one which you did not make.

 

What is the frequency of the signal from your signal generator?

 

Lynn

0 Kudos
Message 2 of 9
(19,723 Views)

Hello John! Thanks for the time spent!

 

Well, I did what you told and I´m going to attach my VI here. But first I´d like to make some considerations:

 

- I don´t think you´re able to run this VI since I´m using an specific hardware to acquire the signal. I´ve tested on another computer and the VI opens normally, shows the default values I´ve selected, but when I try to run it, it returns an error saying that the device was not found (which is pretty obvious). But hopefully you will know how to analyse it better than me. Smiley Happy

 

- I´ve chosen a sampling frequency with the same values for both the hardware and the filter VI (100kHz);

 

- I´ve generated a signal of 5kHz and set it as the default value;

 

- The cutoff frequency is 5kHz. The express VI returns the expected behavior (cutting off about 25% of the signal, as you can see in the graphs). On the other hand, the filter VI do not respond as I expected. I wired a waveform chart and a waveform graph to it´s output. The chart shows a signal very similar (I would say exactly equal) to the original signal, no filtering is happening. The graph shows no signal at all and I don´t know why!!! I put a test probe in this wiring and it shows that is receving the values, but for some reason it isnt plotting anything.

 

 - I´m attaching the VI and also sending a printscreen from the front panel, sou you can see the graphs as I can.

 

Thanks!

 

Henrique

 

frontpanel.png

0 Kudos
Message 3 of 9
(19,714 Views)
Solution
Accepted by topic author henriquegpo

The FIR Windowed Filter VI is generating error -20023, which is a Nyquist violation. Because this VI only returns an error code and not the standard error cluster, you need to explicitly wire an indicator or error handling to the error output.

 

The cause is that you have the cutoff frequency set to zero.  NI uses somewhat confusing nomenclature for the frequency inputs of filter VIs. Here is what the Detailed Help says:


high cutoff freq: fh is the high cutoff frequency in Hz. The default is 0.45 Hz. The VI ignores this parameter when filter type is 0 (Lowpass) or 1 (Highpass). When filter type is 2 (Bandpass) or 3 (Bandstop), high cutoff freq: fh must be greater than low cutoff freq: fl and observe theNyquist criterion.


So, for both highpass and lowpass filters the cutoff frequency is the value wired to low cutoff freq: fl. I make this mistake regularly. When I get strange results, I read the help and fix it. As soon as I wired 5000 to fl, the output looks like this:

 

filters.png

 

The differences in amplitude and initial transient are likely due to the different filter specifications.

 

The way I run this is to convert the Pure indicator to a control, make current value default, then put all the DAQmx VIs in Diagram Disable structures. I place the Pure control (or a copy of it) in an enabled case of the Diagram Disable structure which has the DAQmx Read. Since you only have one channel of data I added Index Array to get a single waveform from the array. Then all the signal analysis code works.

 

indicator to control.png

 

Lynn

0 Kudos
Message 4 of 9
(19,708 Views)

Lynn,

 

Thanks for the help! Now I understood what I was doing wrong. I´ve made a big mess with the parameters, didn´t get the difference between fl and fh. But now I understand!

 

And what you did for running the VI without the hardware was a masterpiece! I wouldnt think in something like that!

 

But there is still something going wrong with my code. I wired 5000 to fl and left the fh input without value (and tried with zero too), but the graph shows a straight line in the zero mark. It doesn´t matter the frequency I put on the signal generator, the output of the filter goes like that:

 

Sem título.png

 

What am I doing wrong?

 

 

Here´s the code with specifications for the filter:

Sem título2.png

 

Thanks in advance!

 

Henrique

0 Kudos
Message 5 of 9
(19,705 Views)

Henrique,

 

The input for the FIR Windowed Filter.vi is a simple array of Double precision numerics. You are wiring an array of waveforms. Note that your pure signal wire is thicker than mine. In my example I used Index Array to get a singel waveform. When I take that out I get something similar to your results.  Internally the filter VI uses a Call Library Function Node. It may be that the code behind that does not know how to interpret the array of waveforms.

 

Lynn

0 Kudos
Message 6 of 9
(19,697 Views)

Lynn,

 

I didn´t understand why the array of waveforms was not a valid input for the filter, but I perfeclty got it now! 

Thank you so much for your help and the time you spent explaining this rookie mistake Smiley Happy

Undoubtly I got more knowledge in LabView after this discussion!

 

Thanks a lot!

 

Henrique

 

0 Kudos
Message 7 of 9
(19,692 Views)

Henrique,

 

We like to help people learn how to use LabVIEW. I would not consider this a mistake as much as inexperience. You were trying to do all the right things. Some of the VIs, especially some which have been around for several years, are not very "user friendly." 

 

Most experienced LV programmers keep the Context Help window open all the time while writing programs. I do not hesitate to look at the Detailed Help links whenever I have any question about how something works.  The help files really contain a lot of good information. The search is not always the best and sometimes you need to dig a little to find the help you need, but once you find it, the information is useful.

 

Also, it is often helpful to write simple test VIs. For example it would only take a few minutes to  write a VI which creates an array of waveforms and feeds it to the filter VI to see what happens.

 

Lynn

0 Kudos
Message 8 of 9
(19,680 Views)

How can I implement lowpass filter via NIDAQmx python API on a channel?

0 Kudos
Message 9 of 9
(5,606 Views)