I took a triangular voltage signal and taking it's time derivative I obtained the current through a pure capacitor. Then I took different portion of voltage and current signals, took their Fourier transform (as if I am taking the STFT with rectangular gate function) and obtained the magnitude & phase from FFT. I obtained the sampling frequency by the formula- Fs = N/(t_final-t_initial) where t_initial & t_final are the time of the starting point and ending point of the portion of signal I choose.

For pure capacitor, I expect $+90^0$ phase shift of each current components with respect to corresponding voltage components. But depending on the portion of signal I choose, sometimes I find $+90^0$, sometimes $+270^0=-90^0$, sometimes $+60^0$!!! In some cases I don't see any meaningful result (see 3rd figure from left)! In addition, different frequency component shows different phase relation.

So, am I doing any mistake? How to obtain correct phase information at every portion of the signal?

enter image description here
MATLAB code:


%% Generate the signal to be processed
C=10e-6;       %10 micro-farad 

v1=1*t_full(1:end/2);  %1st Ramp of the triangle
v2=v1(end)-1*(t_full(end/2+1:end)-t_full(end/2)); %2nd Ramp of the triangle 
v_full=[v1 v2];  %Triangular voltage signal

dv=gradient(v_full); dv_dt=dv./(t_full(2)-t_full(1));
i_full=C*dv_dt;  %Capacitor current =C*dv/dt 

%% Choose the portion of the full signal for STFT
%Total signal has 500 points.

st=40;  %starting point of the signal portion  
np=125; %ending point of the signal portion


%% Calculate sampling frequency
N = length(t);                % Length of signal under study
Fs = N/(t_final-t_initial);   % Sampling frequency                    

%% Obtain the FFT
V = fft(v)/N;
I = fft(i)/N;

mag_V_full = abs(V);
mag_V = mag_V_full(1:N/2+1);mag_V(2:end-1) = 2*mag_V(2:end-1); %FFT is symmetric, taking positive frequency only
phi_V_full=angle(V);phi_V = phi_V_full(1:N/2+1);

mag_I_full = abs(I);
mag_I = mag_I_full(1:N/2+1);mag_I(2:end-1) = 2*mag_I(2:end-1); %FFT is symmetric, taking positive frequency only
phi_I_full=angle(I);phi_I = phi_I_full(1:N/2+1);

f = Fs/N*(0:(N/2));

del_phi=(phi_V-phi_I)/pi*180;  %Phase shift between voltage & current component

%% steming/ploting result

[hAx,hLine1,hLine2] =plotyy(t,i,t,v);
xlabel('time (s)')
ylabel(hAx(1),'Current (A)'); % left y-axis
ylabel(hAx(2),'Voltage (V)'); % right y-axis

ylabel '|V|'
xlim([-0.05 50])

xlim([-0.05 50])
ylabel '|I|'

stem(f/1e3,del_phi)    %We need to see the phase shift of the dominating frequency component.
xlim([-0.05 50])
ylabel 'angle of Z=(Phi_V-Phi_I)'
xlabel 'Frequency (kHz)'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.