Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

FFT line size

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

 

0 Kudos
Message 1 of 11
(8,773 Views)

The main part that i need to set up ASAP is the 3200 line part. Any help would go a long way!

0 Kudos
Message 2 of 11
(8,759 Views)
What version of Visual Studio and Measurement Studio do you have? Have you checked out the FFT example in C:\Documents and Settings\All Users\Documents\National Instruments\MStudioVS2008\DotNET\Examples\Analysis\Filtering\vb   ?  Its an excellent starting point. Here are the other analysis functions that can be used by different versions of Measurement Studio  http://www.ni.com/analysis/cwtools_analysis.htm  . 
Richard S -- National Instruments -- (former) Applications Engineer -- Data Acquisition with TestStand
0 Kudos
Message 3 of 11
(8,756 Views)
I have looked through those examples. The part that I really don't understan, and maybe it's my limited knowledge of fouier transforms, but how can I make the FFT 3200 lines no mater the sample size? I'm measureing a signal that is between 0 and 5K for about 20 sec at 30k samples/sec. So the data set is rather large. What function do I nee to do to average this signal data and then take a 3200 line FFT?
0 Kudos
Message 4 of 11
(8,746 Views)

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

 

  

 

 

 

  

  

Message 5 of 11
(8,745 Views)
Thanks, I think that has pushed me the right direction. Your exapmle was very helpful. I'll post more questions if they come up.
0 Kudos
Message 6 of 11
(8,736 Views)

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

0 Kudos
Message 7 of 11
(8,700 Views)
Just noticing that auto power spectrum just takes the timeBlock and halves it to determine the number of lines in The FFT, I tried 3200*2.56 with a block size of 8192. That gave me 4096 lines in my FFT, so I'm just sticking with a sampleing rate of 2X my base line fq and a time block 2X the number of lines I want in my FFT. that seems to be the only way to get it right, is there anything else I should try?
0 Kudos
Message 8 of 11
(8,674 Views)

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

 

 

Message 9 of 11
(8,666 Views)
"

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?

0 Kudos
Message 10 of 11
(8,654 Views)