I am working on project dealing with analog signals. The program should read the analog signals and then do some process to take actions upon the results.
I have already wrote the ADC part of the program that will read the analog signals and save the corresponding values in arrays (C for Current & V for Voltage). Here is the code and it is working just fine:
Now, One of the process needed is to calculate the phase shift in the current signal wrt voltage signal. I tried using zero crossing method, however, the resulting error is unacceptable.
I mean whatever code it is that you're struggling with. You asked "How can I calculate phase shift?" This was the problem I wanted to try to crack, but the code you provide doesn't even compile. It's obviously incomplete.
Assuming that your current and voltage signals are dominantly one frequency then I would expect the best approach to be to first compute the cross-correlation between the current and the voltage. The time position of the maximum correlation is an estimate of the time delay between the current and the voltage. From this and knowing the frequency an estimate of the phase difference is easily calculated.
KenF:
Actually I think that a Fourier transform function holds the answer, but I suspect that Mahmood has already found an alternative method.
Given the OP's obvious lack of signal processing experience I would hesitate to suggest using Fourier techniques. One could evaluate the cross spectral density using the Discrete Fourier Transform (of course implemented using the FFT for efficiency) but it is significantly more complex than just implementing the cross correlation function directly and the interpretation of the cross spectral density results is not so easy.
For efficiency the cross correlation function can be evaluated using the Fourier transform but again I would hesitate to suggest this extra level of complexity.
KenF:
I mean whatever code it is that you're struggling with. You asked "How can I calculate phase shift?" This was the problem I wanted to try to crack, but the code you provide doesn't even compile. It's obviously incomplete.
Never mind.
[/could you convert the above code of zero cross detection and phase shift measurement b/w current and voltage wave to arduino uno, i need this for arduino uno,]
stowite:
One could evaluate the cross spectral density using the Discrete Fourier Transform (of course implemented using the FFT for efficiency) but it is significantly more complex than just implementing the cross correlation function directly and the interpretation of the cross spectral density results is not so easy.
For efficiency the cross correlation function can be evaluated using the Fourier transform but again I would hesitate to suggest this extra level of complexity.
I'll wager that's NOT the way the OP solved this issue
Mahmood:
Now, One of the process needed is to calculate the phase shift in the current signal wrt voltage signal. I tried using zero crossing method, however, the resulting error is unacceptable.
How did you measure the zero crossing and why was the result unacceptable? I would not explore more complicated techniques if you can't explain why the simplest technique is inadequate.