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 件のコメント

Giorgis
Giorgis 2017 年 5 月 2 日
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.
Star Strider
Star Strider 2017 年 5 月 2 日
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
Giorgis
Giorgis 2017 年 5 月 2 日
That does the job, but there is some low pass filtering. How this low pass filtering is compared with smooth please? Thanks
Star Strider
Star Strider 2017 年 5 月 2 日
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.
Giorgis
Giorgis 2017 年 5 月 4 日
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!
Star Strider
Star Strider 2017 年 5 月 4 日
Thank you!
My pleasure!
May the Fourth be with you! (Today is ‘Star Wars Day’!)

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeInterpolation についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by