upsamling with any number of data

I want to increase my data number that is different matlab functions interp and upsampling. they add numbers after every sample but i want to add them for example two and adding sample like data=(1 3 5 7 9); data_up=(1 3 4 5 7 8 9); i wrote a code but it doesn't work for every numbers sometimes it works with odds sometimes evens can anyone give any suggestion for that?

4 commentaires

Jan
Jan le 10 Déc 2012
Please post the code and explain "doesn't work" with any details.
What does "I want to add them for example two and adding sample data" mean? What is the algorithm or idea to get from data to data_up?
Image Analyst
Image Analyst le 10 Déc 2012
Modifié(e) : Image Analyst le 10 Déc 2012
All I can see is that an interpolated number was inserted in only 2 of the four possible locations: between the 2nd and 3rd location, and between the 4th and 5th location. Why there are not numbers in between the other elements, I have no idea. Regardless, you can still get this strange output by passing in the proper interpolation coordinates to interp1() (not interp()) - see my code below.
geem
geem le 10 Déc 2012
Modifié(e) : geem le 10 Déc 2012
first thanks i have add code my aim is that increase 27 to 30 so i add after every 9 sapmle 1 sample more and i calculate it by averaging but something is wrong at that line dty_upye(1,i:i+r+1)=dty_up(j,:) matlab says:Subscripted assignment dimension mismatch.
%% upsampling with any sampling rate
for i=1:27
%create data
datay(i)=i+(i+1);
end
byt_datay=length(datay);
% calculate datay length
r=fix(byt_datay/10);
% all the number of upsampled data
all=10*(r+1);
loop_nmbr=all-byt_datay;
point=fix(byt_datay/loop_nmbr);
dty_up=zeros(loop_nmbr,point+1);
k=1;
for j=1:loop_nmbr
extra=(datay(1,k+r)+datay(1,k+r+1))/2;
dty_up(j,:)= [datay(1,k:k+point-1) extra];
k=k+point;
end
i=1;
[a b]=size(dty_up);
dty_upye=zeros(1,a*b);
for j=1:loop_nmbr
dty_upye(1,i:i+r+1)=dty_up(j,:)
i=i+r+2;
end
c=all-a*b;
dty_upye2=[dty_upye datay(1,(end-(c-1)):end)];
Image Analyst
Image Analyst le 10 Déc 2012
Proper indenting and adding comments to the above code would help. I'm not going to take the time to figure out badly aligned code that's uncommented with a cryptic alphabet soup of non-descriptive variable names. Perhaps someone else likes to do that though.

Connectez-vous pour commenter.

 Réponse acceptée

Wayne King
Wayne King le 10 Déc 2012

0 votes

something very similar to what Image Analyst suggests is just to use a linear interpolation filter.
x = 1:2:9;
xup = upsample(x,2);
h = [1/2 1 1/2];
y = filter(h,1,xup);
In this case you do get a 1/2 in the first element of the output.

Plus de réponses (1)

Image Analyst
Image Analyst le 10 Déc 2012

0 votes

Is this crazy, weird thing what you want?
data = [1, 3, 5, 7, 9]
% Want data_up = [1 3 4 5 7 8 9]
xInterpLocations = [1, 2, 2.5, 3, 4, 4.5, 5]
data_up = interp1(data, xInterpLocations)
In the command window:
data =
1 3 5 7 9
xInterpLocations =
Columns 1 through 4
1 2 2.5 3
Columns 5 through 7
4 4.5 5
data_up =
1 3 4 5 7 8 9

Community Treasure Hunt

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

Start Hunting!

Translated by