Open In App

What is Upsampling in MATLAB?

Last Updated : 06 Mar, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

In this article, we will see Upsampling in MATLAB. As we know that upsampling is the process of increasing the sampling rate, i.e, increasing the number of samples. When an upsampling functions on a series of samples of a signal or other continued function, it has an estimation of the row that would have been received by sampling the signal at a higher rate. Upsampling is the method of putting zero-valued samples between actual samples to increase the sampling rate. The number of zeros between the samples is decided by the sampling factor L, (Number of zeros = L-1).

In digital signal processing, signals are usually represented as a sequence of samples, where each sample is a numerical value representing the amplitude of the signal at a particular point in time. When a signal is upsampled, the number of samples in the signal is increased, resulting in a higher sample rate. This can be useful in a variety of applications, such as digital audio processing, image processing, and telecommunications.

The process of upsampling involves inserting zeros between each pair of consecutive samples in the signal. This increases the spacing between the samples and effectively increases the sample rate of the signal. The new samples created by the upsampling process are usually filled with zeros, although other interpolation methods can be used to fill the gaps between the original samples.

Why Upsampling?

Often audio hardware and software offer upsampling. When analog audio is converted to digital, it needs to be filtered so that no audio enters the analog-digital converter that is higher than half the sampling rate.  The trick is to convert the digital signal to a higher sampling rate, say two or four times the original sampling rate. When done properly the audio information has not changed and thus does not contain more information, but since the signal now has a higher sampling rate, the analog filter doesn’t have to work so hard and thus causes less distortion.
 

Upsampling()

We have upsampled function in MATLAB that is used to increase the sampling rate of any function x[n] by sampling factor ‘L’. The basic syntax is written below.

y = upsample(a,n)
y = upsample(a,n,phase)

Here,

y = upsample(a,n) is the basic syntax of the upsampling function used in MATLAB where ‘a’ is the input signal and ‘n’ is the sampling factor. We will see an example of the function in the below code.

Suppose, we have a function x = [1 2 3 4] upsampling with a sampling factor of 3 and then downsample with the same sampling factor to get the original signal.

Here are the general steps to do upsampling in MATLAB:

Step 1: Define your input signal: The first step is to define the input signal that you want to upsample. The signal can be in the form of a vector or a matrix, depending on the application.

Step 2: Specify the upsampling factor: The upsampling factor determines the number of zeros to be inserted between each pair of consecutive samples in the signal. You need to specify the upsampling factor as an integer value.

Step 3: Use the upsample() function: MATLAB provides the upsample() function to perform upsampling on a signal. The function takes the input signal and the upsampling factor as its arguments and returns the upsampled signal.

Step 4: Visualize the results: Finally, you can visualize the original and upsampled signals to see the effects of upsampling on the signal. MATLAB provides several plotting functions, such as plot(), stem(), and scatter(), that can be used to plot the signals.

Example: 

Matlab




% MATLAB Code for upsampling
clc
clear all
 
% Original signal
x = [1 2 3 4]
 
% Upsampling
y = upsample(x,3)
 
% plots the data sequence
stem(x)
subplot(4,1,2)
stem(y)
 
% Downsampling
c = downsample(y,3)
subplot(4,1,3)
stem (c)


Output:

Fig 1 : Upsampling the function with the sampling factor of 3

Code Explanation:

The input signal is x has discrete values [1, 2, 3, 4 ]. The sampling factor of the upsample function is 3. Therefore the upsampled function expands the signal by adding (L-1) zeros between each sample i.e, n=3 then the number of zeros is 3-1 =2. We can see the expanded signal in the below output. Again the upsampled function is downsampled with the same scaling factor to retrieve the original signal. The ‘stem (x)’ function is used to basically plot the sequence of the data. The subplot(x,y,z) function splits the current figure into an x-by- y-axis and constructs axes in the part defined by z.


Previous Article
Next Article

Similar Reads

Upsampling in Frequency Domain in MATLAB
Upsampling" is the process of inserting zero-valued samples between original samples to increase the sampling rate. (This is called "zero-stuffing".) Upsampling adds to the original signal undesired spectral images which are centered on multiples of the original sampling rate. In Frequency domain , Upsampling means the padding of zeros at the last
4 min read
How to Select Random Rows from a Matrix in MATLAB?
A matrix is an n x n array that stores integers, floating point numbers or alphanumeric data in MATLAB. Indexing a matrix is the same as indexing an array. Syntax:matrix_name(i,j)where, i is the row number, and J is the column number which is to be indexed. Example 1: C/C++ Code % MATLAB code for select % random matrix elements mat = magic(5); mat(
2 min read
MATLAB Annotation
Annotations in MATLAB is a way of adding explanation or notes to the plots. Annotations add more information to the plots. There are different syntax formations for adding annotations to a plot: annotation(lineType,x,y)annotation(lineType)annotation(shapeType,dim)annotation(shapeType)annotation(___,Name,Value) Let's discuss all the above functions
3 min read
Global Variables in MATLAB
Variables in programming are generally storage spaces to store a certain type of data. There are many types of variables, but two commonly used types are local and Global variables. Generally, each MATLAB function has its own local variables. But sometimes for the sake of programming, we need to change the value of the local variable in another fun
4 min read
How to Calculate Harmonic Mean in MATLAB?
Harmonic mean is a type of mean, which is a measure of central tendencies of data, in statistics that gives large weightage to smaller data and small weightage to larger data. The Harmonic Mean in mathematical terms is nothing but the reciprocal of the mean of reciprocal values of all the data elements. Harmonic Mean in MATLAB:MATLAB provides a bui
2 min read
Copy Objects in MATLAB
In MATLAB, there are two kinds of objects - handles and values. The value objects are ordinary MATLAB objects which behave normally to copy operations. It means that when a value object is copied, the new copies of that object are completely independent of the original one i.e., if the original's value is changed, the copied object will not be chan
2 min read
How to create a function in MATLAB ?
A function is a block of statements that intend to perform a specific task. Functions allow the users to reuse the code frequently. MATLAB has several predefined functions which are ready to use such as sin(), fact(), cos() etc. MATLAB also allows the users to define their own functions. Syntax: function output_params = function_name(iput_params) %
2 min read
Creating Apps Using App Designer in MATLAB
MATLAB is a powerful, high-level programming language. Matlab is widely used for designing systems by engineers and scientists and we all know that the best way to represent any idea is by using a simple but effective GUI. Matlab app builder provides you the power to build different apps, to represent your idea in a GUI-friendly manner. In this art
3 min read
Mesh Surface Plot in MATLAB
Mesh Surface Plot is used to depict f(X, Y, Z) in a three-dimensional space. Matlab allows users to create mesh surface plots using the mesh() method. Different syntax of mesh() method are: Mesh(X, Y, Z)Mesh(Z)Mesh(___,C)Mesh(___, Name, Value)S = mesh()Mesh(ax,____)Mesh(X, Y, Z)It plots X, Y, Z on a three-dimensional surface.Matrices X, Y are plott
3 min read
How To Export a Matrix as a CSV File in MATLAB?
A CSV file - Comma Separated File, as the name suggests, is a file that stores data delimited by a ' , '. In MATLAB, there is a simple way of exporting a matrix to a csv file. The writematrix() function is used to write a matrix into any desired file type. The syntax is writematrix(<matrix_name>, "filename.extension"); This will create a new
2 min read
Article Tags :