Resampling vector from the middle sample (Keeping the symmetry)

1 view (last 30 days)
Hi All,
I would like to re-sample a vector using different sample rates. But I would want to keep the symmetry as it is.
E.g. h = [ 0.1 0.3 0.7 0.3 0.1]; % Original vector with 5 samples h2 = resample(h,4,5); % Re-sampled vector into 4 samples
But the above command doesn't give a symmetric vector as the original one. Is there any way to re-sample keeping the symmetry around the center sample ?
Thanks very much.
  2 Comments
Dishant Arora
Dishant Arora on 20 Jun 2014
And how would you define a centre element in case of even length sampled array?
Dan
Dan on 23 Jun 2014
Good question, in that case I assume the center length as the average (or interpolated) sample, between the mid two. Could you please provide a way to solve this ?
Thanks in advance.

Sign in to comment.

Answers (1)

Image Analyst
Image Analyst on 23 Jun 2014
Try interp1(), or if you have the Image Processing Toolbox, imresize():
% Method using interp1()
h = [ 0.1 0.3 0.7 0.3 0.1]
x = 1 : length(h);
newNumberOfSamples = 4;
xq = linspace(x(1), x(end), newNumberOfSamples);
h2 = interp1(x, h, xq)
% Method using imresize (slightly different)
h3 = imresize(h, [1, newNumberOfSamples])
In the command window:
h =
0.1 0.3 0.7 0.3 0.1
h2 =
0.1 0.43333 0.43333 0.1
h3 =
0.11644 0.48579 0.48579 0.11644
The numbers are somewhat different because where each puts the "end point" x values is different. Interp1, the way I did it, pins down the first and last x value while imresize picked the "in between" x values (1.5, 2.5, 3.5, 4.5)
Use whichever method you want.

Community Treasure Hunt

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

Start Hunting!