04-25-2021 10:54 AM
Hi, I've created a simple LabView program and now I want to be able to save the data from the 'Frequency' graph to a text file or alternatively an excel file. The problem is that I want it to save data from 2 channels simultaneusly, so that I have frequency on X axis and amplitude on Y axis. I can't figure out how to do it, as the 'write to measurement file' function writes just the sample numbers and their values. I also want to be able to save the whole data in one file, not in 50 sample parts. Can someone tell me what am I doing wrong, or if there's another way to do this?
04-25-2021 11:02 AM
As a first recommendation, generally it's easier to work with the DAQmx drivers than the DAQ Assistant and the Dynamic Data Type (blue wire).
The DDT can hide all sorts of behaviours...
Certainly it's possible to store multiple inputs together in one file - using CSV/TSV will be easier than an Excel-specific file (e.g. xlsx), and can still be opened in Excel.
If you move away from the Express VIs, the functions you're looking for are Create/Open File, Close File, and Write to Text File, probably along with Array to Spreadsheet String or Format into String.
You'd want to open a file before your loop, close it after, and write in each iteration if using the Format into String.
If using Array to Spreadsheet String, you might prefer to do all of the writes after the loop finishes (RAM allowing).
Then you could also look at "Write Delimited Spreadsheet.vi" or something, which handles the opening/closing for you.
04-25-2021 02:31 PM
Ok, so I did it like this and now i have trouble connecting the data with write to text file, also I want to add headers over the columns and write 500 lines of data. Anyone has an idea how to do this?
04-26-2021 02:17 AM
What do you want to put in the Frequency columns? You're currently getting a spectrum from the Express VI, and that has two scalar values and an array of amplitudes - "f0", "df", and "magnitude" (the array).
To write a file in the way you describe, you need to get a scalar value for "frequency". How will you calculate this?
You might prefer looking at other methods to find the dominant frequency given a waveform - try the Waveform Measurements subpalette of the Signal Processing palette.
04-26-2021 01:01 PM
I did it like this, but I'm not sure if it's ok. There are some random numbers in the saved file and I don't know what they mean. I also can't get data from 2 simulated sines simultaneusly, do you have an idea how to this?
04-26-2021 01:33 PM - edited 04-26-2021 01:39 PM
Hi marcin,
@Marcin_zxc wrote:
There are some random numbers in the saved file and I don't know what they mean.
There are no "random" numbers, only your spectrum data.
Btw. you forgot to include a delimiter char between those two "columns" in your text file…
(By using only one FormatIntoString functions instead of two it would be easier to avoid that error!)
@Marcin_zxc wrote:
I also can't get data from 2 simulated sines simultaneusly, do you have an idea how to this?
Right now you only save the data of one waveform to your file. When you want to save the data of both waveforms you need to handle both!
Somewhat cleaned up version of your VI:
(You might transpose the array before converting to spreadsheet string…)
04-27-2021 02:58 PM
I've taken into account your tips, but I still have a problem with saving, specifically of the saved samples under the name frequency. I want the data there to be every 1 Hz, not 10 like it's currently being saved. Do you know how to do this?
04-28-2021 01:18 AM
Hi Marcin,
@Marcin_zxc wrote:
I want the data there to be every 1 Hz, not 10 like it's currently being saved. Do you know how to do this?
I cannot open your VI because I'm limited to LV2017 right now, so just guessing:
When you save the data as shown in my snippet then "df" sets the steps of the frequency values. When you need lower df values then you need to change the FFT parameters…
04-28-2021 03:45 AM
As GerdW already said, the df value is calculated based on the FFT parameters, which come in this case straight from the sampling parameters (windowing can change this).
If you want a lower df, you need a longer time series when you perform the FFT. You could most easily achieve this by increasing the number of samples from your "acquisition", but you might more generally consider accumulating multiple iterations of acquisition and then performing an FFT on the combination of them (to keep the loop responsive).
Attached as a snippet is a somewhat tidied version of your code for possible reference.
I'd still be tempted from here to adjust some behaviours (ordering of the outputs for example, probably some of the data structures, I attempted to remain close to the originals here) but I don't think I changed any behaviours (although the settings for the express VI might be adjusted on the bottom one, I played with that a little and it might be included in the snippet).
04-28-2021 04:26 PM
Thank you very much for all your help! One last thing - is there a way to make it so that the csv file is edited instead of creating a new one each time, because I want to do a few things in excel and that way I wouldn't have to type the same commands every time? If that's too hard to do then at least could the 2 files be merged into 1 in the labview application, so that I would have frequency in one collumn and next to it the amplitudes of the first and second signal?