First differences filter
First, you should read up on Matlab’s documentation of the filter function. If you just want to take a first difference, what you’re looking to generate is the series: Which corresponds to the vector a = 1, and b = [1, -1], so your Matlab code would look like: