How to calculate RMS and Crest Factor of separate data and combine into one file and one plot
39 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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?
Thanks for your kind supports
0 commentaires
Réponses (1)
Mathieu NOE
le 1 Mar 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)
data = load(fullfile(fileDir, S(k).name));
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 commentaires
Voir également
Catégories
En savoir plus sur Environment and Settings dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!