Time averaging denoising signal

I would like to use time averaging technique for denoising vibration signal, using the below function, how do we choose the appropriate parameters D and N for optimal denoising !

% sigav.m - signal averaging

%
% y = sigav(D, N, x)
%
% D = length of each period
% N = number of periods
% x = row vector of length at least ND (doesn't check it)
% y = length-D row vector containing the averaged period
% It averages the first N blocks in x
function y = sigav(D, N, x)
y = 0;
for i=0:N-1,
y = y + x((i*D+1) : (i+1)*D);       % accumulate i-th period
end
y = y / N;

• "optimal denoising" depends on your noise and your signal – you'll need to tell us more! In general, averaging is not an optimal denoising (except for very specific signals!), so I'll argue "I want to do optimal denoising" and "I want to use a simple average" is mutually exclusive. Commented Jan 23, 2021 at 12:47
• To me, finding simple $p$ parameters amount to choose them in the set $\{0,\infty\}^p$ Commented Jan 23, 2021 at 12:56

In this case $$D$$ should be chosen to represent EXACTLY one period. $$N$$ is simply determined by the length of your data set. The longer the better.
• first sentence: periodicity is not the point, the signal needs to be stronger correlated than noise for the chosen $D$. Commented Jan 23, 2021 at 15:04