unexpected shift after downsampling using decimate

4 ビュー (過去 30 日間)
Ray Lee
Ray Lee 2014 年 11 月 21 日
編集済み: Vivian 2024 年 2 月 20 日
n = 1000;
t = 1:n;
x = rand(1,n) - 0.5;
x = sin(2*pi/100*t);
y = decimate(x,4);
figure('color','w');
ha = axes('nextplot','add','box','on');
plot(ha,t,x,'k','marker','.');
plot(ha,t(1:4:end),y,'r','marker','o'); addkeycb;
There is a shift of 3 points.

採用された回答

Star Strider
Star Strider 2014 年 11 月 21 日
Add the default filter to produce the correct decimation:
y = decimate(x,4,'fir');
  3 件のコメント
Star Strider
Star Strider 2014 年 11 月 23 日
My pleasure!
It may have to do with the difference between the default IIR filter (using filtfilt) and the specified FIR filter (using filter). They have different characteristics, and one may work better in some situations than the other. (I didn’t try resample to see what results it would produce. That might be worth exploring if you’re interested.)
F S
F S 2019 年 8 月 6 日
This answer solves the problem but is technically wrong. The answer from JK below gives you the real explanation and solution, in case you'd rather use the default filter.

サインインしてコメントする。

その他の回答 (1 件)

Jonathan Kohler
Jonathan Kohler 2017 年 6 月 27 日
編集済み: Jonathan Kohler 2017 年 6 月 28 日
This apparent time shift is due to MATLAB's choice of initial index for the down-sampled data, and only indirectly related to the choice of filter.
As per the documentation ( https://www.mathworks.com/help/signal/ref/decimate.html , under 'Algorithms'), the first point of the original data and downsampled data are chosen to match for FIR filters, and the last point are chosen to match for IIR filters. The reason for this choice eludes me, but maybe the provided reference explains it.
Because of the difference in handling FIR filters, there is in no shift, as pointed out by Star Strider. However, to fix this for IIR filters, you need only change your choice of time values corresponding to the downsampled data. Instead of choosing
t(1:r:end)
You should choose
nBeg = mod(n-1,r)+1;
t(nBeg:r:end)
where r=4 is the decimation factor applied.
  1 件のコメント
Vivian
Vivian 2024 年 2 月 19 日
編集済み: Vivian 2024 年 2 月 20 日
Thank you -- you nailed it! Matlab should really include this in their documentation for decimate.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMultirate Signal Processing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by