diff --git a/PlottingTool.mlapp b/PlottingTool.mlapp new file mode 100644 index 0000000..8729be6 Binary files /dev/null and b/PlottingTool.mlapp differ diff --git a/fourierPlotFnc.m b/fourierPlotFnc.m new file mode 100644 index 0000000..5d56001 --- /dev/null +++ b/fourierPlotFnc.m @@ -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 + diff --git a/graphPlotFnc.m b/graphPlotFnc.m new file mode 100644 index 0000000..232f313 --- /dev/null +++ b/graphPlotFnc.m @@ -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 + diff --git a/loadChannels.m b/loadChannels.m new file mode 100644 index 0000000..b21e0de --- /dev/null +++ b/loadChannels.m @@ -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 \ No newline at end of file diff --git a/loadData.m b/loadData.m new file mode 100644 index 0000000..c8e66dd --- /dev/null +++ b/loadData.m @@ -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 + diff --git a/meanPlotFnc.m b/meanPlotFnc.m new file mode 100644 index 0000000..7d58b3b --- /dev/null +++ b/meanPlotFnc.m @@ -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 + diff --git a/saveFigs.m b/saveFigs.m new file mode 100644 index 0000000..e9e445c --- /dev/null +++ b/saveFigs.m @@ -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 + diff --git a/timeAxisWithIncrement.m b/timeAxisWithIncrement.m new file mode 100644 index 0000000..cdd807e --- /dev/null +++ b/timeAxisWithIncrement.m @@ -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 +