Matlab code to Upsample a given sequence.

Status
Not open for further replies.

Prosenjit101

Newbie level 5
Joined
Apr 18, 2013
Messages
9
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Dhaka, Bangladesh
Activity points
1,349
Here i have a code to downsample a given sequence.

in editor:

function[y]= dns(x)
k = input('Enter downsampling factor = ')
y= x(1:k:length(x));
end

in command window:

>> x = [ 1 2 3 4 5 6 7 8 9 10 11 12]
>> dns(x)
Enter downsampling factor = 3

k =

3


ans =

1 4 7 10


I need a similar type of code for upsampling.
 

Hi,
the upsampling is not that straight forward as down sampling.
there are various methods to do the upsampling, the easiest in my opinion is linear interpolation, but you can use quadratic methods, cubic spline interpolation etc... depends on why you need it for...
so you have to specify your application a bit more.
would recommend you to read at least the wiki page of interpolation: https://en.wikipedia.org/wiki/Interpolation
 

for linear interpolation...

close all;
clear all;
x = [ 1 2 3 4 5 6 7 8 9 10 11 12]
k = input('Enter downsampling factor = ');
z=[];
for i=1:length(x)-1
m=(x(i+1)-x(i))/k;
for j=1:k-1
y(1,j)=x(i)+j*m;
end
z=[z x(i) y];
end
z=[z x(length(x))]


Enter downsampling factor = 2

z =

Columns 1 through 9

1.0000 1.5000 2.0000 2.5000 3.0000 3.5000 4.0000 4.5000 5.0000

Columns 10 through 18

5.5000 6.0000 6.5000 7.0000 7.5000 8.0000 8.5000 9.0000 9.5000

Columns 19 through 23

10.0000 10.5000 11.0000 11.5000 12.0000
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…