How to get the phase sift of the filtering?

15 次查看(过去 30 天)
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 个评论
KALYAN ACHARJYA
KALYAN ACHARJYA 2017-8-10
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 2017-8-11
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.

请先登录,再进行评论。

回答(2 个)

Jeno Boka
Jeno Boka 2017-8-14
Anyone any idea?

Star Strider
Star Strider 2017-8-14
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 个评论
Jeno Boka
Jeno Boka 2017-8-28
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 2017-8-28
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Digital Filter Analysis 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by