Discussion:
My AO triggers were delayed by about 1 ms out of every 1000 ms
(too old to reply)
Fuh
2008-07-09 22:10:10 UTC
Permalink
Dear Labview Experts,
 
I am an EEG person and am currently trying to build my own stimulation system using Labview.  I have a DAQcard 6062E and Labview 8.0, and I am new in Labview programming. My plan is to play a .wav file continuously through AO channel #0, and at the same time deliver triggers through AO channel #1.  I intertwined the outputs of the two AO channels so that the sound signals and the triggers will always be synchronized.  I do this because my DAQ 6062E card does not do hardware-timed triggering.  The sound signals were sent to a loud speaker, whereas the triggers were sent to a Neuroscan recording system.  The Neuroscan recording system will then be used to record EEGs from a human subject along with the triggers that were sent through my Labview program.
 
My problem is: My triggers recorded by the Neuroscan recording system were delayed by about 1 ms out of every 1000 ms.  I mean I have tested the Neuroscan recording system using their own stimulation system.  When the triggers were sent using Neuroscan's stimulation system, the triggers were correct and precise in time.  However, when the triggers were sent using my Labview program, the triggers were delayed by about 1 ms out of every 1000 ms.  I have also checked the output array of my two AO channels.  They contained exactly the same number of data points as it has in the wave file.  Is it possible that the delay is due to my lousy, immature Labview programming skills?  I mean, it is quite possible, but I simply do not know where the problem is.  If anyone would be generous enough to take a look of my Labview programming codes and to give me comments, I would greatly appreciate it.
 
Sincerely,
 
Fuh
 
P.S. My wave file is generated using MATLAB, at a sampling rate of 44,100 samples/second.  Because the ".wav" file extension is not a valid file extension for attachment on the NI Discussion Forum.  I have changed the file extension of my wave file into ".txt".  If anyone needs to use my wave file to test my Labview program, please be sure to change the file extension bact to ".wav" before using it. 


FSnoise_cos_10_100_dur2.txt:
http://forums.ni.com/attachments/ni/250/41436/1/FSnoise_cos_10_100_dur2.txt


Practice_DAQmx_AO_2chan_WAV_AOTrigger2.vi:
http://forums.ni.com/attachments/ni/250/41436/2/Practice_DAQmx_AO_2chan_WAV_AOTrigger2.vi


Read WAV with trigger2.vi:
http://forums.ni.com/attachments/ni/250/41436/3/Read WAV with trigger2.vi
Rob Purser
2008-07-10 13:10:10 UTC
Permalink
Hi Fuh, A google search for "matlab analog output" might help you with a possible solution.-Rob
Fuh
2008-07-10 15:10:17 UTC
Permalink
Hi Rob,
Thank you so much for your input.  I googled the "matlab analog output", but I did not use the "analog output" function in Matlab.  I used MATLAB simply to create amplitude-modulated white noise and save it in a wave file.  The wave file should be exactly the same as any "standardized" wave files.   
Also there is another point I probably didn't explain clear enough in my first posting.  When I said my trigger was delayed by about 1 ms out of every 1000 ms, I mean if I use my Labview program to read in a wave file that contains a 1000-ms sound signal (for example, amplitude-modulated white noise),  the intervals between adjacent triggers recorded in the Neuroscan recording system will be 1001 ms.  I mean, if the recording is set to collect 10,000 samples/second, the intervals between adjacent triggers will be 10,011 data points instead of 10,000 data points.  If the recording is set to 20,000 samples/second, the triggers will be evenly spaced by 20,022 data points, instead of 20,000 data points. 
On the other hand, if I use my Labview program to read in a 2000-ms-long wave file and the recording was set to 10,000 samples/second, the intervals between adjacent triggers will be 20,044 data points instead of 20,000 dtat points.  
I mean, the delay seems to be proportional to the lenght of the wave file.   That makes me think: (1) this might due to Labiview programming overhead (due to my immature Labview programming skills), or (2) this might also due to the fact that my Labview stimulation program and the Neuroscan recording system are not using the same clock.  Before I jump into the second conclusion, I would like to be sure that my Labview program is producing any delay, or not.
Hope this would make more sense to the readers.
Sincerely,
Fuh
Steve_B
2008-07-11 00:40:05 UTC
Permalink
Hi Fuh,
I am interested to find out a little more about the issue. Your programming looks to be ok. The data transfer from the to the card from the PC is done through DMA transfers, which means that the data is written to the card in chunks because the on board memery of the card cannot hold all of the data. Do you see a constant error of 1ms per 1 second or does the delay happen periodically at some other interval? Is the Neuroscan stimulation system independant of LabVIEW, the pc, and the DAQ card? What rate is the Neuroscan recording system acquiring data?
Fuh
2008-07-11 02:40:06 UTC
Permalink
Hi Steve,
Thanks a lot for looking at my Labview program. 
I let my Labview program run for a little while and recorded the continuous EEG data (along with the triggers) from the Neuroscan recording system.  I then analyze the recorded data and calculate the data points between adjacent triggers.  It is a constant delay of 1 ms out of every 1000 ms.  I also noted that the delay is not at the beginning, at the end, or at any specific location of the data points.  Instead, the delay is evenly distributed throughout the entire recording data points.  I have done a little experiment.  I modified my Labview stimulation program and add additional triggers at the middle and at the end of the AO channel #1 output.  The delay is found to be evenly distributed throughout the entire recording data points.  That is, for some reason, the 1000 ms stimulation was evenly distributed over a recording period of 1001 ms.  That is, something wrong was happening and delaying the presentation of each data output (either at the stimulation, recording, or somewhere in between).  I simply cannot figure out where...
The Neuroscan stimulation system is completely independent of Labview.  Actually the entire Neuroscan system (both the stimulation and recording systems) is independent of Labview.  Neuroscan is written in Visual C.  Their stimulation system uses a Keithley I/O card (Model KPCI-PIO24 24-ch, PCI Board w/ parallel Digital I/O) running on a DELL computer using Windows XP.  
Signal flow of the Neuroscan recording system can be described as follow.  EEG signals --> headstage preamplifier --> signal box --> USB cable to a DELL computer.   The triggers should be delivered to a trigger port on the back of the signal box (either using Neuroscan stimulation system or through a TTL cable using my Labview program).  When I use my Labview program as the stimulation system, the Neuroscan stimulation system is turned off and completely disconnected from the Neuroscan recording system.  The Neuroscan recording system can record EEGs at different recording rates, from about 500 samples/second up to 20,000 samples/second.  The recording sampling rate I used was 10,000 samples/second.  I have also tried the recording sampling rate of 20,000 samples/second.  Same thing happened -- 1 ms delay out of every 1000 ms, and the delay is evenly distributed throughout the entire recording process. 
Specifications of the Neuroscan stimulation computer is:NetData (miniature)            Location: W141A (Lab office)            CPU: Pentium (R) 4 CPU 3.00 GHz, 3.00 GHz            RAM: 2 GB           Hard Drive: 80 GB, 80 GB

Windows XP + Service Pack 2

 

Neuroscan STIM computer (DELL OPTIPLEX GX620)

            Location: W141 (AEP Lab)

            CPU: Pentium (R) D 2.80 GHz, 2.79 GHz

            RAM: 1 GB

Hard Drive: 150 GB

Windows XP + Service Pack 2
 
By the way, I computer I used for my DAQ6062E (a PCMCIA card) is an ACER laptop. 
Thanks a lot...
Sincerely,
Fuh
Fuh
2008-07-11 02:40:06 UTC
Permalink
Hi Steve,
Thanks a lot for looking at my Labview program. 
I let my Labview program run for a little while and recorded the continuous EEG data (along with the triggers) from the Neuroscan recording system.  I then analyze the recorded data and calculate the data points between adjacent triggers.  It is a constant delay of 1 ms out of every 1000 ms.  I also noted that the delay is not at the beginning, at the end, or at any specific location of the data points.  Instead, the delay is evenly distributed throughout the entire recording data points.  I have done a little experiment.  I modified my Labview stimulation program and add additional triggers at the middle and at the end of the AO channel #1 output.  The delay is found to be evenly distributed throughout the entire recording data points.  That is, for some reason, the 1000 ms stimulation was evenly distributed over a recording period of 1001 ms.  That is, something wrong was happening and delaying the presentation of each data output (either at the stimulation, recording, or somewhere in between).  I simply cannot figure out where...
The Neuroscan stimulation system is completely independent of Labview.  Actually the entire Neuroscan system (both the stimulation and recording systems) is independent of Labview.  Neuroscan is written in Visual C.  Their stimulation system uses a Keithley I/O card (Model KPCI-PIO24 24-ch, PCI Board w/ parallel Digital I/O) running on a DELL computer using Windows XP.  
Signal flow of the Neuroscan recording system can be described as follow.  EEG signals --> headstage preamplifier --> signal box --> USB cable to a DELL computer.   The triggers should be delivered to a trigger port on the back of the signal box (either using Neuroscan stimulation system or through a TTL cable using my Labview program).  When I use my Labview program as the stimulation system, the Neuroscan stimulation system is turned off and completely disconnected from the Neuroscan recording system.  The Neuroscan recording system can record EEGs at different recording rates, from about 500 samples/second up to 20,000 samples/second.  The recording sampling rate I used was 10,000 samples/second.  I have also tried the recording sampling rate of 20,000 samples/second.  Same thing happened -- 1 ms delay out of every 1000 ms, and the delay is evenly distributed throughout the entire recording process. 
Specifications of the Neuroscan stimulation computer is:NetData (miniature)            Location: W141A (Lab office)            CPU: Pentium (R) 4 CPU 3.00 GHz, 3.00 GHz            RAM: 2 GB            Hard Drive: 80 GB, 80 GB

Windows XP + Service Pack 2

 

Neuroscan STIM computer (DELL OPTIPLEX GX620)

            Location: W141 (AEP Lab)

            CPU: Pentium (R) D 2.80 GHz, 2.79 GHz

            RAM: 1 GB

Hard Drive: 150 GB

Windows XP + Service Pack 2
 
By the way, I computer I used for my DAQ6062E (a PCMCIA card) is an ACER laptop. 
Thanks a lot...
Sincerely,
Fuh
Fuh
2008-07-11 02:40:07 UTC
Permalink
Oops.  I accidentally pressed some key, and submitted the information twice.  Sorry!
Specifications of the computers should be:

Neuroscan Recording computer:

           NetData (miniature)

            CPU: Pentium (R) 4 CPU 3.00 GHz, 3.00 GHz

            RAM: 2 GB

Hard Drive: 80 GB, 80 GB

Windows XP + Service Pack 2

 

Neuroscan stimulation computer (DELL OPTIPLEX GX620)

            Location: W141 (AEP Lab)

            CPU: Pentium (R) D 2.80 GHz, 2.79 GHz

            RAM: 1 GB

Hard Drive: 150 GB

Windows XP + Service Pack 2
 
Fuh
2008-07-11 02:40:07 UTC
Permalink
Oops.  I accidentally pressed some key, and submitted the information twice.  Sorry!
Specifications of the computers should be:

Neuroscan Recording computer:

            NetData (miniature)

            CPU: Pentium (R) 4 CPU 3.00 GHz, 3.00 GHz

            RAM: 2 GB

Hard Drive: 80 GB, 80 GB

Windows XP + Service Pack 2

 

Neuroscan stimulation computer (DELL OPTIPLEX GX620)

            Location: W141 (AEP Lab)

            CPU: Pentium (R) D 2.80 GHz, 2.79 GHz

            RAM: 1 GB

Hard Drive: 150 GB

Windows XP + Service Pack 2
 
Fuh
2008-07-11 02:40:07 UTC
Permalink
Specifications for my Labview stimulation computer is:******************************************************************************Acer Aspire 3000CPU: Mobile AMD Sempron (tm) Processor 3100+ 1.80 GHzRAM: 512 MBWindows XP and Service Pack 2*************************************************************************
For some reason, I kept submitting information twice. 
My apologies about that...
Fuh
Corby_B
2008-07-11 20:10:13 UTC
Permalink
Hello Fuh! Thanks for your post!I was looking into your issue as well and I agree with Steve_B that your program looks fine and I do not contribute the problem that you are seeing with your "poor LabVIEW skill", :). What I was able to notice how ever when running a test on a DAQ board of my own I saw that the sample rate was not actually exactly right on 44100 Hz. It was in fact 44095 Hz. This could be the contributing factor of your output getting off by 1ms. The reason is because the divide down ratio of the master time base will not give you the exact integer 44100. So if you use a DAQmx Timing Property node and set it to "Sample Clock Rate". ( You can find this property node in the DAQmx palette) You can see that the value is not in fact 44100. So what I was able to do is run a test with your code on a Digital Sound Analysis (DSA) card that we have here, the PXI-4461, and since the card has an over sample clock and uses a DDS sample generator this causes the frequency to be more exact. So running your same program we were able to get an exact frequency of 44100 for the output of your sound file. So the only way to compensate for your program at this point may be to do some kind of software manipulation or the 4461 may be a way for you to go for your application. Also if you were able to supply an external sample clock of exactally 44100 then that would be a workaround as well. Let me know if you have any other questions and Good Luck with your application!Cheers!Corby_Bhttp://www.ni.com/support
Fuh
2008-07-14 17:10:21 UTC
Permalink
Dear Corby_B,
 
Thank you for your invaluable comments.
 
I have three more questions.
 
(1) Where can I find the clock rate of the master time base of my DAQ6062E?   I have used the DAQmx Timing Property node and set it to "Sample Clock".  I also set the "source" terminal to be "OnboardClock".  I have attached the configuration as a .jpg file with this post.
 
(2) Can you tell me more about the "software manipulation" that I can do to go around this issue?  Given the actual output rate was 44095 Hz, I re-created a wave file with the same sampling rate (44095 Hz), and tested.  Still the delay is proportional to the number of data points presented throught the AO channel.  I think I am confuse on what to change in my software to go around with this problem.  Can you be more specific of what I shall do to manipulate my software and to go around with this problem?  Thanks a lot!
 
(3) Can NI PCI-6221 be a solution for my application?  During my early attempts, I tried to output my triggers through DO channels.  It didn't work because my DAQCard 6062E does not provide correlated "hardware-timed" DIO.  A NI representative has recommended me an alternative - to purchase a NI card (NI PCI-6221) that provides the option of correlated "hardware-timed" DIO.  If I purchase a NI PCI-6221 card and route my triggers through the DO channels, will this solve my problem?
 
My apologies for my ignorance on many things, but if you or anyone could help me with this, I would greatly appreciate it.
 
Sincerely,
 
Fuh
 
   


Sample Clock1.jpg:
http://forums.ni.com/attachments/ni/250/41524/1/Sample Clock1.jpg
Steve_B
2008-07-15 23:40:10 UTC
Permalink
Hi Fuh,
The Master timebase for the 6052E counters is 20MHz and this can be found on the product page listed under Specifications. Corby was referring to using the Timing Property Node to determine the actual sample clock rate. I have included a screen shot of how this can be done. You can find the property node on the DAQmx palette listed as DAQmx Timing Property Node. When you place it on your Block Diagram you can select the appropriate property (Sample Clock>>Rate). It sounds like you tried creating a sound file that has 44095 points in it and that sounds like a good idea to try. I would recommend that you try setting your rate to an integer that can be created by dividing 20MHz by an integer. This would test the idea more simply than trying to generate fractional frequencies. As far as using a PCI-6221 for this application, the only benefit would be that you can use an 80MHz timebase to divide by an integer to create your frequency.
NI PCI-6052E<a href="http://sine.ni.com/nips/cds/view/p/lang/en/nid/2601" target="_blank">http://sine.ni.com/nips/cds/view/p/lang/en/nid/2601</a>
<img src="file:///C:/Documents%20and%20Settings/sbanaska/Desktop/TimingNode.png">
Fuh
2008-07-16 18:10:09 UTC
Permalink
Dear Steve, Corby_B,&nbsp; and Rob, I created a wave file with a sampling rate of 40,000 samples/second.&nbsp; I then set the sample clock rate to 40,000 Hz.&nbsp; And you know what?&nbsp;&nbsp; It worked!!! &nbsp; Actually it worked perfectly.&nbsp; I checked the timing and recorded data points in the Neuroscan recording system.&nbsp; It is "exactly" the time length I would expect.&nbsp; Thank you all so much for all your help.&nbsp; I really appreciate that.Sincerely,Fuh
Loading...