Calculate Impedance, how to question. - Page 1
Forum section: electronics / projects

author: kvresto
author_rank: Regular Contributor
timestamp: April 29, 2016, 04:26:09 am
content: Hi Everyone.I quickly put together a diagram included here after watching Dave's video #38. Dave did not go into the details calculating Vp, Vq, Ip, and Iq. I’ve prototyped a simple Series RC circuit and I’m feeding a 1Khz sine wave onto it. Measuring across ‘R’ I’ve collected the data for current through the circuit, and measuring across ‘C’ I’ve collected the data for voltage across the capacitor, and after looking into various methods one idea was to use the following to calc V and I:Vp = sum(i = 0 to N-1) ADC(i) * cos(2 * PI * i / N)Vq = sum(i = 0 to N-1) ADC(i) * sin(2 * PI * i / N)and similarly:Ip = sum(i = 0 to N-1) ADC(i) * cos(2 * PI * i / N)Iq = sum(i = 0 to N-1) ADC(i) * sin(2 * PI * i / N)Needless to say I'm not happy with the results, can anyone point me in the right direction on how to properly make these calculations.thankskvrestoI know it probably shows my math's shortcomings, don't be too harsh.

author: kvresto
author_rank: Regular Contributor
timestamp: April 29, 2016, 10:28:49 pm
content: bump

author: IconicPCB
author_rank: Super Contributor
timestamp: April 29, 2016, 11:52:13 pm
content: Theoretically yes..Practically You already know both voltage and current associated with the capacitor.It will give you the impedance minus phase information.|Xc| = V/IPhase is easy... 90 degrees.You know what the resistance isR=V/IPhase is easyand off You go. A bit of Phasor algebra ( pythagoras and all that if You want the impedance in polar form )Otherwise it is simply Z = R-jXcwhere j is the magic number ( SQRT(-1))

author: kvresto
author_rank: Regular Contributor
timestamp: April 30, 2016, 01:59:37 am
content: by the time I carry out the calculations I've listed in the pic, I get a large error in the value for C. As I know what C is (1uF), and of course R, and I know my ADC results are correct (2048, 12bit), that leaves my calculation of Vp, Vq, Ip, and Iq to be suspect, as every other calc depends on this being done correctly.cheers

author: Andy Watson
author_rank: Super Contributor
timestamp: April 30, 2016, 08:11:29 am
content: I think your calculation of \$Xs\$ should say \$Xs = \frac{Vq Ip \; \mathbf{-} \; Vp Iq}{Ip^2 \; Iq^2}\$ ?

author: kvresto
author_rank: Regular Contributor
timestamp: April 30, 2016, 01:33:23 pm
content: QuoteYep your right. Actually that's how they are calculated anyway, Typo.

author: bson
author_rank: Unknown
timestamp: April 30, 2016, 08:14:07 pm
content: Quote from: kvresto on April 29, 2016, 04:26:09 amAccording to the above, Vp=Ip and Vq=Iq. Clearly, this is not correct.

author: kvresto
author_rank: Regular Contributor
timestamp: April 30, 2016, 11:16:24 pm
content: Hmm, in the actual code its correct, but I should have looked at my post more closely.Vp = sum(i = 0 to N-1) ADC_smpls_across_Cap(i) * cos(2 * PI * i / N)Vq = sum(i = 0 to N-1) ADC_smpls_across_Cap(i) * sin(2 * PI * i / N)and similarly:Ip = sum(i = 0 to N-1) ADC_smpls_across_Res(i) * cos(2 * PI * i / N)Iq = sum(i = 0 to N-1) ADC_smpls_across_Res(i) * sin(2 * PI * i / N)as an aside, there have been a lot of reads on this post as is normal, but my errors are sticking when pointed out, interesting it took so long to have anyone comment on them. Is this topic so specialized that most eyes glaze over? (no answer required)

author: bson
author_rank: Unknown
timestamp: May 01, 2016, 07:27:52 pm
content: No, I think it looks reasonable and there's just some minor error. For example, if your samples have an offset you will be accumulating offsets. Presumably you measure the full-scale voltage (Vfs) and normalize the samples against it; if there's a measurement error here it too will accumulate.Edit: also, ESR in the capacitor will add up since the phase angle will likely be some fractional degree less than 90.

author: Andy Watson
author_rank: Super Contributor
timestamp: May 01, 2016, 07:46:03 pm
content: Quote from: kvresto on April 30, 2016, 11:16:24 pmI might have missed this info, but just to make sure, can you confirm that "N" samples corresponds to awholenumber of cycles of your 1kHz signal?Edit: and of course, N=0 has the same phase alignment for all four measurements.

author: kvresto
author_rank: Regular Contributor
timestamp: May 02, 2016, 12:12:20 am
content: Andy, I've posted a section of my matlab code below, which processes the voltage sampled across the series resistor equating to current.f=1Khz, and Fs=10Khz, which equates to 10 samples per period.I'm collecting samples over 100 full cycles, and I intend to eventually averagethis over about 2048 collected samples (not implemented here).Quotethanks bson, the DC offset from the front end has been removed in software.N_cycles = 100;N_samples = 10;N = N_samples;indx1=1;indx=1;sample_sum=0;for i = 1:N_cycles % This is the number of full periods(T) processed.for j = 1:N_samples % This is the number of samples per cycle(period) processed.sp = amp(indx);sample_sum = sample_sum + sp;indx = indx + N_samples;endarg = cos((2*pi*i)/N);Up = Up + (sample_sum * arg);arg = -sin((2*pi*i)/N);Uq = Uq - (sample_sum * arg);sample_sum = 0;indx1 = indx1+1;indx = indx1;endIp = Up / (N_cycles * N_samples);Iq = Uq / (N_cycles * N_samples);EDIT:This is what I want to calculate:Vpp = sqrt((Vp * Vp) + (Vq * Vq))Ipp = sqrt((Ip * Ip) + (Iq * Iq))Y = (Ip * Ip) + (Iq * Iq);Rs = ((Vp * Ip) + (Vq * Iq)) / YXs = ((Vq * Ip) - (Vp * Iq)) / YQ = abs(Xs/Rs)Z = sqrt((Rs * Rs) + (Xs * Xs))phase_angle = atan(Xs / Rs)C = -1 / ((2*pi*f) * Xs)

author: IconicPCB
author_rank: Super Contributor
timestamp: May 02, 2016, 03:45:44 am
content: Averaging over 100 cycles = zerosimply look for peak( max - min) values of resistor voltage ( series current ) and peak values of capacitor voltage and determine |Xc|what you are doing is just not sound.

author: kvresto
author_rank: Regular Contributor
timestamp: May 02, 2016, 04:24:02 am
content: thanks IconicPCB, but you'll have to give me a bit more info. Which part is not sound?

author: IconicPCB
author_rank: Super Contributor
timestamp: May 02, 2016, 05:30:14 am
content: your approach is too numerically intensive.If You are already measuring the current ( implied measurement) and capacitor voltage, then You ought to be able to take a sequence of measurements with a peak detection scheme ( in hardware or software ) determine ratio of voltage to current and so calculate capacitive reactance.You know frequency of signal You can now calculate capacitance. Far simpler than invoking trig functions

author: kvresto
author_rank: Regular Contributor
timestamp: May 02, 2016, 05:50:51 am
content: Quoteok, I see what you mean. I still don't understand how its not sound??I'll see my computation method out to its conclusion, seeing that I'm still learning, and a lot of re-learning.Hopefully those with the experience will give out some advice and solutions, and thank you for yours.thankskvresto

author: Andy Watson
author_rank: Super Contributor
timestamp: May 02, 2016, 08:19:29 am
content: I wasn't questioning the software so much as the timing details of the data acquisition. How do you ensure that the voltage and current samples are taken simultaneously? And, since you appear to be accumulating over several "cycles", how is the data acquisition synchronised at each cycle?What value is N_samples?

author: kvresto
author_rank: Regular Contributor
timestamp: May 02, 2016, 09:34:27 am
content: Andy N_samples=10. At the moment I'm just polling on a rising edge and taking 2048 samples. Its all still wired on proto board with one of those AVR Arduino thingy. I just made some quick changes to the code simulating very unsynchronized sampling between the two signals, and it doesn't take too much before the results are meaningless.With my current setup my phase calculations are sort of close, but C calculation is way off.The other thing is I wasn't too sure if I was using the correct technique, I was only going of Daves video and limited info on how to do this, but since I haven't heard that what I doing is all wrong, ignoring IconicPCB for a moment, I'm going to transfer this on some vero board and better control all the interconnections, then use the STM32 hardware timers to do the sampling, I think my results will improve. Any comments welcome.kvresto

author: Andy Watson
author_rank: Super Contributor
timestamp: May 02, 2016, 10:05:23 am
content: Quote from: kvresto on May 02, 2016, 09:34:27 amYes, exactly! How accurately does your sampling frequency match the signal frequency? - Consider that 5 samples equates to a half-cycle of your signal - if you are 5 samples adrift after 2048 samples, you have a 180 degree shift in the phase of your signal - which obviously makes a nonsense of the correlation.

author: kvresto
author_rank: Regular Contributor
timestamp: May 02, 2016, 10:39:36 am
content: Yep, I'll get to work on it asap. I cant wait for the results, should be much better.cheerskvresto

author: IconicPCB
author_rank: Super Contributor
timestamp: May 02, 2016, 01:37:22 pm
content: You can stick with your sampling process..noproblems..but again ..use the samples to drive an FFT algorithm..for both current and voltage samples.You will endup with a fundamentalin both cases whic you can then use to calculate reactanceand therefore capacitance.And please dont ignore me..put my comments to a side for the time being

author: kvresto
author_rank: Regular Contributor
timestamp: May 02, 2016, 09:53:07 pm
content: no problems IconicPCB , thanks again for your input.