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

17 次查看(过去 30 天)
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

回答(1 个)

Mathieu NOE
Mathieu NOE 2022-3-1
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

类别

Help CenterFile Exchange 中查找有关 Startup and Shutdown 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by