- #1

- 8

- 0

I have 3 signals in the form of sampled values. When I plot them using

plot (t,vPa,t,vPb,t,vPc)

where vPa, vPb, vPc contains the values and t contains the sampling istants I get this:

when I calculate phase shift using fft I get phase angle = 0.

I have tried using my own code ( which works normally on other vectors) and also a function downloaded from Mathworks and the result is always zero.

The mathworks function is at the end.

what am I doing wrong?

Thanks

Mattia

Matlab:

```
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Phase Difference Measurement %
% with MATLAB Implementation %
% %
% Author: M.Sc. Eng. Hristo Zhivomirov 12/01/14 %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function PhDiff = phdiffmeasure(x, y)
% function: PhDiff = phdiffmeasure(x, y)
% x - first signal in the time domain
% y - second signal in the time domain
% PhDiff - phase difference Y -> X, degrees
% represent x as column-vector if it is not
if size(x, 2) > 1
x = x';
end
% represent y as column-vector if it is not
if size(y, 2) > 1
y = y';
end
% signals length
xlen = length(x);
ylen = length(y);
% window preparation
xwin = hanning(xlen, 'periodic');
ywin = hanning(ylen, 'periodic');
% fft of the first signal
X = fft(x.*xwin);
% fft of the second signal
Y = fft(y.*ywin);
% phase difference calculation
[~, indx] = max(abs(X));
[~, indy] = max(abs(Y));
PhDiff = angle(Y(indy)) - angle(X(indx));
PhDiff = PhDiff*180/pi;
end
```