# How to calculate RMS and Crest Factor of separate data and combine into one file and one plot

22 visualizaciones (últimos 30 días)
Pasu Surananchanok el 1 de Mzo. de 2022
Respondida: Mathieu NOE el 1 de Mzo. de 2022
Hello,
In case that I have the separate 123 mat files (bearing1_1_1.mat to bearing 1_1_123.mat) and I would like to calculate RMS and Crest Factor of each file and combine to one file.
In addition, how to plot the RMS into the graph like an attached picture (RMS of data 1 to data 123), how should I write the script?
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

### Respuestas (1)

Mathieu NOE el 1 de Mzo. de 2022
hello
this is my suggestion - maybe you will have to do a few mods according how the data is stored in your mat files (not supplied)
fileDir = pwd; % current directory or specify the target directory
S = dir(fullfile(fileDir,'bearing*.mat')); % get list of data files in directory
S = natsortfiles(S); % sort file names into natural order (what matlab does not do well) , see FEX :
%(https://fr.mathworks.com/matlabcentral/fileexchange/47434-natural-order-filename-sort)
for k = 1:length(S)
time = data.time;
signal = data.signal;
signal_rms(k) = sqrt(mean(signal.^2));
CrestFactor(k) = max(abs(signal))/signal_rms(k);
end
figure
plot((1:k),signal_rms)
figure
plot((1:k),CrestFactor)
FYI I created some dummy data files to test the above code
Fs = 1000;
dt = 1/Fs;
for ci = 1:123
baseFileName = ['bearing_1_1_' num2str(ci) '.mat'];
time = 0:dt:1; % time vector
signal = ci*sin(2*pi*ci*time)+ 0.1*ci*rand(size(time)); % non constant amplitude and freq signal vector
save(baseFileName,'time','signal');
end
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

### Categorías

Más información sobre Startup and Shutdown en Help Center y File Exchange.

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by