about the built-in matlab function decimate
조회 수: 5 (최근 30일)
이전 댓글 표시
In the matlab function 'decimate', the input signal is firstly lowpass-filtered, then downsampled.
In the code, I found that
odata = filtfilt(b,a,idata);
nbeg = r - (r*nout - nd);
odata = odata(nbeg:r:nd);
So, after the lowpass, the downsampling selects points from 'nbeg' rather than the first point, giving rise to a shift in the decimated signal. Why?
댓글 수: 0
채택된 답변
Walter Roberson
2015년 5월 5일
http://www.mathworks.com/help/signal/ref/decimate.html under Algorithms indicates
When using the FIR filter, decimate filters the input sequence in only one direction. This conserves memory and is useful for working with long sequences. In the IIR case, decimate applies the filter in forward and reverse directions using filtfilt to remove phase distortion. This in effect doubles the filter order. In both cases, the function minimizes transient effects at both ends of the signal by matching endpoint conditions.
My thought is that what you are seeing is the part about matching endpoint conditions.
decimate is, according to the documentation, often used upon chunks of the data. In order for that to work smoothly so that you can paste the results back together, you would want to avoid the first few samples of the filter result, as those correspond to the filter values not yet initialized, which is probably equivalent to the case where you were picking up in the middle of filtering an array that had an indefinite number of 0s before the data of interest. Transients caused by the initialization. So you skip the affected output samples and end up with something that can be smoothly combined with the previous or next chunk.
댓글 수: 1
K E
2015년 11월 23일
Is a workaround to pad the time series at the start/end with a 'reflection' (first/last xx points, but in reverse order), apply the filter, then throw out the fake data at the start/end? I have seen this done.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Multirate Signal Processing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!