Jump to content

As of July 17, 2015, the LabJack forums here at forums.labjack.com are shut down. New registrations, topics, and replies are disabled. All forums are in a read-only state for archive purposes.

Please visit our current forums at labjack.com/forums to view and make new posts. To post on the current forums, use your labjack.com login account. Your old LabJack forums login credentials have been retired. There are no longer separate logins for labjack.com and LabJack forums.


Photo

Intermittent Audio Sampling

audio fft sampling

  • Please log in to reply
3 replies to this topic

#1 hmm

hmm
  • Members
  • 4 posts

Posted 02 October 2013 - 01:52 AM

I'm using a U3-HV plugged into a Linux machine. I'm wondering what the best way to acheive the following is:

 

I have 4 audio line levels being fed into a LabJack U3-HV. I'd like to pull samples ideally at 44kHz in packets of 1024 samples (512 or even 256 might work) to feed into a FFT frequency analysis.

 

Latency is not an issue, this process needs to happen (at most) once an hour (possibly only once a day), and time between grabbing the samples from each input doesn't matter, eg its fine to pull each channel with a 15min gap (the sampling doesn't need to be synchonous on all channels). I need the samples to be high resolution and at as high a sample rate as possible, but I don't need a long continuous stream, just a small stream of 1024 samples.

 

Should I be using the streaming functions, is there anyway to have SamplesPerPacket larger than 25? Would this config look sensible:

 

streamConfig( NumChannels = 1, PChannels = [ 0 ], NChannels = [ 31 ], Resolution = 3, SamplesPerPacket = 25, InternalStreamClockFrequency = 1, DivideClockBy256 = False, ScanInterval = 1)

 

What does DivideClockBy256 do? (I'm assuming it would change a 4kHz rate into 4*256 KHz rate) why and when should you use it? (I can't find any verbose info on it's usage)

 

Would there any alterative/better ways to acheive the above (like using getFeedback)?

 

thanks in advance

Dave



#2 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 02 October 2013 - 11:15 AM

For a 44 kHz sample rate you will need to use stream mode. Command/response mode (i.e. getFeedback) cannot sample that fast. SamplesPerPacket maxes at 25, though the streamData reads multiple packets. At that sample rate one streamData read will return 1200 samples. You can use the first 1024 samples from that.

 

As for the streamConfig parameters, it's easiest just to set the ScanFrequency parameter and let the method set SamplesPerPacket, InternalStreamClockFrequency, DivideClockBy256 and ScanInterval for you. So the call can look like this for a 44 kHZ scan/sample rate:

streamConfig( NumChannels = 1, PChannels = [ 0 ], NChannels = [ 31 ], Resolution = 3, ScanFrequency = 44000)

For that speed Resolution needs to be set to 3 (10.5 bits). Higher resolutions slow down stream mode's max sample rate as shown in the Table 3.2-1:

 

http://labjack.com/s...users-guide/3.2

 

For streamConfig documentation on the parameters look at the source code or use Python's help function (ex. help(u3.U3.streamConfig) ). Also, take a look here for StreamConfig low-level documentation, which this method is a high level wrapper for:

 

http://labjack.com/s...rs-guide/5.2.10

 

Last, DivideClockBy256 divides the InternalStreamClockFrequency by 256, so 4 MHz / 256 or 48 MHz / 256.



#3 hmm

hmm
  • Members
  • 4 posts

Posted 03 October 2013 - 04:36 AM

I've moved from Python to C to remove any bottle neck python may be introducing so I can achieve faster sampling speeds.

I've been using the C example for streaming that came with the exodriver (u3Stream.c)
I've modified it, to use a single channel (AIN0)

const uint8 NumChannels = 1;

I've read through 5.2.10 and would like to clarify a few things when setting up streaming.

 

My assumption is that I need to set the internal stream clock freq which can be either 4,000,000Hz or 48,000,000Hz, set by switching Bit 3 to a 0 or 1 of sendBuff[9]. I can also get 15,625Hz or 187,500Hz by setting Bit 2 (Divide Clock by 256) to 1.

 

For faster sample rates I can only use the lowest resolution of 10.5-bit so I must set Bits 0-1 both to ones (11 in binary)

Then from that speed I can set my scan interval to further divide the clock to the sample rate I want.

 

So for a sample rate of 44,000Hz I would set

Bit 0 = 1

Bit 1 = 1

Bit 2 = 0

Bit 3 = 0

so 3 in decimal or 0x3 in hex, this will give me a base sample speed of 4,000,000Hz.

Scan interval is an integer, so I can now only get 44,944Hz (scan interval = 89)

 

Alternatively I could use the divide clock by 256

Bit 0 = 1

Bit 1 = 1

Bit 2 = 1

Bit 3 = 1

so 15 in decimal or 0xF in hex, this will give me a base sample speed of 187,500Hz .

Scan interval is an integer, so I can now only get 46,875Hz (scan interval = 4)

 

Is the above correct?

 

I'm fine with either these sample rates - is one way better than the other?



#4 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 03 October 2013 - 07:14 AM

The Windows UD driver just uses the 48M base clock without extra /256 divisor, all the way down to 732 scans/second.  So for a scan rate of 44k, I would just use the 48M base clock with ScanInterval=1091.  This gives 48M/1091 = 43996 scans/second, but the U3 clock is only 1.5% accurate anyway.

 

You are correct on choosing your resolution.  From Table 3.2-1 you need to use low-level resolution index 3 to get sample rates over 20k.  If you use a lower resolution index you will see scan overlap errors when you go too fast.

 

http://labjack.com/s...users-guide/3.2




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users