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
2017-5-2
编辑:Star Strider
2017-5-2
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 的更多信息
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
