Updated June 20, 2023
Definition of Matlab Autocorrelation
In Matlab, Autocorrelation function means a correlation between numbers in a set or series with other numbers in the same set or series separated by provided time interval. Autocorrelation is also called a serial correlation because it correlates numbers with a delayed copy of itself set or series. Autocorrelation is used in signal processing for analyzing a series of values like time-domain signals. Autocorrelation means the correlation between the observation at the current time spot and the observation at previous time spots. Autocorrelation is used to determine the terms used in the MA model. Autocorrelation is used to measure the relation between the elements’ current value and past values of the same element.
[acf,lags,] = autocorr(___)
How does Autocorrelation Function work in Matlab?
Autocorrelation measures the relation between elements’ current value and past values of the same element. There are the following steps of autocorrelation function to work in Matlab: –
Step 1: Load and read all the data from the file.
Step 2: Assign all data to a variable.
Step 3: Then, use the appropriate syntax of the ‘Matlab Autocorrelation’ function.
Step 4: then execute the code.
Examples of Matlab Autocorrelation
Lets us discuss the examples of Matlab Autocorrelation.
In this example, we calculate the autocorrelation of random Gaussian noise in Matlab. We know that autocorrelation means matching signals with the delayed version itself. Now for random Gaussian noise, only when shift= 0 is there some autocorrelation value, and for all other cases, the autocorrelation result will be zero. Now first, we will generate random Gaussian noise in Matlab. For generating random Gaussian noise, we will use randn function in Matlab. “x= randn(1, length(t))” generates length t Gaussian sequence with mean 0 and variance 1. After that, we use the subplot and plot function to plot the random Gaussian noise signal. Here we will use the Matlab autocorrelation function to calculate the autocorrelation of random Gaussian noise in Matlab.“autocorr(x)” this syntax is used for calculating the autocorrelation of random Gaussian noise. Then subplot and plot function is used for plotting the autocorrelation of random Gaussian noise. To calculate the autocorrelation of a random Gaussian signal, execute the Matlab code.
In this example, we can see how we can find the periodicity of the signal using the function. So let’s first load the data. Here we use office temperature for data. This is, by default, available in Matlab. Once we load the data, we plot the data. We use a plot function to plot the data. After the plotting data, we will find the temperature oscillates. So we take the normal temperature by using mean temperature. “normal_temp= temp -mean(temp)” ones we subtract mean temperature from temperature, we get the normal temperature. After that, we will plot the normal temperature using the plot function. so we get normal temperatures varying around zero. Now we will set sampling ‘fs’ as 24. Then we are going to create a time vector t. The t will start from 0 and go up to the length of the normal temperature. Then we use Matlab autocorrelation to find the periodicity of the signal. Then we use above syntax “[autocor, lags]= xcorr (normal_temp,3*7*fs,’coeff’)”. Here ‘autocor’ variable stores the autocorrelation matrix, and ‘lags’ this variable stores the lags between the data. ‘xcorr’ correlates between normal temperature and sampling frequency. Then we plot the data that lag/fs, and autocor plot the autocorrelation of the signal.
normal_temp= temp -mean(temp);
t = (0:length(normal_temp)-1)/fs;
xlabel='Time in days';
[autocor, lags]= xcorr(normal_temp,3*7*fs,'coeff');
After executing the code, we get the autocorrelation of the input signal. If we see in Figure 2, we get that the input signal is periodic.
In this example, we calculate the autocorrelation of the input sine signal. Now we load the signal in variable ‘x.’ “x= sin(2*t)” is used to get the sine signal in Matlab. After that, we use the subplot and plot function to plot the sine signal. Here we will use the function to calculate the autocorrelation of random Gaussian noise in Matlab.“autocorr(x)” this syntax is used for calculating the autocorrelation of sine signal. Then subplot and plot function is used for plotting the autocorrelation of the sine signal.
In this article, we saw the concept of Matlab autocorrelation. Basically, this function is used to measure the relation between elements’ current values and past values of the same element. Then we saw how we could find the periodicity of the signal using this function and the efficient work of the Matlab autocorrelation function.
This is a guide to Matlab Autocorrelation. Here we discuss the definition, How Autocorrelation Function works in Matlab, along with code implementation. You may also have a look at the following articles to learn more –