Commit c45b310e authored by Lukas Aspöck's avatar Lukas Aspöck

- load ac3d: added method returning surface area of given material

- itaRavenProject: fixed bug: projectTag is now intialized preventing RavenOutput folder from being deleted
- itaRavenProject: finished implementation of plot routines for materials (plotMaterialsAbsorption & plotMaterialsScattering)
parent 25e92ae1
...@@ -303,6 +303,7 @@ classdef itaRavenProject < handle ...@@ -303,6 +303,7 @@ classdef itaRavenProject < handle
% [Global] % % [Global] %
obj.projectName = obj.rpf_ini.GetValues('Global', 'ProjectName', 'Matlab'); obj.projectName = obj.rpf_ini.GetValues('Global', 'ProjectName', 'Matlab');
obj.projectTag = obj.projectName;
obj.pathResults = obj.rpf_ini.GetValues('Global', 'ProjectPath_Output', '..\RavenOutput'); obj.pathResults = obj.rpf_ini.GetValues('Global', 'ProjectPath_Output', '..\RavenOutput');
obj.pathDirectivities = obj.rpf_ini.GetValues('Global', 'ProjectPath_DirectivityDB', '..\RavenDatabase\DirectivityDatabase'); obj.pathDirectivities = obj.rpf_ini.GetValues('Global', 'ProjectPath_DirectivityDB', '..\RavenDatabase\DirectivityDatabase');
obj.pathMaterials = obj.rpf_ini.GetValues('Global', 'ProjectPath_MaterialDB', '..\RavenDatabase\MaterialDatabase'); obj.pathMaterials = obj.rpf_ini.GetValues('Global', 'ProjectPath_MaterialDB', '..\RavenDatabase\MaterialDatabase');
...@@ -324,6 +325,7 @@ classdef itaRavenProject < handle ...@@ -324,6 +325,7 @@ classdef itaRavenProject < handle
obj.logPerformance = obj.rpf_ini.GetValues('Global', 'logPerformance', 0); obj.logPerformance = obj.rpf_ini.GetValues('Global', 'logPerformance', 0);
obj.keepOutputFiles = obj.rpf_ini.GetValues('Global', 'keepOutputFiles', 0); obj.keepOutputFiles = obj.rpf_ini.GetValues('Global', 'keepOutputFiles', 0);
% change relative to absolute paths % change relative to absolute paths
if obj.ravenExe(2) == ':' % absolute path if obj.ravenExe(2) == ':' % absolute path
ravenBasePath = fileparts(fileparts(obj.ravenExe)); % base path of raven ravenBasePath = fileparts(fileparts(obj.ravenExe)); % base path of raven
...@@ -332,6 +334,8 @@ classdef itaRavenProject < handle ...@@ -332,6 +334,8 @@ classdef itaRavenProject < handle
if (strcmp(obj.pathDirectivities(1:2),'..')), obj.pathDirectivities = [ ravenBasePath obj.pathDirectivities(3:end) ]; end if (strcmp(obj.pathDirectivities(1:2),'..')), obj.pathDirectivities = [ ravenBasePath obj.pathDirectivities(3:end) ]; end
if (strcmp(obj.pathMaterials(1:2),'..')), obj.pathMaterials = [ ravenBasePath obj.pathMaterials(3:end) ]; end if (strcmp(obj.pathMaterials(1:2),'..')), obj.pathMaterials = [ ravenBasePath obj.pathMaterials(3:end) ]; end
if (strcmp(obj.fileHRTF(1:2),'..')), obj.fileHRTF = [ ravenBasePath obj.fileHRTF(3:end) ]; end if (strcmp(obj.fileHRTF(1:2),'..')), obj.fileHRTF = [ ravenBasePath obj.fileHRTF(3:end) ]; end
end end
% [Rooms] % % [Rooms] %
...@@ -347,6 +351,7 @@ classdef itaRavenProject < handle ...@@ -347,6 +351,7 @@ classdef itaRavenProject < handle
end end
% [PrimarySources] % % [PrimarySources] %
obj.sourceNameString = obj.rpf_ini.GetValues('PrimarySources', 'sourceNames', 'Sender'); obj.sourceNameString = obj.rpf_ini.GetValues('PrimarySources', 'sourceNames', 'Sender');
...@@ -708,6 +713,126 @@ classdef itaRavenProject < handle ...@@ -708,6 +713,126 @@ classdef itaRavenProject < handle
text(rpos(:,3)+0.2,rpos(:,1),rpos(:,2),rnames) text(rpos(:,3)+0.2,rpos(:,1),rpos(:,2),rnames)
end end
%------------------------------------------------------------------
function plotMaterialsAbsorption(obj, exportPlot)
if nargin < 2
exportPlot = false;
end
freqVector = [20 25 31.5 40 50 63 80 100 125 160 200 250 315 400 500 630 800 1000 1250 1600 2000 2500 3150 4000 5000 6300 8000 10000 12500 16000 20000];
freqLabel3rdVisual = { '', '', '31.5 Hz', '', '', '' '', ' ', ' 125 Hz', ' ', ' ', ...
'', ' ', ' ', ' 500 Hz', ' ', ' ', '', '', ' ', ' 2 kHz', ...
' ', '', '', '', '', ' 8 kHz', ' ', '', '', '20 kHz'};
yticks = { '0.0','', '0.20','','0.40','','0.60','','0.80','','1.0'};
allMaterials = obj.getRoomMaterialNames;
numberMaterials = length(allMaterials);
currentMaterial = itaResult;
currentMaterial.freqVector = freqVector;
currentMaterial.freqData = [];
for iMat=1:numberMaterials
[absorp scatter ] = obj.getMaterial(allMaterials{iMat});
currentMaterial.freqData = [ currentMaterial.freqData absorp' ];
currentSurfaceArea = obj.getSurfaceAreaOfMaterial(allMaterials{iMat});
allMaterials{iMat} = strrep(allMaterials{iMat},'_',' ');
allMaterials{iMat} = [ allMaterials{iMat} ' (S = ' num2str(currentSurfaceArea,'%5.2f') ' m ;'];
allMaterials{iMat} = [ allMaterials{iMat} ' A (Eyring, f=1000 Hz) = ' num2str(-currentSurfaceArea*log(1-currentMaterial.freqData(18)),'%5.2f') ' m )'];
end
currentMaterial.channelNames = allMaterials;
currentMaterial.allowDBPlot = false;
currentMaterial.pf;
% change format of plot
title('');
ylabel('Absorption coefficient');
xlabel('Frequency in Hz');
set(gca,'XLim',[63 20000]);
set(gca,'YLim',[0 1]);
leg = findobj(gcf,'Tag','legend');
set(leg,'Location','NorthWest');
set(leg,'FontSize',9);
% remove [1] in legend entry
for iMat=1:numberMaterials
leg.String{iMat} = leg.String{iMat}(1:end-4);
end
% export plot to raven output
if (exportPlot)
[pathstr,name,ext] = fileparts(obj.ravenProjectFile);
dateTimeStr = datestr(now,30);
dateTimeStr = strrep(dateTimeStr,'T','_');
fileName = [ obj.pathResults '\Absorption_' name '_' dateTimeStr '.png'];
saveas(gcf,fileName);
end
end
%------------------------------------------------------------------
function plotMaterialsScattering(obj, exportPlot)
if nargin < 2
exportPlot = false;
end
freqVector = [20 25 31.5 40 50 63 80 100 125 160 200 250 315 400 500 630 800 1000 1250 1600 2000 2500 3150 4000 5000 6300 8000 10000 12500 16000 20000];
freqLabel3rdVisual = { '', '', '31.5 Hz', '', '', '' '', ' ', ' 125 Hz', ' ', ' ', ...
'', ' ', ' ', ' 500 Hz', ' ', ' ', '', '', ' ', ' 2 kHz', ...
' ', '', '', '', '', ' 8 kHz', ' ', '', '', '20 kHz'};
yticks = { '0.0','', '0.20','','0.40','','0.60','','0.80','','1.0'};
allMaterials = obj.getRoomMaterialNames;
numberMaterials = length(allMaterials);
currentMaterial = itaResult;
currentMaterial.freqVector = freqVector;
currentMaterial.freqData = [];
for i=1:numberMaterials
[absorp scatter ] = obj.getMaterial(allMaterials{i});
currentMaterial.freqData = [ currentMaterial.freqData scatter' ];
currentSurfaceArea = obj.getSurfaceAreaOfMaterial(allMaterials{i});
allMaterials{i} = strrep(allMaterials{i},'_',' ');
allMaterials{i} = [ allMaterials{i} ' (S = ' num2str(currentSurfaceArea,'%5.2f') ' m )'];
end
currentMaterial.channelNames = allMaterials;
currentMaterial.allowDBPlot = false;
currentMaterial.pf;
% change format of plot
title('');
ylabel('Scattering coefficient');
xlabel('Frequency in Hz');
set(gca,'XLim',[63 20000]);
set(gca,'YLim',[0 1]);
leg = findobj(gcf,'Tag','legend');
set(leg,'Location','NorthWest');
set(leg,'FontSize',9);
% remove [1] in legend entry
for iMat=1:numberMaterials
leg.String{iMat} = leg.String{iMat}(1:end-4);
end
% export plot to raven output
if (exportPlot)
[pathstr,name,ext] = fileparts(obj.ravenProjectFile);
dateTimeStr = datestr(now,30);
dateTimeStr = strrep(dateTimeStr,'T','_');
fileName = [ obj.pathResults '\Scattering_' name '_' dateTimeStr '.png'];
saveas(gcf,fileName);
end
end
% [Global] % % [Global] %
%------------------------------------------------------------------ %------------------------------------------------------------------
function setProjectName(obj, projectName) function setProjectName(obj, projectName)
...@@ -2652,6 +2777,31 @@ classdef itaRavenProject < handle ...@@ -2652,6 +2777,31 @@ classdef itaRavenProject < handle
function RT = getReverbTime_Eyring(obj) function RT = getReverbTime_Eyring(obj)
RT = obj.getReverbTime(1); RT = obj.getReverbTime(1);
end end
%------------------------------------------------------------------
function S = getSurfaceAreaOfMaterial(obj,material)
if isempty(obj.model)
if iscell(obj.modelFileList)
for iRoom = 1 : numel(obj.modelFileList)
obj.model{iRoom} = load_ac3d(obj.modelFileList{iRoom});
end
roommodel = obj.model{roomID + 1};
else
obj.model = load_ac3d(obj.modelFileList);
roommodel = obj.model;
end
else
if iscell(obj.model)
roommodel = obj.model{roomID + 1};
else
roommodel = obj.model;
end
end
S = roommodel.getSurfaceArea(material);
end
%------------------------------------------------------------------ %------------------------------------------------------------------
function materialNames = getRoomMaterialNames(obj, roomID) function materialNames = getRoomMaterialNames(obj, roomID)
......
...@@ -357,6 +357,8 @@ classdef load_ac3d ...@@ -357,6 +357,8 @@ classdef load_ac3d
A = -S .* log(1 - A_tmp); A = -S .* log(1 - A_tmp);
end end
function [A, S] = getEquivalentAbsorptionArea(obj) function [A, S] = getEquivalentAbsorptionArea(obj)
[A, S] = obj.getEquivalentAbsorptionArea_sabine(); [A, S] = obj.getEquivalentAbsorptionArea_sabine();
end end
...@@ -397,6 +399,18 @@ classdef load_ac3d ...@@ -397,6 +399,18 @@ classdef load_ac3d
RT = 0.163 .* obj.totalVolume ./ (A + 4*airAbsorption*obj.totalVolume); RT = 0.163 .* obj.totalVolume ./ (A + 4*airAbsorption*obj.totalVolume);
end end
% get surface area of given material
function S = getSurfaceArea(obj, material)
S = 0; %surface area (scalar)
for matID = 1:length(obj.bcGroups)
if (strfind(obj.bcGroups{matID}.name, material))
S = S + obj.bcGroups{matID}.surface; % scalar
end
end
end
function materialNames = getMaterialNames(obj) function materialNames = getMaterialNames(obj)
% check if path model has absolute or relative path (if ':" is % check if path model has absolute or relative path (if ':" is
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment