Create average data file and plots

11 views (last 30 days)
Rens Bressers
Rens Bressers on 3 May 2022
Commented: Jon on 3 May 2022
Hello!
I've been working on a project concerning vibration analysis and to analyse the results I have a small script to create FFT's of certain timeframes. This script takes the raw data, and transforms it into an FFT and a time/acceleration graph. This data includes accelerations and time. My this script saves a plot of both the FFT and t/a graph, and a seperate .mat datafile.
To continue, I would like to create average values of these FFT's and datafiles. Does anyone know how I can create averages of for instance 10 .mat files? Is this even possible? And further, can I for instance multiply or divide the data by data in another .mat file?

Answers (1)

Jon
Jon on 3 May 2022
Edited: Jon on 3 May 2022
You will have to read the data back out of the individual data files, store the variables of interest in arrays, and then compute your means (averages)
So, for example if you stored your data in files test01.mat, test02.mat, ...and each file stored a variable named t to hold the time values, and a variable named a to hold the acceleration values then you could do something like this. I think you can adapt this approach to your exact situation. In this example I just stored the values in arrays, but you could also put them in tables.
% get list of available .mat test files, assume they are named for example
% test01.mat, test02.mat, ...
list = dir('test*.mat')
% read the time vector from the first file, assume it is the same for all
% of the others
s = load(list(1).name); % load into structure whose fields are variable names
t = s.t
% loop through available tests reading in the test data from each test
numTests = numel(list);
numPoints = numel(t); % assume same for all tests
A = zeros(numTests,numPoints); % preallocate array to hold acceleration values
for k = 1:numTests
s = load(list(k).name);
A(k,:) = s.a(:)'; % use (:)' to make sure it is a row,
end
% compute ensemble averaged signal
aAvg = mean(A,1)
  1 Comment
Jon
Jon on 3 May 2022
Also note, that you don't necessarily have to store the whole array of data and then average it. You could also just accumulate running sums of each vector of interest and then finally divide by the number of tests. Depends upon whether you need the data for all of the individual tests all in one place too, or you just are interested in the final average. Unless you have so much data that your A matrix (in my above example) would use up all of your memory, either approach would work

Sign in to comment.

Categories

Find more on Vibration Analysis in Help Center and File Exchange

Tags

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!