interpft
1-D interpolation (FFT method)
Description
Examples
Fourier Interpolation
Interpolate 1-D data using the FFT method and visualize the result.
Generate some sample points in the interval for the function . Use a spacing interval dx
to ensure the data is evenly spaced. Plot the sample points.
dx = 3*pi/30;
x = 0:dx:3*pi;
f = sin(x).^2 .* cos(x);
plot(x,f,'o')
Use FFT interpolation to find the function value at 200 query points.
N = 200; y = interpft(f,N);
Calculate the spacing of the interpolated data from the spacing of the sample points with dy = dx*length(x)/N
, where N
is the number of interpolation points. Truncate the data in y
to match the sampling density of x2
.
dy = dx*length(x)/N; x2 = 0:dy:3*pi; y = y(1:length(x2));
Plot the results.
hold on plot(x2,y,'.') title('FFT Interpolation of Periodic Function')
Interpolate Rows of Data
Generate three separate data sets of normally distributed random numbers. Assume the data is sampled at the positive integers, 1:N
. Store the data sets as rows in a matrix.
A = randn(3,20); x = 1:20;
Interpolate the rows of the matrix at 500 query points each. Specify dim = 2
so that interpft
works on the rows of A
.
N = 500; y = interpft(A,N,2);
Calculate the spacing interval of the interpolated data dy
. Truncate the data in y
to match the sampling density of x2
.
dy = length(x)/N; x2 = 1:dy:20; y = y(:,1:length(x2));
Plot the results.
subplot(3,1,1) plot(x,A(1,:)','o'); hold on plot(x2,y(1,:)','--') title('Row 1') subplot(3,1,2) plot(x,A(2,:)','o'); hold on plot(x2,y(2,:)','--') title('Row 2') subplot(3,1,3) plot(x,A(3,:)','o'); hold on plot(x2,y(3,:)','--') title('Row 3')
Input Arguments
X
— Input array
vector | matrix | multidimensional array
Input array, specified as a vector, matrix, or multidimensional
array. The data in X
is assumed to be sampled at
an evenly spaced interval of the independent variable. interpft
works
best with periodic data.
Data Types: single
| double
Complex Number Support: Yes
n
— Number of points
positive integer scalar
Number of points, specified as a positive integer scalar.
Data Types: single
| double
dim
— Dimension to operate along
positive integer scalar
Dimension to operate along, specified as a positive integer scalar. If no value is specified, then the default is the first array dimension whose size does not equal 1.
interpft(X,n,1)
interpolates the columns ofX
.interpft(X,n,2)
interpolates the rows ofX
.
Example: interpft(X,n,3)
Output Arguments
y
— Interpolated points
vector | matrix | multidimensional array
Interpolated points, returned as a vector, matrix, or multidimensional
array. If length(X,dim) = m
, and X
has
a sampling interval of dx
, then the new sampling
interval for y
is dy = dx*m/n
,
where n > m
.
If dim
is specified, then interpft
pads
or truncates X
to length n
in
dimension dim
, so that size(y,dim) = n
.
Algorithms
The interpft
function uses the FFT method. The original vector
x
is transformed to the Fourier domain using
fft
, and then it is transformed back with more points.
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
Usage notes and limitations:
n
must be a positive integer.For limitations related to variable-size data, see Variable-Sizing Restrictions for Code Generation of Toolbox Functions (MATLAB Coder).
Thread-Based Environment
Run code in the background using MATLAB® backgroundPool
or accelerate code with Parallel Computing Toolbox™ ThreadPool
.
This function fully supports thread-based environments. For more information, see Run MATLAB Functions in Thread-Based Environment.
Version History
Introduced before R2006a
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- 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)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)