06-27-2010 12:41 PM
Hi everyone,
I am new in Labview and I just started learning. There is one simple question that I don't know how to solve and I hope I can find some help here.
I get a 20Hz ramp signal from a function generator. A-D board and BNC cable are used for communication between the computer and function generator. DAQ assistant is used to send signal to Write so that the data is recorded in file. A while loop keeps the code continuously run and so is the data continuously recorded. My question is that how can I get the data which is just on one single period from the ramp signal. Basicly, I need the new data can overwrite on the old data so that the data inside the file only show the latest period. Can anyone help me find the solution? I await your bright idea with warm regards.
Best,
--
Weiye
06-28-2010 03:10 PM
Hi Weiye,
What hardware are you using? When you say you get a 20Hz ramp signal from a function generator, do you mean you are outputting that signal from your DAQ device or are you reading in that signal to your DAQ device? If you want a single period, you are going to have to look at your sampling rate and determine how many points you need in your file.
For instance, a 20 Hz ramp signal sampled at 200 Hz means that in one period of that signal, you will have 10 points. So, when you set up your read and record, you will do this in 10 sample increments so that you will always get exactly one period per read. This can be done by setting Sampling Rate = 200 Hz, Samples to Read = 10. Of course, these settings are dependant on your hardware, so it would be important to find that out.
Also, when you write data to file, just make sure you specify the same file path for all writes, and you do not specify Append to File as true. In this way, you will always overwrite the file with the current iteration of your while loop.
06-28-2010 05:55 PM
Thank you for your reply. I read signal from function generator and record the data using labview code. I need 500 points per period. So I already specified 10kHz as Sampling Rate and 500 as Sample to Read. I run it in a for loop and set iteration is 100. Where should I put Write to Measurement File then? Inside the loop or outside? When I put it inside the loop, after I started write to file, it gave me some backup files to store the data. When I put it outside, it gave me one file in which contains many columns of data. Each column gave one period of data. How can I overwrite old data with new data on new period? Where can I specify Append to File that you mentioned? Is it in the Properties of Write to Measurement File?
Another problem I have is that when I used a while loop rather than a for loop. It cannot write to file. Same thing happened when I choose iteration over 200. Can you explain this to me? Is it something with the hardware? The function generator I used is Stanford Research systems model DS345, 30MHz synthesized function generator. Is it because the rate I chose too high?
Thanks,
--
Weiye
06-28-2010 06:10 PM
@Weiye wrote:
How can I overwrite old data with new data on new period? Where can I specify Append to File that you mentioned? Is it in the Properties of Write to Measurement File?
If you double click on the Write Measurement File, you will get a configuration screen. On that screen you can choose to append or overwrite the file.
@Weiye wrote:
Another problem I have is that when I used a while loop rather than a for loop. It cannot write to file.
It should not matter if it is a For Loop or a While Loop. Please post your code, or an example of what you are doing.
06-29-2010 09:41 AM
My code is attached.
In the code, DAQ assistant read two signals, one is the 20Hz ramp signal from the function generator , another is the voltage signal from our experimental setup which has the same period as the ramp signal. This signal is being averaged by a for loop and sent to Write to measurement File. The ramp signal is sent directly to Write to measurement File.
06-29-2010 11:00 AM
The VI looks functional. What is your problem? Is it still to do with Write to Measurement File? Have you set it up according to my recommedations in my previous post?
06-29-2010 12:15 PM
So, does the for loop for average also function? I am a beginner and this is my first code.. I tried both Overwrite to file and Append to file, but the file still shows multiple columns. Do I need to use array to store the data which comes out of the for loop? Then, somehow, I make a command to write the latest period data?
Data file is attached. Can you look at it?
Thanks,
--
Weiye
06-29-2010 12:30 PM
What comes out of the loop is an array. Every time the loop iterates, the array grows by one row. So when you write to the file, you will have 200 rows of data. The loop itself does not do any averaging. You have to add code to average. Since you are working with waveforms, each waveform will have many data points. So the output of the loop is a 1D array of waveforms, which is similar to a 2D array of numbers. Your data file is an lvm file. You should convert to a spreadsheet to see it better. I would need to create a vi just to read the LVM file. But I'm sure your data file is like a 2D array.
I'm not sure exactly what you want to write to your file. Sounds like you only want to write data from the last loop iteration. If so, then just disable indexing on the loop border. Right click on the terminal and select Disabled Indexing. Then only the last iteration data will come out and it will be a waveform, which is like a 1D array.
06-29-2010 12:54 PM
What code do I need to add to that inner for loop to do averaging? What I want is to average the waveform using the inner for loop. Then I need to write the averaged waveform to file.
--Weiye
06-29-2010 01:05 PM - edited 06-29-2010 01:09 PM
Add all data points and divide by the number of data points. This is simple arithmetic. To do this, extract the Y data out of the waveform. The output is an array. Use the Add Array Elements function and the Array size function. Divide the sum by the size. No loop needed.
By average waveform, do you mean the average of the first data point, then the second data point, etc? You could extract the Y data from the waveform and wire it to the loop border with indexing enabled. After the loop, transpose the 2D array to make rows into columns. Now each row has data from the same position in the waveform. Send this to a loop with indexing on. Inside the loop, add the array elements, get the size (should be 200 because you are running the big loop 200 times), and divide sum by size. Wire the output to the loop border with indexing on. Your final output will be an average of data points. You can write this array directly to a file using Wrtie To Spreadsheet File.