LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Measuring frequency from an analog signal and reducing noise

Solved!
Go to solution

Hello everyone.

 

I am reading from a flow rate sensor that outputs a square wave signal whose frequency has a linear relationship with the flow rate and ranges from 37 to 550 Hz. My hardware does not support reading the frequency, so I have to calculate it. What I ended up doing was reading the signal every 1 millisecond (1000 Hz), taking two samples and averaging them, and storing both the signal value and time at which it was read. Every 400 milliseconds, I loop through this data and find out how many cycles occurred and the time between the first and last cycle, divide number of cycles by that time.

 

Here's a graph of the signal.

When I do my calculations, I get a fluctuating value averaging out to 120 Hz with no flow through the sensor. Here is the graph of the measured frequency, each step is 400 milliseconds.
So I was wondering a few things. First, is this even a good way to to it? The second question is how to clean up the frequency.
 
I have a few theories as to why it's noisy. One, it's not shielded and might be picking up some frequency from another oscillating current, possibly a motor. Second, I might have software timing inaccuracies. I know it would be better to do this in hardware, but I don't have that capability. Third, my method of calculating the frequency is wrong or not accurate.
 
If anyone has any information, answers, or comments that could help me, that would be great. I'm using LabVIEW 8.6 Base. Thanks in advance!
0 Kudos
Message 1 of 13
(4,695 Views)
How are you doing your calculations? And how does the signal from the sensor look like then you do not have any flow?


Besides which, my opinion is that Express VIs Carthage must be destroyed deleted
(Sorry no Labview "brag list" so far)
0 Kudos
Message 2 of 13
(4,656 Views)

What you see is the quantization noise. So in your 400 ms there might be 67 or 68 and sometimes 66 peaks). That is o.k.

You can reduce the noise by longer integration time, but it makes your sensor less responsive to changes.

 

Felix 

0 Kudos
Message 3 of 13
(4,653 Views)
>When I do my calculations, I get a fluctuating value averaging out to 120 Hz with no flow through the sensor. Here is the graph of the measured frequency, each step is 400 milliseconds.
 
 That's sounds like hum. Your power line frequency is 60Hz? 
 
What DAQ hardware are you using? 
 
First: Getting a clean signal:  Use a (one side!) shielded cable. Do you have the spec of your sensor? Your signal vary between 3.8V to 5V. Looks like your sensor attachment could be improved.
<CRISTAL_BALL_MODE>
Adding a pull down resistor (10k from signal to Sig-GND) might help. (AT OWN RISK! Digg into your hardware specs)
</CRISTAL_BALL_MODE>
 
 Last resort hardware solution: add a smitt-trigger to reshape your pulses.
 
For a pulse rate of 550Hz your  samplerate of 1ms is to slow. Change it to 0.5ms or 2kHz  or even better to 4kHz. 
 
Now do a slope detection, count the slopes and decrement one, take the time between the fist and the last slope to calculate your count rate.
 
 
Message Edited by Henrik Volkers on 06-15-2009 01:13 PM
Message Edited by Henrik Volkers on 06-15-2009 01:15 PM
Greetings from Germany
Henrik

LV since v3.1

“ground” is a convenient fantasy

'˙˙˙˙uıɐƃɐ lɐıp puɐ °06 ǝuoɥd ɹnoʎ uɹnʇ ǝsɐǝld 'ʎɹɐuıƃɐɯı sı pǝlɐıp ǝʌɐɥ noʎ ɹǝqɯnu ǝɥʇ'


0 Kudos
Message 4 of 13
(4,650 Views)

Thanks for all the replies!

 

I'm not sure what the power line frequency is, I'll have to check. I'm using the SCXI-1000 with a NI SCXI-1100 module. I don't think the spec sheet I was given had the output voltage range, but I will have that and the cable checked out.

 

As for sampling faster then 1kHz, I'm not sure how to do that. I'm using a timed loop structure, the fastest I can loop is 1 millisecond. I did a little searching around, it appears you can use the hardware to do faster timing? I'll dig around some more, but if anyone knows how this is done that would be very helpful. 

 

Again, thanks for all the answers, they are very helpful! 

0 Kudos
Message 5 of 13
(4,634 Views)
Solution
Accepted by topic author lukepike

I never use software timed loops then performing DAQ operations as a thumb rule. It is to many negative issues connected to it. And as you mentioned you can not run a timed loop faster than 1Khz. You should go to the help menu in the toolbar, and then select find examples. Then you search for "continuous acq". It is best to leave all the timing details to the daq unit, and just pull data from the daq buffer then they are needed. I your case I will recommend a sample freq equal to 6KHz. That is more than 10 times your highest frequency. You can still update your data at 400msec intervals. Your signal also looks good. I can not much noise in your signal. So My guess is that your software is not optimal. You should not get 120Hz then there are no flow. If you post it we can take a look.     



Besides which, my opinion is that Express VIs Carthage must be destroyed deleted
(Sorry no Labview "brag list" so far)
0 Kudos
Message 6 of 13
(4,629 Views)

Thanks!

 

I took a look at the examples, I think the "Cont Acq&Graph Voltage-Int Clk" example is what I'm looking for. I didn't see my hardware in the requirements box, will it still work? (I don't have access to the hardware right now.)

 

Also, one last queston and I should be set. I still need to calculate the frequency of the signal, but I'm wondering if I'm doing it in the best way. I'm looping through the data and counting how many high-low-high's in the data using an enum to keep track of what state I'm in. I'll upload an example vi of what I'm doing, I just want to know if there is a better way to do it with LabVIEW Base.

 

Thanks so much for the replies, this is great information!

0 Kudos
Message 7 of 13
(4,619 Views)

I whipped up this quick and dirty. I do not think you get it more accurate. Take a look and see if you can use it.

Note! This user has only base version 😉 

Edit I think the example VI you referred to is the correct one. But I have no DAQ VIs on my current PC

Message Edited by Coq rouge on 06-15-2009 07:14 PM


Besides which, my opinion is that Express VIs Carthage must be destroyed deleted
(Sorry no Labview "brag list" so far)
0 Kudos
Message 8 of 13
(4,608 Views)
Cool! I'll have to look at it tomorrow, as I only have 8.5.1 here at home.
0 Kudos
Message 9 of 13
(4,601 Views)

Lukepipe,

now that we know your DAQ Hardware, tell us more about your sensor (manufactor,type ) and cabling (type of wire, lengh) and we might be able to help you getting a better signal.

If your posted signal wave comes from your sensor without any flow there shouldn't be any pulses to detect and all I see is a 4.4V DC with 1.2Vpp line noise (120Hz is typical for 2 way rectifier on a 60Hz System).

The typical outputs of flow sensors are reed contacts (bad because of bouncing contacts), open collector (hall sensor)  or pushpull (activ, sensor needs power supply) ...

 

Greetings from Germany
Henrik

LV since v3.1

“ground” is a convenient fantasy

'˙˙˙˙uıɐƃɐ lɐıp puɐ °06 ǝuoɥd ɹnoʎ uɹnʇ ǝsɐǝld 'ʎɹɐuıƃɐɯı sı pǝlɐıp ǝʌɐɥ noʎ ɹǝqɯnu ǝɥʇ'


0 Kudos
Message 10 of 13
(4,563 Views)