Filter löschen
Filter löschen

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

17 Ansichten (letzte 30 Tage)
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

Antworten (1)

Mathieu NOE
Mathieu NOE am 1 Mär. 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

Kategorien

Mehr zu Startup and Shutdown finden Sie in Help Center und File Exchange

Tags

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by