03-19-2014 10:18 AM
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,
03-19-2014 03:29 PM
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
03-21-2014 03:49 AM - edited 03-21-2014 03:54 AM
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 😉
03-21-2014 05:05 AM
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.
Thanks again for your hints.
Regards,
03-21-2014 01:08 PM
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
03-24-2014 11:18 AM
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