# How do we perform second order differential power analysis attack?

I have read papers which describe that the power traces(acquired from a side channel resistant implementation like masking) need to be centered and squared, then a correlation needs to be performed with the hypothetical power model to perform second order DPA. Suppose if I have a matrix of $m \times n$, where $m$ represents the number of traces and $n$ represents the number of samples, I have computed the mean matrix along each $m$ trace, so size of mean=$m$ by 1, I then subtract each power trace as:

power_trace_new(i,j)=(power_trace(i,j)-mean(i)).^2,


I then use this trace to correlate with my hypothetical power consumption.

Is this the correct way to do it? Or is there any other way to perform second order DPA?