Initialization

This commit is contained in:
Max Heckmann 2022-12-30 22:44:46 +01:00
parent 4456b5c7bf
commit f5df07157d
8 changed files with 212 additions and 0 deletions

BIN
PlottingTool.mlapp Normal file

Binary file not shown.

53
fourierPlotFnc.m Normal file
View File

@ -0,0 +1,53 @@
function fourierPlotFnc(data, fileSettings, checkboxes, start, stop, yAxis, channels, path)
%Iterate through all channels
for channel = 1:width(data)
%If Graph is checked
if checkboxes{channel}.Value == 1
%Convert start and ending time
beginning = str2double(start{channel}.Value);
ending = str2double(stop{channel}.Value);
%if first row increment is not checked
if fileSettings{2}.Value == 0
[timeArray, yData] = timeAxisWithIncrement(data, fileSettings{3}.Value, beginning, ending, channel);
else
%TO DO
end
%Don't really now what I am doing here.
fs = 1 / fileSettings{3}.Value;
Nfft = 2^nextpow2(length(yData));
yData = fft(yData, Nfft);
Nspec = 256;
wspec = hamming(Nspec);
Noverlap = Nspec/2;
hold on
figure(channel)
spectrogram(yData, wspec, Noverlap, Nspec, fs, 'yaxis');
title(channels{channel});
%Plot the channel
% hold on
% figure(channel)
% spectrogram(yData, 'yaxis');
% title(channels{channel});
%Save plot
saveFigs('fourier', figure(channel), channels(channel), path, fileSettings{1}.Value)
%reset
hold off;
close all;
end
end
end

41
graphPlotFnc.m Normal file
View File

@ -0,0 +1,41 @@
function graphPlotFnc(data, fileSettings, checkboxes, start, stop, yAxis, channels, path)
%Iterate through all channels
for channel = 1:width(data)
%If Graph is checked
if checkboxes{channel}.Value == 1
%Convert start and ending time
beginning = str2double(start{channel}.Value);
ending = str2double(stop{channel}.Value);
%if first row increment is not checked
if fileSettings{2}.Value == 0
[timeArray, yData] = timeAxisWithIncrement(data, fileSettings{3}.Value, beginning, ending, channel);
else
%TO DO
end
%Plot the channel
hold on
figure(channel)
plot(timeArray, yData);
ylabel(yAxis{channel}.Value);
xlabel('Time [s]');
title(channels{channel});
%Save plot
saveFigs('graph', figure(channel), channels(channel), path, fileSettings{1}.Value)
%reset
hold off;
close all;
end
end
end

11
loadChannels.m Normal file
View File

@ -0,0 +1,11 @@
function [channels] = loadChannels(path, filenames)
channels = {};
for i = 1:length(filenames)
channel = tdmsinfo(append(path, '\', filenames(i).name)).ChannelList;
channel = channel{:, "ChannelName"};
channels{i} = channel;
end
end

18
loadData.m Normal file
View File

@ -0,0 +1,18 @@
function [dataListTable] = loadData(tdmsFileList)
%Convert struct to cell for easy access
tdmsFileList = struct2cell(tdmsFileList);
for i = 1:width(tdmsFileList)
%Read files and save them as a table in a list
data = tdmsread(strcat(tdmsFileList{2, i}, '\', tdmsFileList{1, i}));
%Take the table out of an 1x1 cell array and convert it in a cell array.
dataListTable{i} = table2array(data{1,1});
end
end

43
meanPlotFnc.m Normal file
View File

@ -0,0 +1,43 @@
function meanPlotFnc(data, fileSettings, checkboxes, start, stop, yAxis, channels, path)
%Iterate through all channels
for channel = 1:width(data)
%If Graph is checked
if checkboxes{channel}.Value == 1
%Convert start and ending time
beginning = str2double(start{channel}.Value);
ending = str2double(stop{channel}.Value);
%if first row increment is not checked
if fileSettings{2}.Value == 0
[timeArray, yData] = timeAxisWithIncrement(data, fileSettings{3}.Value, beginning, ending, channel);
else
%TO DO
end
%Plot the channel
figure(channel)
plot(timeArray, yData, '-b');
hold all
plot(timeArray, movmean(yData, 20), '-r');
ylabel(yAxis{channel}.Value);
xlabel('Time [s]');
legend('Without movmean','With movmean (20th order)')
title(channels{channel});
%Save plot
saveFigs('median', figure(channel), channels(channel), path, fileSettings{1}.Value)
%reset
hold off
close all;
end
end
end

23
saveFigs.m Normal file
View File

@ -0,0 +1,23 @@
function saveFigs(folder, figureVar, channelName, path, file)
%Suppress the warnings. If not where would be a lot of warnings
%because of the creation of folders that already exist
warning('off','all');
%Create file folder
file = strcat(path, '\', file);
mkdir(file);
%Create type folder (graph, mean, fourier)
folder = strcat(file, '\', folder);
mkdir(folder);
%Create path for saving and save as .fig and .png
pathName = strcat(folder, '\', channelName);
savefig(figureVar, strcat(pathName, '.fig'));
saveas(figureVar, strcat(pathName, '.png'));
%Turn warning back on
warning('on','all')
end

23
timeAxisWithIncrement.m Normal file
View File

@ -0,0 +1,23 @@
function [timeAxis, yData] = timeAxisWithIncrement(data, increment, beginning, ending, channel)
if ending ~= 0
timeAxis = 0:increment:ending;
else
timeAxis(1) = increment;
for i = 2:height(data)
timeAxis(i) = increment + timeAxis(i-1);
end
end
yData = data(:, channel);
yData = yData(1:length(timeAxis));
if beginning ~= 0
tempTimeArray = beginning:increment:timeAxis(end);
startIndex = length(timeAxis) - length(tempTimeArray);
yData = yData(startIndex+1:startIndex+length(tempTimeArray));
timeAxis = tempTimeArray;
end
end