Typo in the TKE evaluation

28 views
Skip to first unread message

Stefano Marcocci

unread,
Jul 31, 2025, 12:55:04 PMJul 31
to PIVlab
Hi William,
I would like to thank you for the new features in the 3.10 realease of PIVlab.

Speaking of which, while I was reading the codes you have modified I've found a typo in the evaluation of the TKE, in particular in the v_prime calculation (line 197 of the function 'temporal_operation_Callback.m', as shown by the attached figure). It should be 'v_prime = vmittelselected - repmat(v_mean, [1, 1, nt]);' instead of 'umittelselected' since in that line you are evaluating the fluctuations on the vertical component of the velocity.

Best regards,
Stefano Marcocci
Screenshot 2025-07-31 184932.png

thielickeoptolution

unread,
Aug 1, 2025, 11:11:42 AMAug 1
to PIVlab
Oh thanks, that seems to make sense!

Stefano Marcocci

unread,
Aug 4, 2025, 11:46:18 AMAug 4
to PIVlab
You're welcome!

In any case, I would have found a better way to implement the evaluation of each component of the turbulent kinetic energy. As a matter of fact, since the TKE of each component of the velocity depends only by its variance, it would be sufficient to evaluate both component of TKE as follows:

-----------------------------------------------------------
TKE_u=0.5*var(umittelselected,0,3,'omitnan');
TKE_v=0.5*var(vmittelselected,0,3,'omitnan');
-----------------------------------------------------------

I've put 0 as weight in the variance function (i.e. normalization by N-1 with N number of observation) since you are evaluating the standard deviation in the same way. In my opinion, this strategy is better for two reasons.

The first is that this fixes a problem related to the fact that, in the way you have implemented the TKE calculation, you are normalizing by N the variance, as you can see if you run the lines below as test:

-----------------------------------------------------------
A=1:10;
A_prime=A-mean(A);
A_prime_squared_mean=mean(A_prime.^2);
var1=var(A,0); %normalized by N-1
var2=var(A,1); %normalized by N
check=[A_prime_squared_mean==var1 A_prime_squared_mean==var2];
-----------------------------------------------------------

You will see that check=[0 1], meaning that in the way you are evaluating the TKE, you are normalizing by N the variance, but this is in contrast with what you did for the evaluation of the standard deviation some lines below (lines 219-220 in the 'temporal_operation_Callback.m' function), where you have normalized by N-1 (weight 0 in the std function).

The second advantage of following my suggested method is that you avoid a creation of two (unnecessary) 3D matrix like u_prime and v_prime, saving RAM memory (this may be crucial if you are analyzing thousands of images) and computational cost.

Therefore, I would suggest to change lines 189-205 in the 'temporal_operation_Callback.m' function with the lines I have proposed. Please do not hesitate to contact me should you have questions or doubts.

Best regards,
Stefano

thielickeoptolution

unread,
Aug 6, 2025, 7:44:16 AMAug 6
to PIVlab
Dear Stefano, thanks, sounds logical and I have changed the code accordingly:
Reply all
Reply to author
Forward
0 new messages