Commit 44eb987d authored by jme's avatar jme

Updated V2-Lab code for new MATLAB-version

parent d4eb6aee
C:\Program Files\gs\gs9.21\bin\gswin64c.exe
\ No newline at end of file
C:\Windows\Fonts
\ No newline at end of file
function fh = copyfig(fh)
%COPYFIG Create a copy of a figure, without changing the figure
%
% Examples:
% fh_new = copyfig(fh_old)
%
% This function will create a copy of a figure, but not change the figure,
% as copyobj sometimes does, e.g. by changing legends.
%
% IN:
% fh_old - The handle of the figure to be copied. Default: gcf.
%
% OUT:
% fh_new - The handle of the created figure.
% Copyright (C) Oliver Woodford 2012
% 26/02/15: If temp dir is not writable, use the dest folder for temp
% destination files (Javier Paredes)
% 15/04/15: Suppress warnings during copyobj (Dun Kirk comment on FEX page 2013-10-02)
% Set the default
if nargin == 0
fh = gcf;
end
% Is there a legend?
if isempty(findall(fh, 'Type', 'axes', 'Tag', 'legend'))
% Safe to copy using copyobj
oldWarn = warning('off'); %#ok<WNOFF> %Suppress warnings during copyobj (Dun Kirk comment on FEX page 2013-10-02)
fh = copyobj(fh, 0);
warning(oldWarn);
else
% copyobj will change the figure, so save and then load it instead
tmp_nam = [tempname '.fig'];
try
% Ensure that the temp dir is writable (Javier Paredes 26/2/15)
fid = fopen(tmp_nam,'w');
fwrite(fid,1);
fclose(fid);
delete(tmp_nam); % cleanup
catch
% Temp dir is not writable, so use the current folder
[dummy,fname,fext] = fileparts(tmp_nam); %#ok<ASGLU>
fpath = pwd;
tmp_nam = fullfile(fpath,[fname fext]);
end
hgsave(fh, tmp_nam);
fh = hgload(tmp_nam);
delete(tmp_nam);
end
end
This diff is collapsed.
function varargout = ghostscript(cmd)
%GHOSTSCRIPT Calls a local GhostScript executable with the input command
%
% Example:
% [status result] = ghostscript(cmd)
%
% Attempts to locate a ghostscript executable, finally asking the user to
% specify the directory ghostcript was installed into. The resulting path
% is stored for future reference.
%
% Once found, the executable is called with the input command string.
%
% This function requires that you have Ghostscript installed on your
% system. You can download this from: http://www.ghostscript.com
%
% IN:
% cmd - Command string to be passed into ghostscript.
%
% OUT:
% status - 0 iff command ran without problem.
% result - Output from ghostscript.
% Copyright: Oliver Woodford, 2009-2015, Yair Altman 2015-
%{
% Thanks to Jonas Dorn for the fix for the title of the uigetdir window on Mac OS.
% Thanks to Nathan Childress for the fix to default location on 64-bit Windows systems.
% 27/04/11 - Find 64-bit Ghostscript on Windows. Thanks to Paul Durack and
% Shaun Kline for pointing out the issue
% 04/05/11 - Thanks to David Chorlian for pointing out an alternative
% location for gs on linux.
% 12/12/12 - Add extra executable name on Windows. Thanks to Ratish
% Punnoose for highlighting the issue.
% 28/06/13 - Fix error using GS 9.07 in Linux. Many thanks to Jannick
% Steinbring for proposing the fix.
% 24/10/13 - Fix error using GS 9.07 in Linux. Many thanks to Johannes
% for the fix.
% 23/01/14 - Add full path to ghostscript.txt in warning. Thanks to Koen
% Vermeer for raising the issue.
% 27/02/15 - If Ghostscript croaks, display suggested workarounds
% 30/03/15 - Improved performance by caching status of GS path check, if ok
% 14/05/15 - Clarified warning message in case GS path could not be saved
% 29/05/15 - Avoid cryptic error in case the ghostscipt path cannot be saved (issue #74)
%}
try
% Call ghostscript
[varargout{1:nargout}] = system([gs_command(gs_path()) cmd]);
catch err
% Display possible workarounds for Ghostscript croaks
url1 = 'https://github.com/altmany/export_fig/issues/12#issuecomment-61467998'; % issue #12
url2 = 'https://github.com/altmany/export_fig/issues/20#issuecomment-63826270'; % issue #20
hg2_str = ''; if using_hg2, hg2_str = ' or Matlab R2014a'; end
fprintf(2, 'Ghostscript error. Rolling back to GS 9.10%s may possibly solve this:\n * <a href="%s">%s</a> ',hg2_str,url1,url1);
if using_hg2
fprintf(2, '(GS 9.10)\n * <a href="%s">%s</a> (R2014a)',url2,url2);
end
fprintf('\n\n');
if ismac || isunix
url3 = 'https://github.com/altmany/export_fig/issues/27'; % issue #27
fprintf(2, 'Alternatively, this may possibly be due to a font path issue:\n * <a href="%s">%s</a>\n\n',url3,url3);
% issue #20
fpath = which(mfilename);
if isempty(fpath), fpath = [mfilename('fullpath') '.m']; end
fprintf(2, 'Alternatively, if you are using csh, modify shell_cmd from "export..." to "setenv ..."\nat the bottom of <a href="matlab:opentoline(''%s'',174)">%s</a>\n\n',fpath,fpath);
end
rethrow(err);
end
end
function path_ = gs_path
% Return a valid path
% Start with the currently set path
path_ = user_string('ghostscript');
% Check the path works
if check_gs_path(path_)
return
end
% Check whether the binary is on the path
if ispc
bin = {'gswin32c.exe', 'gswin64c.exe', 'gs'};
else
bin = {'gs'};
end
for a = 1:numel(bin)
path_ = bin{a};
if check_store_gs_path(path_)
return
end
end
% Search the obvious places
if ispc
default_location = 'C:\Program Files\gs\';
dir_list = dir(default_location);
if isempty(dir_list)
default_location = 'C:\Program Files (x86)\gs\'; % Possible location on 64-bit systems
dir_list = dir(default_location);
end
executable = {'\bin\gswin32c.exe', '\bin\gswin64c.exe'};
ver_num = 0;
% If there are multiple versions, use the newest
for a = 1:numel(dir_list)
ver_num2 = sscanf(dir_list(a).name, 'gs%g');
if ~isempty(ver_num2) && ver_num2 > ver_num
for b = 1:numel(executable)
path2 = [default_location dir_list(a).name executable{b}];
if exist(path2, 'file') == 2
path_ = path2;
ver_num = ver_num2;
end
end
end
end
if check_store_gs_path(path_)
return
end
else
executable = {'/usr/bin/gs', '/usr/local/bin/gs'};
for a = 1:numel(executable)
path_ = executable{a};
if check_store_gs_path(path_)
return
end
end
end
% Ask the user to enter the path
while true
if strncmp(computer, 'MAC', 3) % Is a Mac
% Give separate warning as the uigetdir dialogue box doesn't have a
% title
uiwait(warndlg('Ghostscript not found. Please locate the program.'))
end
base = uigetdir('/', 'Ghostcript not found. Please locate the program.');
if isequal(base, 0)
% User hit cancel or closed window
break;
end
base = [base filesep]; %#ok<AGROW>
bin_dir = {'', ['bin' filesep], ['lib' filesep]};
for a = 1:numel(bin_dir)
for b = 1:numel(bin)
path_ = [base bin_dir{a} bin{b}];
if exist(path_, 'file') == 2
if check_store_gs_path(path_)
return
end
end
end
end
end
error('Ghostscript not found. Have you installed it from www.ghostscript.com?');
end
function good = check_store_gs_path(path_)
% Check the path is valid
good = check_gs_path(path_);
if ~good
return
end
% Update the current default path to the path found
if ~user_string('ghostscript', path_)
filename = fullfile(fileparts(which('user_string.m')), '.ignore', 'ghostscript.txt');
warning('Path to ghostscript installation could not be saved in %s (perhaps a permissions issue). You can manually create this file and set its contents to %s, to improve performance in future invocations (this warning is safe to ignore).', filename, path_);
return
end
end
function good = check_gs_path(path_)
persistent isOk
if isempty(path_)
isOk = false;
elseif ~isequal(isOk,true)
% Check whether the path is valid
[status, message] = system([gs_command(path_) '-h']); %#ok<ASGLU>
isOk = status == 0;
end
good = isOk;
end
function cmd = gs_command(path_)
% Initialize any required system calls before calling ghostscript
% TODO: in Unix/Mac, find a way to determine whether to use "export" (bash) or "setenv" (csh/tcsh)
shell_cmd = '';
if isunix
shell_cmd = 'export LD_LIBRARY_PATH=""; '; % Avoids an error on Linux with GS 9.07
end
if ismac
shell_cmd = 'export DYLD_LIBRARY_PATH=""; '; % Avoids an error on Mac with GS 9.07
end
% Construct the command string
cmd = sprintf('%s"%s" ', shell_cmd, path_);
end
function fh = isolate_axes(ah, vis)
%ISOLATE_AXES Isolate the specified axes in a figure on their own
%
% Examples:
% fh = isolate_axes(ah)
% fh = isolate_axes(ah, vis)
%
% This function will create a new figure containing the axes/uipanels
% specified, and also their associated legends and colorbars. The objects
% specified must all be in the same figure, but they will generally only be
% a subset of the objects in the figure.
%
% IN:
% ah - An array of axes and uipanel handles, which must come from the
% same figure.
% vis - A boolean indicating whether the new figure should be visible.
% Default: false.
%
% OUT:
% fh - The handle of the created figure.
% Copyright (C) Oliver Woodford 2011-2013
% Thank you to Rosella Blatt for reporting a bug to do with axes in GUIs
% 16/03/12: Moved copyfig to its own function. Thanks to Bob Fratantonio
% for pointing out that the function is also used in export_fig.m
% 12/12/12: Add support for isolating uipanels. Thanks to michael for suggesting it
% 08/10/13: Bug fix to allchildren suggested by Will Grant (many thanks!)
% 05/12/13: Bug fix to axes having different units. Thanks to Remington Reid for reporting
% 21/04/15: Bug fix for exporting uipanels with legend/colorbar on HG1 (reported by Alvaro
% on FEX page as a comment on 24-Apr-2014); standardized indentation & help section
% 22/04/15: Bug fix: legends and colorbars were not exported when exporting axes handle in HG2
% Make sure we have an array of handles
if ~all(ishandle(ah))
error('ah must be an array of handles');
end
% Check that the handles are all for axes or uipanels, and are all in the same figure
fh = ancestor(ah(1), 'figure');
nAx = numel(ah);
for a = 1:nAx
if ~ismember(get(ah(a), 'Type'), {'axes', 'uipanel'})
error('All handles must be axes or uipanel handles.');
end
if ~isequal(ancestor(ah(a), 'figure'), fh)
error('Axes must all come from the same figure.');
end
end
% Tag the objects so we can find them in the copy
old_tag = get(ah, 'Tag');
if nAx == 1
old_tag = {old_tag};
end
set(ah, 'Tag', 'ObjectToCopy');
% Create a new figure exactly the same as the old one
fh = copyfig(fh); %copyobj(fh, 0);
if nargin < 2 || ~vis
set(fh, 'Visible', 'off');
end
% Reset the object tags
for a = 1:nAx
set(ah(a), 'Tag', old_tag{a});
end
% Find the objects to save
ah = findall(fh, 'Tag', 'ObjectToCopy');
if numel(ah) ~= nAx
close(fh);
error('Incorrect number of objects found.');
end
% Set the axes tags to what they should be
for a = 1:nAx
set(ah(a), 'Tag', old_tag{a});
end
% Keep any legends and colorbars which overlap the subplots
% Note: in HG1 these are axes objects; in HG2 they are separate objects, therefore we
% don't test for the type, only the tag (hopefully nobody but Matlab uses them!)
lh = findall(fh, 'Tag', 'legend', '-or', 'Tag', 'Colorbar');
nLeg = numel(lh);
if nLeg > 0
set([ah(:); lh(:)], 'Units', 'normalized');
try
ax_pos = get(ah, 'OuterPosition'); % axes and figures have the OuterPosition property
catch
ax_pos = get(ah, 'Position'); % uipanels only have Position, not OuterPosition
end
if nAx > 1
ax_pos = cell2mat(ax_pos(:));
end
ax_pos(:,3:4) = ax_pos(:,3:4) + ax_pos(:,1:2);
try
leg_pos = get(lh, 'OuterPosition');
catch
leg_pos = get(lh, 'Position'); % No OuterPosition in HG2, only in HG1
end
if nLeg > 1;
leg_pos = cell2mat(leg_pos);
end
leg_pos(:,3:4) = leg_pos(:,3:4) + leg_pos(:,1:2);
ax_pos = shiftdim(ax_pos, -1);
% Overlap test
M = bsxfun(@lt, leg_pos(:,1), ax_pos(:,:,3)) & ...
bsxfun(@lt, leg_pos(:,2), ax_pos(:,:,4)) & ...
bsxfun(@gt, leg_pos(:,3), ax_pos(:,:,1)) & ...
bsxfun(@gt, leg_pos(:,4), ax_pos(:,:,2));
ah = [ah; lh(any(M, 2))];
end
% Get all the objects in the figure
axs = findall(fh);
% Delete everything except for the input objects and associated items
delete(axs(~ismember(axs, [ah; allchildren(ah); allancestors(ah)])));
end
function ah = allchildren(ah)
ah = findall(ah);
if iscell(ah)
ah = cell2mat(ah);
end
ah = ah(:);
end
function ph = allancestors(ah)
ph = [];
for a = 1:numel(ah)
h = get(ah(a), 'parent');
while h ~= 0
ph = [ph; h];
h = get(h, 'parent');
end
end
end
This diff is collapsed.
function string = user_string(string_name, string)
%USER_STRING Get/set a user specific string
%
% Examples:
% string = user_string(string_name)
% isSaved = user_string(string_name, new_string)
%
% Function to get and set a string in a system or user specific file. This
% enables, for example, system specific paths to binaries to be saved.
%
% The specified string will be saved in a file named <string_name>.txt,
% either in a subfolder named .ignore under this file's folder, or in the
% user's prefdir folder (in case this file's folder is non-writable).
%
% IN:
% string_name - String containing the name of the string required, which
% sets the filename storing the string: <string_name>.txt
% new_string - The new string to be saved in the <string_name>.txt file
%
% OUT:
% string - The currently saved string. Default: ''
% isSaved - Boolean indicating whether the save was succesful
% Copyright (C) Oliver Woodford 2011-2014, Yair Altman 2015-
% This method of saving paths avoids changing .m files which might be in a
% version control system. Instead it saves the user dependent paths in
% separate files with a .txt extension, which need not be checked in to
% the version control system. Thank you to Jonas Dorn for suggesting this
% approach.
% 10/01/2013 - Access files in text, not binary mode, as latter can cause
% errors. Thanks to Christian for pointing this out.
% 29/05/2015 - Save file in prefdir if current folder is non-writable (issue #74)
if ~ischar(string_name)
error('string_name must be a string.');
end
% Create the full filename
fname = [string_name '.txt'];
dname = fullfile(fileparts(mfilename('fullpath')), '.ignore');
file_name = fullfile(dname, fname);
if nargin > 1
% Set string
if ~ischar(string)
error('new_string must be a string.');
end
% Make sure the save directory exists
%dname = fileparts(file_name);
if ~exist(dname, 'dir')
% Create the directory
try
if ~mkdir(dname)
string = false;
return
end
catch
string = false;
return
end
% Make it hidden
try
fileattrib(dname, '+h');
catch
end
end
% Write the file
fid = fopen(file_name, 'wt');
if fid == -1
% file cannot be created/updated - use prefdir if file does not already exist
% (if file exists but is simply not writable, don't create a duplicate in prefdir)
if ~exist(file_name,'file')
file_name = fullfile(prefdir, fname);
fid = fopen(file_name, 'wt');
end
if fid == -1
string = false;
return;
end
end
try
fprintf(fid, '%s', string);
catch
fclose(fid);
string = false;
return
end
fclose(fid);
string = true;
else
% Get string
fid = fopen(file_name, 'rt');
if fid == -1
% file cannot be read, try to read the file in prefdir
file_name = fullfile(prefdir, fname);
fid = fopen(file_name, 'rt');
if fid == -1
string = '';
return
end
end
string = fgetl(fid);
fclose(fid);
end
end
......@@ -28,7 +28,7 @@ function varargout = ita_marker(varargin)
% Created: 02-Jun-2010
%% Initialization and Input Parsing
narginchk(0,10);
error(nargchk(0,10,nargin,'string'));
sArgs = struct('linevector',[],'marker','s','markersize',5);
[sArgs] = ita_parse_arguments(sArgs,varargin);
......
......@@ -14,7 +14,7 @@ classdef v2
% v2gui.
%
% v1.0, 7.10.2014
% Florian Thevien, Florian.Thevissen@rwth-aachen.de
% Florian Thevien, Florian.Thevissen@rwth-aachen.de
% Institute of Technical Acoustics (ITA), RWTH Aachen University
properties (Access=public)
......@@ -113,7 +113,7 @@ classdef v2
obj.MS.outputamplification = 22;
obj.MS.fftDegree = 16; %init.
obj.MS.averages = 1;
obj.MS.nSamples = obj.measurementProperties.samples;
obj.MS.fftDegree = obj.measurementProperties.samples;
end
% measure SNR and Signals in both sending and receiving room
......@@ -141,25 +141,27 @@ classdef v2
% do this only for the first measurement of the lab course to discuss
% the measurement wrt. to modes and Schroeder frequency
if ~exist([obj.outputDirectory,'\measurement_result_S.jpg'],'file')
plotSignalsS = ita_merge([obj.Signals.ch(1:4),ita_mean(obj.Signals.ch(1:4))]);
plotSignalsS.channelNames = {'ch(1)','ch(2)','ch(3)','ch(4)','mean(ch(1:4))'};
% plotSignalsS = ita_merge([ita_merge(obj.Signals.ch(1:4)),ita_mean(obj.Signals.ch(1:4))]);
plotSignalsS = ita_merge([obj.Signals.ch(1:4)]);
plotSignalsS.channelNames = {'ch(1)','ch(2)','ch(3)','ch(4)'};
plotSignalsS.comment = 'Sound pressure measured at the 4 microphone positions in transmitter room';
hS=ita_plot_freq(plotSignalsS);
hline = findobj(hS, 'type', 'line');
set(hline,'LineStyle','--', 'LineWidth', 1);
set(hline(11),'LineWidth',2,'LineStyle','-');
set(hline,'LineStyle','-', 'LineWidth', 1);
% set(hline(11),'LineWidth',2,'LineStyle','-');
mkdir(obj.outputDirectory)
saveas(hS,[obj.outputDirectory,'\measurement_result_S'],'jpg')
saveas(hS,[obj.outputDirectory,'\measurement_result_S'],'fig')
plotSignalsR = ita_merge([obj.Signals.ch(5:8),ita_mean(obj.Signals.ch(5:8))]);
plotSignalsR.channelNames = {'ch(5)','ch(6)','ch(7)','ch(8)','mean(ch(5:8))'};
% plotSignalsR = ita_merge([obj.Signals.ch(5:8),ita_mean(obj.Signals.ch(5:8))]);
plotSignalsR = ita_merge([obj.Signals.ch(5:8)]);
plotSignalsR.channelNames = {'ch(5)','ch(6)','ch(7)','ch(8)'};
plotSignalsR.comment = 'Sound pressure measured at the 4 microphone positions in receiver room';
hR=ita_plot_freq(plotSignalsR);
hline = findobj(hR, 'type', 'line');
set(hline,'LineStyle','--', 'LineWidth', 1);
set(hline(11),'LineWidth',2,'LineStyle','-');
set(hline,'LineStyle','-', 'LineWidth', 1);
% set(hline(11),'LineWidth',2,'LineStyle','-');
saveas(hR,[obj.outputDirectory,'\measurement_result_R'],'jpg')
saveas(hR,[obj.outputDirectory,'\measurement_result_R'],'fig')
......
......@@ -77,7 +77,7 @@ guidata(hObject, handles);
global handlesg;
handlesg = handles;
image1=imread('logo.png');
image1=imread('ita_toolbox_logo.png');
axes(handles.logoAxes);
imshow(image1);
handles.currentAxes(1) = axes('tag', 'ax1');
......@@ -360,10 +360,11 @@ if(handles.v2.measurementProperties.sourcePositions == 1)
title(handles.currentAxes(1), ['Signal-to-Noise Ratio in 1/3 octave bands, ' handles.v2.genMaterialString(),...
', fftdegree = ',num2str(measurementProperties.samples)], 'FontSize', 9);
hline = findobj(gcf, 'type', 'line');
set(hline,'LineStyle','--', 'LineWidth', 1);
set(hline([2:4,21:22]),'LineWidth',2,'LineStyle','-');
% set(hline,'LineStyle','--', 'LineWidth', 1);
set(hline([3:4]),'LineWidth',2,'LineStyle','-');
ylim([0 80]);
hlegend = findobj(gcf,'Type','axes','Tag','legend');
set(hlegend, 'Location', 'best');
set(handles.gui, 'Name', 'V2 Laboratory: Airborne Sound Insulation');
% ask user if he wants to continue (yes, no)
......@@ -423,10 +424,12 @@ elseif(handles.v2.measurementProperties.sourcePositions > 1)
% move legends out of the way
hl = findobj(handles.gui, 'Tag', 'legend');
set(hl(2), 'Position', [0.839 0.6680 0.1431 0.2638]);
set(hl(1), 'Position', [0.806 0.322 0.1756 0.2638]);
set(hl(2), 'Position', [0.28 0.6680 0.1431 0.2638]);
set(hl(1), 'Position', [0.28 0.322 0.1756 0.2638]);
ax1 = handles.currentAxes(1);
ax2 = handles.currentAxes(2);
% move axes to a figure, s.t. it can be passed to export_fig, make it
% look good and temporarily save it
fh = figure();
......@@ -436,12 +439,12 @@ elseif(handles.v2.measurementProperties.sourcePositions > 1)
set(ha1, 'position', [50 350 940 250]);
hxlbl1 = get(ha1, 'XLabel');
set(hxlbl1, 'visible', 'off');
hla1 = copyobj(hl(2), fh);
hla1 = copyobj([hl(1) ax1],fh);
set(hla1, 'position', [0.79 0.6 0.1760 0.3208])
ha2 = copyobj(handles.currentAxes(2), fh);
set(ha2, 'units', 'pixel');
set(ha2, 'position', [50 50 940 250]);
hla2 = copyobj(hl(1), fh);
hla2 = copyobj(hl(2), fh);
set(hla2, 'position', [0.79 0.12 0.1760 0.3208])
export_fig(fh, fullfile(pwd, 'temp.jpg'), '-painters')
%ita_savethisplot(handles.gui,fullfile(pwd,'temp.fig'),'resolution',300);
......@@ -486,8 +489,11 @@ ylabel(handles.currentAxes(1), 'Sound insulation [dB]', 'FontSize', 9);
xlabel(handles.currentAxes(1), 'Frequency [Hz]', 'FontSize', 9);
% ... and the reference curve
hold(handles.currentAxes(1), 'on');
h = plot(handles.currentAxes(1), handles.v2.R.freqVector(:,1), 20*log10(handles.v2.soundInsulationCurve), 'r', 'LineWidth', 2);
legend(handles.currentAxes(1), 'R measured', 'R calculated (mass law)', 'Shifted reference curve', 'Location', 'South');
ref_values = 20*log10(handles.v2.soundInsulationCurve);
ref_freqs = ~isnan(ref_values)
h = plot(handles.currentAxes(1), handles.v2.R.freqVector(ref_freqs,1), ref_values(ref_freqs), 'r', 'LineWidth', 2, 'Color', 'g');
hLegend = legend(handles.currentAxes(1),'R measured', 'R calculated (mass law)', 'Shifted reference curve', 'Location', 'South');
ylim('auto');
set(handles.gui, 'Name', 'V2 Laboratory: Airborne Sound Insulation');
str = strcat('Measurement complete. Sound Insulation Index at 500Hz = ', num2str(handles.v2.soundInsulationIndex), 'dB.');
......
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