Henry
Henry

Reputation: 171

Using MATLAB to perform upsampling of signal

I was searching for code that upsample a signal by 3 and I found thefollowing steps

dataSize = size(datain,2);
upsamp = [datain.' zeros(dataSize,1) zeros(dataSize,1)];
len = size(upsamp,1) * size(upsamp,2);
upsamp = reshape(upsamp.',1,len);

Iam not sure how these steps supposed to execute it? I am lookin for intuition only

Upvotes: 2

Views: 3843

Answers (1)

Stergios Poularakis
Stergios Poularakis

Reputation: 104

Copying from Wikipedia:

Interpolation by an integer factor, L, can be explained as a 2-step process, with an equivalent implementation that is more efficient:

  1. Create a sequence, x_L[n], comprising the original samples, x[n], separated by L-1 zeros.
  2. Smooth out the discontinuities with a lowpass filter, which replaces the zeros.

You can also read more details here and here.

Function upsample executes only the first step, while function resample executes both of them. Take a look at the following code and notice the differences in the two figures:

close all; clear all; clc;

t = [0:0.03:1];
x = sin(4*pi*t);

% function resample performs interpolation
y = resample(x, 3, 1);
ty = [0:0.01:1.01];

figure;stem(ty, y, 'r*');
hold on;stem(t, x);

Result using function resample

% function upsample adds zeros
z = upsample(x,3);
tz = [0:0.01:1.01];

figure;stem(tz, z, 'r*');
hold on;stem(t, x);

Result using function upsample

Upvotes: 4

Related Questions