# LabVIEW

cancel
Showing results for
Did you mean:

## Determining frequency and amplitude of a real-time sampled current signal

I am sampling current from a foot actuated voice-coil in real-time through an NI-9505 module (using the 'current sense' function). I have a sinusoidal waveform of current that changes in Amperes over an arbitary time (I think labview is putting the ticks on the x axis).

How can I determine the frequency of the current signal and its corresponding amplitude? I don't think I have the appropriate time axis, I do know that my fpga current loop is sampling at 50us (20kHz), but my host code loop which is getting the current data is obtaining it at a rate of 1kHz...

Message 1 of 15
(1,851 Views)

## Re: Determining frequency and amplitude of a real-time sampled current signal

Hendrick,

I did not follow everything you tried to say.

1. The actual data sampling rate is what is important to calculating the frequency of the signal.  When the host loop (1 kHz) gets data, does it get about 20 samples each time?

2. If you have enough data to include several cycles of the signal being meaured, any of the FFT based methods should work well.  The Extract Single Tone Information.vi is easy to use.  I am assuming that this is being done on the host, not the fpga.

3. The amplitude depends on several scaling factors. The transducer transfer function. The full scale range of the A/D converter.  And any software scaling which is included in any of the VIs used.

Lynn

Message 2 of 15
(1,827 Views)

## Re: Determining frequency and amplitude of a real-time sampled current signal

If the current is being sampled in the fpga at 20kHz but the host code is reading the data in a timed loop with settings of 1kHz clock with a period of 10ms, does that mean that I'm sampling the current in the host code at 100Hz (1/10ms)?

You're correct in that I'm trying to obtain the frequency and the amplitude in the host and not the fpga, I've tried to use the extract tone .vi but I couldn't get it I've working. I've attached an image of the present waveform which I'm obtaining, the red line is the current signal which is fluctuating due to an oscillation applied to the voice coil. I just want to get the frequency and amplitude of this current signal in real-time (the frequency and amplitude of the signal will change)...

I hope that explanation was better. Thanks.

Message 3 of 15
(1,819 Views)

## Re: Determining frequency and amplitude of a real-time sampled current signal

Hendrick,

Unfortunately that image does not give much of a clue.  The time units are not specified for example.  It does not have the appearance of an undersampled system, so you may be OK.

How many samples does the host read from the fpga every 10 ms? 200 or 1 or some other number? If it gets about 200 (all the available samples) then your sampling rate is still 20 kHz. If it gets only the oldest unread sample every 10 ms, the sample rate will still be 20 kHz but it will take forever for you to get the data to the host. In this case a continuous acquisition will soon overflow a buffer somewhere and you will lose data.  If the host gets only  the newest sample every 10 ms, then your effective sample rate is 100 Hz and you are throwing away 199 of every 200 samples.

Lynn

Message 4 of 15
(1,814 Views)

## Re: Determining frequency and amplitude of a real-time sampled current signal

Hi Lynn,

how should I go about finding out how many samples the host reads from the FPGA at each iteration?

I've attached three images: the first is of the PWM generating loop within the FPGA that triggers the second image FPGA sample current loop, the third image is of the loop in the host code with which I'm reading the current feedback from the FPGA.

The current feedback as shown in the previously attached image is pretty responsive so perhaps I am obtaining the newest sample every 10ms.

Message 5 of 15
(1,809 Views)

## Re: Determining frequency and amplitude of a real-time sampled current signal

I am not familiar with the fpga stuff so I may be misinterpretting something, but it looks liek you write a scalar value to the Current Feedback local in the second frame of the Sample Current loop which runs slighlty slower than 100 ms.  Then the Host Current loop appears to read on sample every 20 ms.  So it looks like you are sampling at about 100 Hz.

Event though you may be sending 20000 triggers, you are not sampling that fast.

Lynn

Message 6 of 15
(1,801 Views)

## Re: Determining frequency and amplitude of a real-time sampled current signal

I've built a waveform with the current data so that time is included but I still can't get an output of frequency/amplitude from tone measurements...

Message 7 of 15
(1,793 Views)

## Re: Determining frequency and amplitude of a real-time sampled current signal

Tone measurements and all the other frequency determining methods require a series of data samples, usually in an array or waveform.  I do not see anything in your images where you accumulate your data points into an array.

Lynn

Message 8 of 15
(1,789 Views)

## Re: Determining frequency and amplitude of a real-time sampled current signal

As shown in the attached image, I have built a current waveform (sorry if it's messy but I'm just trying to see what works), I'm still getting no data from the amplitude and frequency outputs. Do I need some sort of block/window within which the .vi can determine the freq/amp of the signal since it's in real-time? Thanks

Message 9 of 15
(1,786 Views)

## Re: Determining frequency and amplitude of a real-time sampled current signal

You build an array but you only put one element into it.  Build Array does not have any memory or accumulator.  Each time through the loop you send the Tone VI exactly one data point.  It cannot figure out the frequency from one point.

Put a shift register on your loop. Put the array in the shift register. Every time a new data point is available, put it into the array.  The best way to do this is to initialize the array outside the loop and use Replace Array Subset inside the loop.  You also need some method of keeping track of the index of the next array element to be replaced.  Once you have several cycles of data points in the array, the Tone VI will start giving you the frequency.

Lynn

Message 10 of 15
(1,781 Views)