how does calculate root mean square (rms) the sampling window?

Question:

I have the following scenario. I collected some acceleration data (accX, accY and accZ) from a three-phase motor through the Edge Impulse platform, using a smartphone.

When structuring my raw data in a Data frame, the following values are left:
values of a sample collected

So plotting this data I have the following subplots:
sampling subplots

So in this context, my difficulty in building a vector (list) that contains the rms root mean square of the samples comes into play.

I’ve been trying to calculate through the following code:

# calculate the average value of the accY column
media = dado['accY'].mean()

# calculate the RMS vector of the column
rms = np.sqrt(dado['accY'].apply(lambda x: (x - media)**2))

result this code in plot note: rms green line

My advisor said that rms and media should have the following behavior inside the accY subplot:
red rms and green media
Note: rms red line and medium green line.

So what are your opinions, is it wrong in the code?

New implementations, I’ve been developing moving rms of accelerations:

rms = (pd.DataFrame(abs(dado['accX'].values)**2).rolling(window).mean()) **0.5

moving rms

that makes sense?


Answers:

RMSE is defined for two sets of values, Here you are using a single set of ‘accY’ to calculate RMSE? This is not possible what you are doing is calculating the Standard Deviation, the deviation from the mean value. Here is a sample dataset which implements standard deviations.

df = pd.DataFrame({'col1': np.random.randint(low = 0,high=1000,size=100),'col2':np.random.randint(low = 0,high=120,size=100)})
aa = pd.date_range(start='1/1/2018', end='4/10/2018')
df.index = aa
df['std'] = df.rolling('5D')['col1'].std()
df = df.fillna(0)
plt.plot(df.index.values, df.col1.values)
plt.plot(df.index.values, df['std'].values)

I have created a window of 5 days calculated the standard deviation for those 5 days and plotted it against the original values.

Answered By: darth baba

I managed to solve it by

Here n is window of size n and let’s say you have an array [1, 2, 3, 4, 5] and window of size n = 2, then to calculate moving RMS for each window (x_i) or element in the array, you should have to compute the sum of squares of x_i and n-1 right shifted values (1 right shifted value in this case) in the array.

For example,

moving RMS = √( 1/n Σ x_i^2 ), where i = i to i+n-1,

moving RMS for window 1 = np.sqrt((1/2) * np.sum([1^2, 2^2])) = 1.58

moving RMS for window 2 = np.sqrt((1/2) * np.sum([2^2, 3^2])) = 2.54

moving RMS for window 3 = np.sqrt((1/2) * np.sum([3^2, 4^2])) = 3.53

moving RMS for window 4 = np.sqrt((1/2) * np.sum([4^2, 5^2])) = 4.52

moving RMS for window 5 can not be calculated.

Use code below:

for i in range(len(dado['accX'])):
  rms[i] = (i+window-1 < len(dado['accX'])) * np.sqrt( (1/window) * np.sum( dado['accX'].loc[i:i+window-1]**2 ) )

[![moving rms][3]][3]

Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.