07-15-2009 11:25 AM
I am using a PCI 4472 with Measurement studio 8.5 in vb.net.
How can I use Measurement Studio do do the following?
3200 line FFT
Hanning Window
16 Averages Min
0-50% overlap
07-16-2009 01:08 PM
The main part that i need to set up ASAP is the 3200 line part. Any help would go a long way!
07-16-2009 03:07 PM
07-17-2009 07:37 AM
07-17-2009 07:52 AM
The number of lines in the spectrum is governed by the number of samples in the block of time data.
For eample the equations that you need assuming traditional bench top analyser approach are as follows: -
Lets assume that you want to measure a baseband signal from 0-10kHz, the traditional sample rate (Fs) would then be 2.56 * 10kHz = 25,600
and therefore the time between each sample dT would be 1/Fs = 0.0000390625.
In order to obtain the resolution in the frequency domain FFT line size (3200 in your case), then we need to capture 3200*2.56 time samples = 8192 (usually defined as blocksize).
The total time (T) to capture this block is therefore dT * Blocksize = 0.32 seconds
This would the give a frequency resoltion dF of 10000 /3200 = 3.125Hz.
If you halve the blocksize say to 4096, then T = 0.16 seconds the FFT line size would halve to 1600 and df would double.
In order to produce an autopower spectrum then follow these steps: -
'capture a time block of length 8192 samples call it timeBlock.
Dim timeBlock() As Double = New Double(8191){}
'Create a hanning window variable e.g.
Dim m_WindowType As Analysis.Dsp.ScaledWindow
m_WindowType = Analysis.Dsp.ScaledWindow.CreateHanningWindow
'apply hanning window
m_WindowType.Apply(timeblock)
' create array to hold spectrum
Dim Spectrum() As Double = New Double() {}
When calculating the Spectrum Note! that you need to supply dT i.e. 1/Fs = 1/25600 in this example
Spectrum = Analysis.SpectralMeasurements.Measurements.AutoPowerSpectrum(timeblock, dT, dF)
'the spectrum and dF are returned
'scale the answer to suit
Spectrum = Analysis.SpectralMeasurements.Measurements.SpectrumUnitConversion(Spectrum,Analysis.SpectralMeasurements.SpectrumType.Power, Analysis.SpectralMeasurements.ScalingMode.Linear, Analysis.SpectralMeasurements.DisplayUnits.VoltsRms, dF, eNbw, cohGain, sb)
In order to carry out averaging you will have to perform a loop and average the returned spectrum either in a linear sense (RMS or stable averaging), by holding just the peaks (Peak Hold) or using an exponetial averaging technique.
For an overlap of 0% just loop on the number of blocks you capture for your average number. For 50% then you need to capture 1 block for average 1 and a further half block namely 4096 points and then for the second average use the last 4096 samples of block 1 combined with 4096 new samples and so on.
Hope this helps
StevieB
07-17-2009 09:01 AM
07-20-2009 08:00 AM
How do I set my time data record length that is the same as block size? Should I just take a 1 second recording and extract the blocksize for the data I want? If there is a smarter way to do this please let me know. Here is the code I'm using right now, it is borrowed from the spectrum analyizer example.
Private Sub acquisitionStateSwitch_StateChanged(ByVal sender As System.Object, ByVal e As NationalInstruments.UI.ActionEventArgs) Handles acquisitionStateSwitch.StateChanged
Try
' Acquisition on
If (acquisitionStateSwitch.Value And (runningTask Is Nothing)) Then
samplingRate = rateNumericEdit.Value
samplesPerChannel = Convert.ToInt16(samplesNumericEdit.Value)
myTask = New Task
myTask.AIChannels.CreateVoltageChannel(channelTextBox.Text, "aiChannel", AITerminalConfiguration.Pseudodifferential, -10.0, 10.0, AIVoltageUnits.Volts)
myTask.Timing.ConfigureSampleClock("", samplingRate, SampleClockActiveEdge.Rising, SampleQuantityMode.ContinuousSamples, samplesPerChannel)
runningTask = myTask
firstTime = True 'Boolean value that sets longData array to begin a new set
reader = New AnalogSingleChannelReader(myTask.Stream)
reader.SynchronizeCallbacks = True
reader.BeginReadMultiSample(samplesPerChannel, New AsyncCallback(AddressOf myCallback), myTask)
run = 0
'Disable channel variables
samplesNumericEdit.Enabled = False
rateNumericEdit.Enabled = False
channelTextBox.Enabled = False
aqTime.Enabled = False
runTime.Enabled = False
'Acquisition off
Else
If Not (runningTask Is Nothing) Then
runningTask = Nothing
myTask.Dispose()
End If
'Do FFT of most recently collected data
analyize.goFFT(longData, samplingRate, spectrum, df)
timeDataWaveformGraph.PlotY(spectrum, 0, df)
're-enable channel variables
samplesNumericEdit.Enabled = True
rateNumericEdit.Enabled = True
channelTextBox.Enabled = True
aqTime.Enabled = True
runTime.Enabled = True
End If
Catch ex As DaqException
MessageBox.Show(ex.Message)
runningTask = Nothing
myTask.Dispose()
End Try
End Sub
Private Sub myCallback(ByVal ar As IAsyncResult)
Try
If runningTask Is ar.AsyncState Then
data = reader.EndReadMultiSample(ar)
'Collect all data points into single array list
If firstTime Then
longData = data
firstTime = False
Else
longData = NationalInstruments.Analysis.Math.ArrayOperation.Concatenate(data, longData)
End If
' Display current time
runningLabel.Text = Now
'begin next read
reader.BeginReadMultiSample(samplesPerChannel, New AsyncCallback(AddressOf myCallback), myTask)
End If
Catch ex As DaqException
MessageBox.Show(ex.Message)
runningTask = Nothing
myTask.Dispose()
End Try
End Sub
07-22-2009 08:37 AM
07-22-2009 11:04 AM
Yes, sorry I forgot to mention that when you obtain the Autospectrum then blocksize/2 lines are returned.
However, in traditional analysers only blocksize/2.56 lines are considered alias free.
Therefore you usually carry out a Redim Preserve Spectrum(Cint(blocksize/2.56) to obtain your 3200 alias free spectrum or you could use the array.constrainedcopy function or you could just plot the array from 0-3200. The values between 3201 and 4095 are therefore not used.
In observing your requirement, in order to obtain 0-5kHz, I would set the samplerate to 12800 samples/s = 2.56*5000 on your acquisition card.
Also I have no experience with your card so I cannot help with gathering the correct number of samples.
Regards
StevieB
07-22-2009 12:12 PM
In order to carry out averaging you will have to perform a loop and average the returned spectrum either in a linear sense (RMS or stable averaging), by holding just the peaks (Peak Hold) or using an exponetial averaging technique."
Can you explain this a little bit more? Can I not just average each point on the graph?