Signal Conditioning

cancel
Showing results for 
Search instead for 
Did you mean: 

integrate and derivate Sine wave

Hi,
I've a PXI-7841R (FPGA).
My VI needs to send the derivative of a sine wave to an external card and acquire a sine wave input that I haveto integrate.
When the frequency is too high, I notice aliasing problems and the sine's derivative  amplitude and integral are not exact.

 

Checking with simulink, for example with a sinusoid of amplitude 1, the integral should have amplitude 2 and the derivative 1.

 

In addition I wolud know if it is possible to timing the while loop with the frequency of the sinusoid (Hz), instead of using the block "wait until next ms multiple"?

 

I have attached a screenshot of simulink and VI simple to check if the integral and the derivative values are corrected, by changing the frequency.

 

Any help would be appreciated.

 

Regards,

Download All
0 Kudos
Message 1 of 6
(9,760 Views)

1. The Derivative and Integral VIs have inputs for dt. These tell the VIs what the time scale is. Wire the 0.001 time increment value to both VIs.

2. The period in the simulation images is 2*pi ~ 6.28 seconds. Set the frequency in your VI to 1/(2*pi) ~ 0.16.

 

Doing these two things and changing the X-axis scalling to show a whole cycle results in data very similar to the simulation image.

 

I am not sure what you want the timing of the loop to be. You can certainly set it to match the time increment dt. Multiply the time increment constant ( 0.001 in your VI) by 1000, convert to U32 and wire to Wait (ms). Wait (ms) is probably a better choice than Wait Until Next Millisecond Multiple. If the Integral or Derivative VIs happen to take more than 1 ms to execute, Wait Until Next Millisecond Multiple may cause more timing jitter than the standard Wait (ms).

 

Lynn 

 

Integrate.png

 

0 Kudos
Message 2 of 6
(9,747 Views)

Well, if you have 'only' a sine, why not apply a sine fit (or use tone detection.vi  with > 11 periods)

and do the integration and differentiation in the frequency domain ? (divide or multiply with omega !!complex!!phase!!)

Especially the differentiation will be MUCH MORE noise robust 🙂 but since you have to send it, just do the math 😉

Greetings from Germany
Henrik

LV since v3.1

“ground” is a convenient fantasy

'˙˙˙˙uıɐƃɐ lɐıp puɐ °06 ǝuoɥd ɹnoʎ uɹnʇ ǝsɐǝld 'ʎɹɐuıƃɐɯı sı pǝlɐıp ǝʌɐɥ noʎ ɹǝqɯnu ǝɥʇ'


0 Kudos
Message 3 of 6
(9,727 Views)

Hi,
thanks to johnsold and Henrik_Volkers.

 

I tried the solution of johnsold but when I change the frequency (f) the sine's derivative amplitude and integral are not correct.

 

In the real VI I'll have a sine wave with more harmonics so in that case, the solution will not be correct (I would not let it change frequency and fixed to 0.16).

 

I will send a signal with more harmonics to an external card and I'll acquire a similar one. I have to integrate and derive these signals.

 

For that reason I can't calculate the quantities by myself.Smiley Happy

 

Thanks again for your hints.

 

Regards,

0 Kudos
Message 4 of 6
(9,722 Views)

What kind of errors are you getting when you say the amplitudes of the derivative and integral are not correct? 

The amplitudes do depend on the frequency so they should vary as the frequency changes. The derivative amplitudes increase with increasing frequency and the integral amplitudes decrease with increasing frequency. Do the math.

 

Lynn

0 Kudos
Message 5 of 6
(9,710 Views)

Hi Mario,

 

in order to perform the  integration, you have to remove the DC offset at all times, because this will mess you integration  up.

 

To perform intergral:

1. you could  use the cumulitive sum (shift register) and then multiply by dt (sampling rate/time for single loop iteration).

2. you could use a point by point integral and specify your dt in there.

 

make sure you remove the mean before you do the integration/summation, to remove mean, use a point by point mean block, make sure you do the mean with enough samples to cover at least one period of your signal. (if you are sampling ur signal from an anlolgue input for instance sake, each iteration of the loop would read as much samples as ur analogue channel rate, so you can know how many samples you are reading at every interation accordingly)

note that if you specify your too many samples in your mean block, distortion of the integral is expected due to the delay the will be generated at mean block

similarly for a second integral, the mean has to be considered.

 

for  reference I have attached the following code.

 

hope this helps and good luck with your code.

 

email me if you need further help: ali.hassan@northampton.ac.uk

 

Regards

Ali

 

 

 

 

0 Kudos
Message 6 of 6
(9,689 Views)