%% GPU Acceleration for Autocorrelation Sequence Estimation
% This example requires Parallel Computing Toolbox™ software. Refer to GPU Support by Release to see what GPUs are supported.
% Create a signal consisting of a 10 Hz sine wave in additive noise, sampled at 1 kHz. Use gpuArray to create a gpuArray object stored on your computer’s GPU.

t = 0:0.001:10-0.001;
x = cos(2*pi*10*t) + randn(size(t));
X = gpuArray(x);

%
% Compute the normalized autocorrelation sequence to lag 200. The output, xc, is a gpuArray object.

[xc,lags] = xcorr(X,200,'coeff');

% Use gather to transfer the data from the GPU to the MATLAB® workspace as a double-precision vector.

xc = gather(xc);

% Copyright 2018 The MathWorks, Inc.