LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Change write to file sampling rate

Evening All,

 

Playing around with the write to measurement file.

 

I am reading from a thermocouple that is displaying on a chart. I want to log the data but not all the data. I have seen this topic in a few places but it seems the solutions do not fit my needs...

I have tried to use the "sample compression" which sometimes works, but then sometimes does not, it fills the file with many entries with the same time stamp...

perhaps there is a better solution for simply setting the intervals to record data...?

 

the Vi. is attached.

 

advise appreciated

 

Toby

0 Kudos
Message 1 of 7
(3,350 Views)

Am I correct that you have never taken a class in LabVIEW?  Have never learned about data acquisition and sampling?  Here are some problems:

  • Try to avoid Express VIs -- they hide too many details and usually prevent you from doing all but the simplest, most "vanilla", aspect of the task.
  • You are sampling one sample at a time in your loop.  The "clock" you are using is the equivalent of LabVIEW's "Wait (ms)", which uses the PC's (relatively imprecise) clock.
  • You compound the problem with Express VIs by using the Dynamic Data Wire, whose reason-for-being I've never understood.  Waveforms are much better (in my opinion), and certainly clearer and easier to understand.
  • Look at the input to Time Delay -- it is labeled "Samples per S" (which I assume means "Samples per second".  The unit of Samples/sec is 1/time, so 0.25 Samples/sec means one sample every 4 seconds.  I have no idea whether you want to sample at 4 Hz (and so want to "wait" for 0.25 sec, as you code exists), or whether you want to sample at 0.25 Hz (as the name of your variable appears to state) and forgot to take the reciprocal to turn this into a wait of 4 seconds.

With so much going wrong at the beginning, it hardly makes sense to try to understand why you are (again!) using Express VIs that you don't understand, and what you are really trying to accomplish.  Sorry to be so negative.  The Good News is if you hurry, you can still take the LabVIEW Core 1 and Core 2 classes for free.

 

Bob Schor

0 Kudos
Message 2 of 7
(3,341 Views)

Hi Bob,

 

Thanks for the fast reply.

 

Yes, you are correct, I am new and learning and playing with features.

I have started core 1 but... not finished it yet.

 

What I am currently looking for is (as you put it) the most "vanilla" way to log the data at a rate that I want.

 

I will keep looking around and see if I can find something and see if I can correct some of the failings as you suggest.

 

cheers

 

Toby.

0 Kudos
Message 3 of 7
(3,333 Views)

As a scientist, I go by the mantra "Data are sacred".  If I am going to collect data at 0.25 Hz (one point every 4 seconds), or at 4 Hz, or at 1 kHz, I'm going to save all of those data (though I might choose not to display them all, as watching data zip by at 1 kHz can make your eyeballs dance around in funny patterns).

 

Can you explain a little better what you want to do?  This should be a sentence like "I want to acquire such-and-such data at a rate of XX points/second for YY seconds (or points, up to you) and save it all to disk for later analysis".  [You'll notice Bob's Rule -- If It's Worth Acquiring, It's Worth Saving].  Feel free to add additional processing or displaying as you wish.  Sometimes you need to understand (or al least be clear) on the "What" before tackling the "How".  Case in point -- I can't figure out "what" you are trying to do ...

 

Bob Schor

 

 

0 Kudos
Message 4 of 7
(3,305 Views)

Good Morning Bob,

 

indeed, Data are sacred! 

 

on my Vi I have a control to adjust the time delay. I have changed the label so its function is more clear. I am using the time delay as a control for the sampling rate. as a write this I have set it to 10 seconds between samples.

 

ok, so, scope...

I have to build a vi. that acquires from a thermocouple. I have the thermocouple connected to a breadboard with an op-amp, this is then connected to a USB-6000 which is connected to my laptop.

I have to build the vi. using the express and mathematical elements of LabVIEW.

 

the system is an environmental monitoring system, monitoring temperature for an AC system so temperature does not change fast.

 

The scope is to present historical data in a graph, present historical data, and have a logging option.

once I have completed the vi. it will be used to create a system of 100 sensors through a multiplexor that can mimic the vi.

 

It makes perfect sense to me that the logging rate should match the sampling rate!! but! if the user wants to adjust the sampling rate on the GUI to a higher level I don't want the log filling up with useless information ( I want to sample at 1 time every 10 seconds as standard, so this is what I want to log.) 

so, I am looking for a way that the user can adjust the sampling rate (time delay between samples) but not effect the logging rate which is set to 1 sample every 10 seconds.

 

I really hope that this clears things up a little!!!

 

Toby

0 Kudos
Message 5 of 7
(3,252 Views)

Sure.  Let's take a concrete example, and say that because you are measuring "environmental variables", you expect to save one sample every 10 seconds (or a "sampling rate" of 0.1 Hz).  Let's furthermore assume that you do not want to monitor/graph the data, but simply save the data to a disk file for later analysis.  Let's also say that you are monitoring K (maybe 10-40) sensors and want to collect N samples at a time (maybe 1000, a nice round number).  [Note that our sampling rate is unusually slow -- a more common setting is acquiring 1000 samples at 1 KHz, so the samples come in once a second].

 

So you set up your DAQmx functions to sample 1000 samples at a rate of 0.1 (Hz).  You use a convenient method (straight DAQmx function calls, a Task defined in MAX, a Task defined in your Project) to define the Task, the DAQmx Device, and the DAQmx Channels, set the Timing, and now you are ready to acquire data.

 

In a While Loop, you do a DAQmx Read of 1000 points, N Channels N Samples, getting the output as an Array of Waveforms.  Why Waveforms?  That's the "natural" LabVIEW data structure for sampled data, which includes the sampling interval (dt, here 10) as part of the saved information.  You know that it's going to take 100 seconds for the DAQmx Read to produce your data (you don't need a Wait function here -- the DAQmx Read is your "clock", and it is much more accurate and precise than the Windows clock powering the LabVIEW Wait function).  When the Read finishes, it hands you its Array of Waveforms, and you have 99.995 seconds to write these data to a file (there is a Waveform Write to File function you can find on the Waveform Palette).

 

OK, but now you decide you want to "see the variables update at 10 Hz", but still save the data at 0.1 Hz.  How do you do that?  

 

First step is to "collect the data".  That's fairly simple -- just change the sampling rate from 0.1 to 10 Hz, equivalent to changing the sampling interval from 10 to 0.1 sec.  Keep everything else the same.  Now your While Loop will run 100 times faster, you'll generate 1000 points in 0.1 sec, and will need to write it in just under 0.1 sec (so you are ready for the next batch to be read).  No problem, but now you are saving 100 times the data that you need.  How to fix this?

 

There are several things you can do.

  1. Just save the extra data.  Disk space is (relatively) cheap, and you might want to "save what you saw" (such as "Where did that data Spike come from?  I hope it's on the Saved Data ...")
  2. Take your 1000 points and save 1-in-100 of the points, "as though" you were sampling at 0.1 Hz.
  3. Take your 1000 points and average in groups of 100, a kind of "low-pass filter" of your data.

If you save your data as Waveforms, doing methods 2 or 3 require that you not only change the Y (sample data) component of the Waveform (replacing an Array of 1000 with an Array of 10), but that you change dt to reflect the "computed" sampling rate (changing it from 0.1 to 10).

 

Does this make sense to you?

 

Bob Schor

0 Kudos
Message 6 of 7
(3,238 Views)

Bob, Hello.

 

Everything you have written makes perfect sense. 

I will try to implement the philosophy you are suggesting.

 

one thing for sure. I will steer clear of the express tools and learn more about primitives in the next project!!!

 

Toby

0 Kudos
Message 7 of 7
(3,237 Views)