How to get the phase sift of the filtering?

26 views (last 30 days)
If I filter the signal, using filter(), there is a phase shift, between the original and the filtered signal. If I use filtfilt() function, the delay is compensated.
How may I know the amount of phase shift the filter causes, if my signal is stochastic (not a sine wave), and not periodic? For example the speed of a moving object. So it is hard to tell the base frequency component of the signal.
%%Time specifications:
Fs = 100; % samples per second
dt = 1/Fs; % seconds per sample
StopTime = 1; % seconds
t = (0:dt:StopTime-dt)'; % seconds
%%Sine wave:
Fc = 1; % Hz
x = sin(2*pi*Fc*t);
% Plot the signal versus time:
xlabel('time (in seconds)');
title('Signal versus Time');
zoom xon;
%%Generate random noise
rng('default');
r = randn(100,1);
r = r / 50*max(r);
y = x + r;
numd = [0.1667 0.1667];
dend = [1.000 -0.6667];
filtered_y = filter(numd, dend, y);
filtfilt_y = filtfilt(numd, dend, y);
plot(t,[x,y,filtered_y,filtfilt_y]);
ylim([-1.3, 1.3])
legend('Original signal','Noisy signal','Filtered signal','No phase shift filtered signal')
grid on
  2 Comments
KALYAN ACHARJYA
KALYAN ACHARJYA on 10 Aug 2017
Dear Peter,
Are you looking for to calculate the phase difference between two nonsinusoidal signals? May be following link will help full to you, still having the problem, let me know.
https://goo.gl/37xkGQ
Jeno Boka
Jeno Boka on 11 Aug 2017
He is asking the delay of the filter, not in sinusoidal case. Of course it is trivial to tell the phase shift of the filter in a purely sinusiodal case, or when the signal is periodic.
The question is when the signal is not periodic, nor deterministic.
The sine wave is just an example, to demonstare the phenomenom.
Probably the answer is linked to the tap size of the filter, as it is a digital filter. But I was not able to fint a way to get the tap number of the filter, when using filt.

Sign in to comment.

Answers (2)

Jeno Boka
Jeno Boka on 14 Aug 2017
Anyone any idea?

Star Strider
Star Strider on 14 Aug 2017
The only way I can see to calculate this is to filter the same signal using filter and filtfilt, then compare them with the finddelay (link) function. Compute the phase shift from that information. (The finddelay function was introduced two years ago if I remember correctly. The documentation does not say when it was introduced.)
  2 Comments
Jeno Boka
Jeno Boka on 28 Aug 2017
I was looking for a way to avoid the usage of the Signal Processing Toolbox.
But, yes your answer is clearly a solutuion.
Star Strider
Star Strider on 28 Aug 2017
If you want to avoid using the Signal Processing Toolbox, another option may be Curve fitting to a sinusoidal function (link), since it calculates the phase as one of the parameters. You can compare the parameters — particularly the phase parameter — of the unfiltered signal with those of the filtered signal.

Sign in to comment.

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!