LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

File Problem

I want to read two .wav files in LabVIEW and process each of them.
In fact one acts as a signal and the other noise in an algorithm.

I can read an individual file but when I read two - one after the other
(using
the 'film strip' sequence thing) the first array seems to go to zero! Is

this the right method? I have two separate sequences one to the left of
the other. Do I need two events in one sequence or a local event?

Tom
0 Kudos
Message 1 of 7
(3,331 Views)
> I want to read two .wav files in LabVIEW and process each of them.
> In fact one acts as a signal and the other noise in an algorithm.
>
> I can read an individual file but when I read two - one after the other
> (using
> the 'film strip' sequence thing) the first array seems to go to zero! Is
>
> this the right method? I have two separate sequences one to the left of
> the other. Do I need two events in one sequence or a local event?
>

To read two files, you will either need two uses of the node that reads
the file, or you will need to use a loop. Probably the easiest way to
start is to select the code that reads the first file, copy and paste it
to have another block of code that reads the second file. This assumes
that there is very little code. If
the code to read the file is complicated,
then you can make a subVI from it and instead, so that what gets copied
are the calls to the subVI. Anyway, this will result in two arrays and
I believe you are off to the races.

If you want to do this with a loop, such as when you have 20 files to read,
or an undetermined number of files, this is probably best written by placing
the copied code in a loop. Then modify it so that the values that change,
such as the path/name of the file are input as an array of values. Each
iteration of the loop will index a path and any other relevant inputs, read
the file, then go to the next. You will also want to collect the info such
as the file data and the Error Status. You will want to do most of these
by autoindexing or building a cluster that you autoindex into an array
of ...
Some outputs such as error status are probably better handled by using a
shift register to feed the result to the next iteration.

Greg McKaskle
0 Kudos
Message 2 of 7
(3,331 Views)
Thanks Greg

I already have a copy of the code each within a sequence - the trouble is
that the data vanishes from the first array? Also how can you have a loop
and a read file within it as there would only be one array which would
be overwritten at each loop count?

Tom


Greg McKaskle wrote:

> > I want to read two .wav files in LabVIEW and process each of them.
> > In fact one acts as a signal and the other noise in an algorithm.
> >
> > I can read an individual file but when I read two - one after the other
> > (using
> > the 'film strip' sequence thing) the first array seems to go to zero! Is
> >
> > this the right method? I have two separate sequences one to the left of
> > the other. Do I need two events in one sequence or a local event?
> >
>
> To read two files, you will either need two uses of the node that reads
> the file, or you will need to use a loop. Probably the easiest way to
> start is to select the code that reads the first file, copy and paste it
> to have another block of code that reads the second file. This assumes
> that there is very little code. If the code to read the file is complicated,
> then you can make a subVI from it and instead, so that what gets copied
> are the calls to the subVI. Anyway, this will result in two arrays and
> I believe you are off to the races.
>
> If you want to do this with a loop, such as when you have 20 files to read,
> or an undetermined number of files, this is probably best written by placing
> the copied code in a loop. Then modify it so that the values that change,
> such as the path/name of the file are input as an array of values. Each
> iteration of the loop will index a path and any other relevant inputs, read
> the file, then go to the next. You will also want to collect the info such
> as the file data and the Error Status. You will want to do most of these
> by autoindexing or building a cluster that you autoindex into an array
> of ...
> Some outputs such as error status are probably better handled by using a
> shift register to feed the result to the next iteration.
>
> Greg McKaskle
0 Kudos
Message 3 of 7
(3,331 Views)
> I already have a copy of the code each within a sequence - the trouble is
> that the data vanishes from the first array? Also how can you have a loop
> and a read file within it as there would only be one array which would
> be overwritten at each loop count?
>

Perhaps you are talking about the data disappearing from the array control
on the front panel because each sequence is writing to it using a local
variable? In LV you do not need to write the data to a control in order
to store it somewhere. If you want two displays, then duplicate the displays.
If you want to append the arrays, then use a Build Array node.

Let's say that you want to plot the two arrays and plot the difference
between them. Outside of either sequence, drop down the Build Cluster
Array node. It is in the function palette in Cluster in the middle row.
Grow it to have three inputs. Wire the array wires from inside the sequence
to the terminals of the Build Cluster Array node. Also drop down a
Subtraction node, branch the array wires and send the array to the termianls
of the Subtraction. Wire the output of the Subtraction to the final Build
Cluster Array node. The Build Cluster Array node is collecting the data
into a three element array where each element contains the data on the
wire wrapped in a cluster. Finally, you need a graph on the front panel
and you wire the output of the Build Cluster Array to the graph. The
graph should update to the new type, and when run, it will show you three
plots.

You might want to look at a couple examples such as Examples/apps/freqresp.llb/
frequency response.vi. This builds up a couple arrays using a loop, bundles
them to plot one against the other, branches one of the arrays to
perform and display another value.

The second question has a very similar answer. It isn't he update of the
controls that is important to keep the data. Rather, you need to either
collect the data using an auto-indexing tunnel. You do this simply by
wiring across the for loop boundary. The tunnel will build an array, or
a higher dimensional array and collect the data from each loop iteration.
The other way to do this is to collect the data yourself and use a shift
register to feed the wire's data to the next iteration of the loop.

Greg McKaskle
0 Kudos
Message 4 of 7
(3,331 Views)
Thanks again for a detailed reply but I cannot find an example which does
what I am trying to do. I can read a file ok and process it. I do this
by having a sequence outside the main while loop and have another sequence around
the while loop. This way it reads the file first and then passes
the array to the processing loop. However I need to have two arrays read
from file and so I use two sequences. It reads the first and then the second
and passes the data to a third sequence where the while loop
is within but the data on the first array is lost!
The file is not read within a while loop or any kind of loop
but a sequence.I cannot auto index it therefore but I could send it to the main
while loop into a shift register - is this what you mean?

regards

Tom


Greg McKaskle wrote:

> > I already have a copy of the code each within a sequence - the trouble is
> > that the data vanishes from the first array? Also how can you have a loop
> > and a read file within it as there would only be one array which would
> > be overwritten at each loop count?
> >
>
> Perhaps you are talking about the data disappearing from the array control
> on the front panel because each sequence is writing to it using a local
> variable? In LV you do not need to write the data to a control in order
> to store it somewhere. If you want two displays, then duplicate the displays.
> If you want to append the arrays, then use a Build Array node.
>
> Let's say that you want to plot the two arrays and plot the difference
> between them. Outside of either sequence, drop down the Build Cluster
> Array node. It is in the function palette in Cluster in the middle row.
> Grow it to have three inputs. Wire the array wires from inside the sequence
> to the terminals of the Build Cluster Array node. Also drop down a
> Subtraction node, branch the array wires and send the array to the termianls
> of the Subtraction. Wire the output of the Subtraction to the final Build
> Cluster Array node. The Build Cluster Array node is collecting the data
> into a three element array where each element contains the data on the
> wire wrapped in a cluster. Finally, you need a graph on the front panel
> and you wire the output of the Build Cluster Array to the graph. The
> graph should update to the new type, and when run, it will show you three
> plots.
>
> You might want to look at a couple examples such as Examples/apps/freqresp.llb/
> frequency response.vi. This builds up a couple arrays using a loop, bundles
> them to plot one against the other, branches one of the arrays to
> perform and display another value.
>
> The second question has a very similar answer. It isn't he update of the
> controls that is important to keep the data. Rather, you need to either
> collect the data using an auto-indexing tunnel. You do this simply by
> wiring across the for loop boundary. The tunnel will build an array, or
> a higher dimensional array and collect the data from each loop iteration.
> The other way to do this is to collect the data yourself and use a shift
> register to feed the wire's data to the next iteration of the loop.
>
> Greg McKaskle
0 Kudos
Message 5 of 7
(3,331 Views)
> Thanks again for a detailed reply but I cannot find an example which does
> what I am trying to do. I can read a file ok and process it. I do this
> by having a sequence outside the main while loop and have another sequence around
> the while loop. This way it reads the file first and then passes
> the array to the processing loop. However I need to have two arrays read
> from file and so I use two sequences. It reads the first and then the second
> and passes the data to a third sequence where the while loop
> is within but the data on the first array is lost!
> The file is not read within a while loop or any kind of loop
> but a sequence.I cannot auto index it therefore but I could send it to the main
> while loop into a
shift register - is this what you mean?
>

Sorry if my detailed replies aren't being more helpful, but
it is difficult to guess what your diagram is doing without
seeing it. How many wires array wires are entering your
while loop? There should be two of them, each coming from
a different block of code for reading the file.

I doubt that the sequence nodes are necessary, and they
often make it more difficult to read your code. A wire
can only be written to once. The data written the wire
will then be read by each and every reader from the wire.
You might want to probe each of the wires going into the
loop, also probe the wires coming out of your sequences.
You can then run your VI and see a little better what is
happening on your diagram. It will run slower, but you
may also want to turn on execution hilighting -- the light
bulb at the top.

You need two wires coming into your loop, each written by
the separate blocks of code doing file I/O. You can have,
but do not need sequenc
e structures -- the loop cannot begin
until the file I/O blocks have delivered data. You haven't
said whether you are using them or not, but for this simple
program, do not use any global or local variables -- only
wires.

Greg McKaskle
0 Kudos
Message 6 of 7
(3,331 Views)
Hi Greg

I got it working by using a register like you suggested.
Many thanks

Tom


Greg McKaskle wrote:

> > Thanks again for a detailed reply but I cannot find an example which does
> > what I am trying to do. I can read a file ok and process it. I do this
> > by having a sequence outside the main while loop and have another sequence around
> > the while loop. This way it reads the file first and then passes
> > the array to the processing loop. However I need to have two arrays read
> > from file and so I use two sequences. It reads the first and then the second
> > and passes the data to a third sequence where the while loop
> > is within but the data on the first array is lost!
> > The file is not read within a while loop or any kind of loop
> > but a sequence.I cannot auto index it therefore but I could send it to the main
> > while loop into a shift register - is this what you mean?
> >
>
> Sorry if my detailed replies aren't being more helpful, but
> it is difficult to guess what your diagram is doing without
> seeing it. How many wires array wires are entering your
> while loop? There should be two of them, each coming from
> a different block of code for reading the file.
>
> I doubt that the sequence nodes are necessary, and they
> often make it more difficult to read your code. A wire
> can only be written to once. The data written the wire
> will then be read by each and every reader from the wire.
> You might want to probe each of the wires going into the
> loop, also probe the wires coming out of your sequences.
> You can then run your VI and see a little better what is
> happening on your diagram. It will run slower, but you
> may also want to turn on execution hilighting -- the light
> bulb at the top.
>
> You need two wires coming into your loop, each written by
> the separate blocks of code doing file I/O. You can have,
> but do not need sequence structures -- the loop cannot begin
> until the file I/O blocks have delivered data. You haven't
> said whether you are using them or not, but for this simple
> program, do not use any global or local variables -- only
> wires.
>
> Greg McKaskle
0 Kudos
Message 7 of 7
(3,331 Views)