开发者

Extending a sequence statistically in MATLAB

Is there any built-in functions in MATLAB that would statistically extend a sequence of real numbers so that the resulting se开发者_Go百科quence is extended to any size I want. I have a sequence of 499 elements and I want to extend it to 4096 elements. Thanks in advance.


If you're wanting to interpolate a vector of 499 elements to a higher resolution of 4096 elements, you can use the INTERP1 function in the following way (where x is your 499-element vector):

y = interp1(x,linspace(1,499,4096));

The above uses the function LINSPACE to generate a 4096-element vector of values spaced linearly between 1 and 499, which is then used as the interpolation points. By default, the INTERP1 function uses linear interpolation to compute new values between the old points. You can use other interpolation methods in the following way:

y = interp1(x,linspace(1,499,4096),'spline');  %# Cubic spline method
y = interp1(x,linspace(1,499,4096),'pchip');   %# Piecewise cubic Hermite method


I don't really understand the word "statistically" in the question, but from your comments it seems that you just need linear (or smooth) interpolation. Try with interp1q or interp1.


If you know the distribution of the data to be in a Pearson or Johnson system of parametric family of distributions, then you can generate more data using the sampling functions pearsrnd and johnsrnd (useful in generating random values without specifying which parametric distribution)

Example:

%# load data, lets say this is vector of 499 elements
data = load('data.dat');

%# generate more data using pearsrnd
moments = {mean(data),std(data),skewness(data),kurtosis(data)};
newData = pearsrnd(moments{:}, [4096-499 1]);

%# concat sequences
extendedData = [data; newData];

%# plot histograms (you may need to adjust the num of bins to see the similarity)
subplot(121), hist(data), xlabel('x'), ylabel('Frequency')
subplot(122), hist(extendedData), xlabel('x'), ylabel('Frequency')

or using johnsrnd:

%# generate more data using johnsrnd
quantiles = quantile(data, normcdf([-1.5 -0.5 0.5 1.5]));
newData = johnsrnd(quantiles, [4096-499 1]);


On the other hand, if you want to assume a non-paramteric distribution, you can use the ecdf function or the ksdensity function. Please refer to the demo Nonparametric Estimates of Cumulative Distribution Functions and Their Inverses for a complete example (highly suggested!).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜