interpolate (using interp) with a decimal number

Hi
I'm trying to interpolate using a non-integer number as required by interp command. Is there another function that would allow interpolation using a decimal number please?
Thanks

 채택된 답변

Star Strider
Star Strider 2017년 5월 2일
편집: Star Strider 2017년 5월 2일

1 개 추천

I am not certain what you are asking. If you have integers and want to interpolate to the nearest integer, use the 'nearest', 'next', or 'previous' method option in your interp1 call.
You could also use the 'linear' method and the use floor, ceil, fix, or round to produce integer output from interp1.

댓글 수: 6

If you try
A = interp(B, 4.2);
You'll get
Resampling rate R must be an integer
I need a function which could take a decimal e.g. 4.2 in this case as the resampling rate. Approximation is not an option unfortunately.
I was not sure what you meant by interp, or what version you are using (Control, System Identification, Signal Processing).
If you have the Signal Processing Toolbox, your best option is probably the resample function, especially since it also uses an anti-aliasing filter. You can use the rat function to get the frequency ratio integers:
[p,q] = rat(4.2)
p =
21
q =
5
That does the job, but there is some low pass filtering. How this low pass filtering is compared with smooth please? Thanks
My pleasure.
The lowpass filtering is the result of the anti-aliasing filter. You actually do want that result, because the interpolation process can introduce spurious signals that will otherwise be aliased to the interpolated result as low-frequency energy, giving you an erroneous result. That is the real strength of the resample function, and the reason not to use the regular interpolation functions, that are not specifically designed for signal processing, for signal processing applications.
I do not have the smooth function since I don’t have the Curve Fitting Toolbox. The documentation says that it uses a moving average filter. Moving average filters can give strange results, as you can see if you plot them with the freqz function. (The core MATLAB smoothdata function uses one of several methods to smooth the data.)
I would use the results of resample for signsl processing, for the reasons I stated. It uses an anti-aliasing filter specifically designed for the particular resampling frequency ratio rather than an arbitrary smoothing filter.
You are quite right. I had to run a few examples and see that the lowpass filter changes the signal insignificantly. Thanks and good day!
Thank you!
My pleasure!
May the Fourth be with you! (Today is ‘Star Wars Day’!)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Interpolation에 대해 자세히 알아보기

태그

질문:

2017년 5월 2일

댓글:

2017년 5월 4일

Community Treasure Hunt

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

Start Hunting!

Translated by