function varargout = stf_sim_v2(varargin)
% STF_SIM_V2 M-file for stf_sim_v2.fig
% STF_SIM_V2, by itself, creates a new STF_SIM_V2 or raises the existing
% singleton*.
%
% H = STF_SIM_V2 returns the handle to a new STF_SIM_V2 or the handle to
% the existing singleton*.
%
% STF_SIM_V2('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in STF_SIM_V2.M with the given input arguments.
%
% STF_SIM_V2('Property','Value',...) creates a new STF_SIM_V2 or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before stf_sim_v2_OpeningFunction gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to stf_sim_v2_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help stf_sim_v2
% Last Modified by GUIDE v2.5 13-Nov-2007 17:41:20
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @stf_sim_v2_OpeningFcn, ...
'gui_OutputFcn', @stf_sim_v2_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before stf_sim_v2 is made visible.
function stf_sim_v2_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to stf_sim_v2 (see VARARGIN)
% Choose default command line output for stf_sim_v2
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes stf_sim_v2 wait for user response (see UIRESUME)
% uiwait(handles.figure1);
load 'utils\wall_data.mat';
load 'utils\freqs.mat';
axes(handles.wall_axes);
on_screen = wall_stuffing{1};
text = wall_stuffing{2};
wall_data = wall_stuffing{3};
val = wall_data{on_screen(1), 2};
plot(freq_walls, 1-val, 'MarkerEdgeColor','r','MarkerFaceColor','b','MarkerSize',3);
xlabel('frequency - hz')
ylabel('Reflection');
title('Wall Frequency Response');
set(gca, 'ytick', 0:0.1:1);
for i=0:1:10
ytcklbl{i+1} = [num2str(i*10) '%'];
end
set(gca, 'yticklabel', ytcklbl);
axis([0 8000 -0.2 1.2]);
% % % load wall_data;
on_screen = wall_stuffing{1};
text_ = wall_stuffing{2};
wall_data = wall_stuffing{3};
set(handles.search_text, 'string', text_);
% load wall_data;
% on_screen = wall_stuffing{1};
% text = wall_stuffing{2};
% wall_data = wall_stuffing{3};
wall_data = wall_data(on_screen, :);
for i=1:size(wall_data, 1)
dum = [num2str(on_screen(i)) ' - ' wall_data{i, 1}];
wall{i, 1} = dum;
end
set(handles.wall_list, 'string', wall);
%puts a temporary room
room = 'rooms\basic_room.mig';
room_stuff = infofromfile(room);
src = room_stuff{6};
save 'temp\temp_room_stuff.mat' room_stuff;
save 'temp\temp_mod_room_stuff.mat' room_stuff;
set(handles.room_name, 'string', room_stuff{1});
wall_coor = room_stuff{2}/100;
wall_coor(:, 2) = wall_coor(:, 2)*-1;
wall_coor(size(wall_coor, 1)+1, :) = wall_coor(1, :);
wall_coor_x = wall_coor(1:size(wall_coor, 1), 1);
wall_coor_z = wall_coor(1:size(wall_coor, 1), 2)*-1;
ceil_coor = room_stuff{4}/100;
ceil_coor = ceil_coor(1);
floor_coor = room_stuff{5}/100;
floor_coor = floor_coor(1);
% set the axis - labels correctly for each of the three graphs
minx = min(wall_coor(:, 1));
maxx = max(wall_coor(:, 1));
minz = min(wall_coor(:, 2));
maxz = max(wall_coor(:, 2));
intx = 1;
while (maxx-minx)/intx>=10
intx=intx*2;
end
while (maxx-minx)/intx<5
intx=intx/2;
end
intz = 1;
while (maxz-minz)/intz>=10
intz=intz*2;
end
while (maxz-minz)/intz<5
intz=intz/2;
end
%main graph
axes(handles.main_axes)
newplot
set(gca, 'xtick', floor(minx):intx:ceil(maxx))
set(gca, 'ytick', floor(minz):intz:ceil(maxz));
dum = floor(minz):intz:ceil(maxz);
for i=1:length(dum)
dummy{i} = num2str(-1*dum(i));
end
set(gca, 'yticklabel', dummy);
axis([minx-0.2 maxx+0.2 minz-0.2 maxz+0.2])
%xy graph
axes(handles.xy_axes)
newplot
set(gca, 'xtick', floor(minx):intx:ceil(maxx));
set(gca, 'ytick', [floor_coor ceil_coor]);
axis([minx-0.2 maxx+0.2 floor_coor-0.1 ceil_coor+0.1])
%zy graph
minz = min(wall_coor_z);
maxz = max(wall_coor_z);
axes(handles.zy_axes)
newplot
set(gca, 'xtick', floor(minz):intz:ceil(maxz));
set(gca, 'ytick', [floor_coor ceil_coor]);
axis([minz-0.2 maxz+0.2 floor_coor-0.1 ceil_coor+0.1])
place_room_stuff;
plot_room_in_figure;
% --- Outputs from this function are returned to the command line.
function varargout = stf_sim_v2_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes on button press in mirimage.
function mirimage_Callback(hObject, eventdata, handles)
% hObject handle to mirimage (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
system('utils\mirimage');
% --- Executes on button press in load_room.
function load_room_Callback(hObject, eventdata, handles)
% hObject handle to load_room (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[roomfile, roompath] = uigetfile('*.mig', 'Choose Room File');
if roomfile==0
warndlg('No File Chosen','Load Room')
return
end
room=strcat(roompath, roomfile);
room_stuff = infofromfile(room);
src = room_stuff{6};
save 'temp\temp_room_stuff.mat' room_stuff;
save 'temp\temp_mod_room_stuff.mat' room_stuff;
% % % % % set(handles.room_name, 'string', room_stuff{1});
% % % % % wall_coor = room_stuff{2}/100;
% % % % % wall_coor(:, 2) = wall_coor(:, 2)*-1;
% % % % % wall_coor(size(wall_coor, 1)+1, :) = wall_coor(1, :);
% % % % % wall_coor_x = wall_coor(1:size(wall_coor, 1), 1);
% % % % % wall_coor_z = wall_coor(1:size(wall_coor, 1), 2)*-1;
% % % % % ceil_coor = room_stuff{4}/100;
% % % % % ceil_coor = ceil_coor(1);
% % % % % floor_coor = room_stuff{5}/100;
% % % % % floor_coor = floor_coor(1);
% % % % % % set the axis - labels correctly for each of the three graphs
% % % % % minx = min(wall_coor(:, 1));
% % % % % maxx = max(wall_coor(:, 1));
% % % % % minz = min(wall_coor(:, 2));
% % % % % maxz = max(wall_coor(:, 2));
% % % % % intx = 1;
% % % % % while (maxx-minx)/intx>=10
% % % % % intx=intx*2;
% % % % % end
% % % % % while (maxx-minx)/intx<5
% % % % % intx=intx/2;
% % % % % end
% % % % % intz = 1;
% % % % % while (maxz-minz)/intz>=10
% % % % % intz=intz*2;
% % % % % end
% % % % % while (maxz-minz)/intz<5
% % % % % intz=intz/2;
% % % % % end
% % % % % %main graph
% % % % % axes(handles.main_axes)
% % % % % newplot
% % % % % set(gca, 'xtick', floor(minx):intx:ceil(maxx))
% % % % % set(gca, 'ytick', floor(minz):intz:ceil(maxz));
% % % % % dum = floor(minz):intz:ceil(maxz);
% % % % % for i=1:length(dum)
% % % % % dummy{i} = num2str(-1*dum(i));
% % % % % end
% % % % % set(gca, 'yticklabel', dummy);
% % % % % axis([minx-0.2 maxx+0.2 minz-0.2 maxz+0.2])
% % % % % %xy graph
% % % % % axes(handles.xy_axes)
% % % % % newplot
% % % % % set(gca, 'xtick', floor(minx):intx:ceil(maxx));
% % % % % set(gca, 'ytick', [floor_coor ceil_coor]);
% % % % % axis([minx-0.2 maxx+0.2 floor_coor-0.1 ceil_coor+0.1])
% % % % % %zy graph
% % % % % minz = min(wall_coor_z);
% % % % % maxz = max(wall_coor_z);
% % % % % axes(handles.zy_axes)
% % % % % newplot
% % % % % set(gca, 'xtick', floor(minz):intz:ceil(maxz));
% % % % % set(gca, 'ytick', [floor_coor ceil_coor]);
% % % % % axis([minz-0.2 maxz+0.2 floor_coor-0.1 ceil_coor+0.1])
place_room_stuff;
plot_room_in_figure;
function room_name_Callback(hObject, eventdata, handles)
% hObject handle to room_name (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of room_name as text
% str2double(get(hObject,'String')) returns contents of room_name as a double
% --- Executes during object creation, after setting all properties.
function room_name_CreateFcn(hObject, eventdata, handles)
% hObject handle to room_name (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on selection change in wall_list.
function wall_list_Callback(hObject, eventdata, handles)
% hObject handle to wall_list (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = get(hObject,'String') returns wall_list contents as cell array
% contents{get(hObject,'Value')} returns selected item from wall_list
load 'utils\freqs.mat';
load 'utils\wall_data.mat';
on_screen = wall_stuffing{1};
text = wall_stuffing{2};
wall_data = wall_stuffing{3};
wall_data = wall_data(on_screen, :);
sel = get(hObject, 'Value');
val = wall_data{sel, 2};
axes(handles.wall_axes);
plot(freq_walls, 1-val, 'MarkerEdgeColor','r','MarkerFaceColor','b','MarkerSize',3);
xlabel('frequency - hz')
ylabel('Reflection');
title('Wall Frequency Response');
set(gca, 'ytick', 0:0.1:1);
for i=0:1:10
ytcklbl{i+1} = [num2str(i*10) '%'];
end
set(gca, 'yticklabel', ytcklbl);
axis([0 8000 -0.2 1.2]);
% --- Executes during object creation, after setting all properties.
function wall_list_CreateFcn(hObject, eventdata, handles)
% hObject handle to wall_list (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: listbox controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes during object creation, after setting all properties.
function wall_axes_CreateFcn(hObject, eventdata, handles)
% hObject handle to wall_axes (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: place code in OpeningFcn to populate wall_axes
% --- Executes on selection change in wall_id_label.
function wall_id_label_Callback(hObject, eventdata, handles)
% hObject handle to wall_id_label (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = get(hObject,'String') returns wall_id_label contents as cell array
% contents{get(hObject,'Value')} returns selected item from wall_id_label
load 'temp\temp_mod_room_stuff.mat';
plot_room_in_figure;
% --- Executes during object creation, after setting all properties.
function wall_id_label_CreateFcn(hObject, eventdata, handles)
% hObject handle to wall_id_label (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: listbox controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in change_id.
function change_id_Callback(hObject, eventdata, handles)
% hObject handle to change_id (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
load 'utils\wall_data.mat';
on_screen = wall_stuffing{1};
text = wall_stuffing{2};
wall_data = wall_stuffing{3};
wall_ind = get(handles.wall_id_label, 'value');
wall_list = get(handles.wall_id_label, 'string');
wall_type = get(handles.wall_list, 'value');
wall_type = on_screen(wall_type);
for i=1:length(wall_ind)
dum = wall_list{wall_ind(i)};
p=1;
while strcmp(dum(p), '-')~=1
p=p+1;
end
dum = [dum(1:p+1) num2str(wall_type)];
wall_list{wall_ind(i)}=dum;
end
set(handles.wall_id_label, 'string', wall_list);
load 'temp\temp_mod_room_stuff.mat';
for i=1:length(wall_list)-2
dum = wall_list{i};
p=1;
while strcmp(dum(p), '-')~=1
p=p+1;
end
wall_id_change(i, 1) = str2num(dum(1:p-1));
wall_id_change(i, 2) = str2num(dum(p+1:length(dum)));
end
i=length(wall_list)-1;
dum = wall_list{i};
p=1;
while strcmp(dum(p), '-')~=1
p=p+1;
end
ceil_change = room_stuff{4};
ceil_change(2) = str2num(dum(p+1:length(dum)));
i=length(wall_list);
dum = wall_list{i};
p=1;
while strcmp(dum(p), '-')~=1
p=p+1;
end
floor_change = room_stuff{5};
floor_change(2) = str2num(dum(p+1:length(dum)));
room_stuff{3} = wall_id_change;
room_stuff{4} = ceil_change;
room_stuff{5} = floor_change;
save 'temp\temp_mod_room_stuff.mat' room_stuff;
% --- Executes on selection change in src_list.
function src_list_Callback(hObject, eventdata, handles)
% hObject handle to src_list (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = get(hObject,'String') returns src_list contents as cell array
% contents{get(hObject,'Value')} returns selected item from src_list
load 'temp\temp_mod_room_stuff.mat';
plot_room_in_figure;
% --- Executes during object creation, after setting all properties.
function src_list_CreateFcn(hObject, eventdata, handles)
% hObject handle to src_list (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: listbox controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in add_src.
function add_src_Callback(hObject, eventdata, handles)
% hObject handle to add_src (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
prompt = {'x', 'y', 'z', 'az', 'el'};
dum = inputdlg(prompt, 'Enter Source Info', 1);
if size(dum, 1)==0
warndlg('Add Source Cancelled','Add Source');
return
end
load 'temp\temp_mod_room_stuff.mat';
src = room_stuff{6};
src(size(src, 1)+1, :) = [str2num(dum{1}) str2num(dum{2}) str2num(dum{3})]*100;
room_stuff{6} = src;
az = room_stuff{8};
az{length(az)+1} = str2num(dum{4});
room_stuff{8} = az;
el = room_stuff{9};
el{length(el)+1} = str2num(dum{5});
room_stuff{9} = el;
save 'temp\temp_mod_room_stuff.mat' room_stuff;
place_room_stuff;
plot_room_in_figure;
% --- Executes on button press in rem_src.
function rem_src_Callback(hObject, eventdata, handles)
% hObject handle to rem_src (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
list = get(handles.src_list, 'string');
if size(list, 1)<2
errordlg('Please Add a Source Before Removing the Last One');
return
end
val = get(handles.src_list, 'value');
load 'temp\temp_mod_room_stuff.mat';
src = room_stuff{6};
az = room_stuff{8};
el = room_stuff{9};
l = size(src, 1);
l = [1:l];
for i=1:length(val)
l = find(l~=val(i));
src = src(l, :);
l=[1:length(l)];
val = val-1;
end
src = src(l, :);
room_stuff{6} = src;
az = az(l);
room_stuff{8} = az;
el = el(l);
room_stuff{9} = el;
save 'temp\temp_mod_room_stuff.mat' room_stuff;
place_room_stuff;
plot_room_in_figure;
% --- Executes on selection change in mic_list.
function mic_list_Callback(hObject, eventdata, handles)
% hObject handle to mic_list (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = get(hObject,'String') returns mic_list contents as cell array
% contents{get(hObject,'Value')} returns selected item from mic_list
load 'temp\temp_mod_room_stuff.mat';
plot_room_in_figure;
% --- Executes during object creation, after setting all properties.
function mic_list_CreateFcn(hObject, eventdata, handles)
% hObject handle to mic_list (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: listbox controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in add_mic.
function add_mic_Callback(hObject, eventdata, handles)
% hObject handle to add_mic (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
prompt = {'x', 'y', 'z'};
dum = inputdlg(prompt, 'Enter Mic Info', 1);
if size(dum, 1)==0
warndlg('Add Mic Cancelled','Add Mic')
return
end
load 'temp\temp_mod_room_stuff.mat';
mic = room_stuff{7};
mic(size(mic, 1)+1, :) = [str2num(dum{1}) str2num(dum{2}) str2num(dum{3})]*100;
room_stuff{7} = mic;
save 'temp\temp_mod_room_stuff.mat' room_stuff;
place_room_stuff;
plot_room_in_figure;
% --- Executes on button press in add_batch_mic.
function add_batch_mic_Callback(hObject, eventdata, handles)
% hObject handle to add_batch_mic (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[file, path] = uigetfile('*.mat','Please Select - Make sure the variable is named batch_mics');
if file==0
warndlg('Add Batch Cancelled','Add Batch')
return
end
eval(['load ''' strcat(path, file) '''']);
if size(batch_mics, 2)>3
batch_mics = batch_mics';
end
load 'temp\temp_mod_room_stuff.mat';
mic = room_stuff{7};
s = size(mic, 1);
b = size(batch_mics, 1);
mic(s+1:s+b, :) = batch_mics*100;
room_stuff{7} = mic;
save 'temp\temp_mod_room_stuff.mat' room_stuff;
place_room_stuff;
plot_room_in_figure;
% --- Executes on button press in rem_mic.
function rem_mic_Callback(hObject, eventdata, handles)
% hObject handle to rem_mic (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
list = get(handles.mic_list, 'string');
if size(list, 1)<2
errordlg('Please Add a Microphone Before Removing the Last One');
return
end
val = get(handles.mic_list, 'value');
load 'temp\temp_mod_room_stuff.mat';
mic = room_stuff{7};
l = size(mic, 1);
l = [1:l];
for i=1:length(val)
l = find(l~=val(i));
mic = mic(l, :);
l=[1:length(l)];
val = val-1;
end
room_stuff{7} = mic;
save 'temp\temp_mod_room_stuff.mat' room_stuff;
place_room_stuff;
plot_room_in_figure;
% --- Executes on button press in save_room.
function save_room_Callback(hObject, eventdata, handles)
% hObject handle to save_room (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[file, path] = uiputfile('*.mig', 'Save Current Room Config');
if file==0
warndlg('Save Cancelled','Save Room')
return
end
fid = fopen(strcat(path, file), 'w');
load 'temp\temp_mod_room_stuff.mat';
count = fwrite(fid, 'KenS', 'char');
wall_coor = room_stuff{2};
wall_id = room_stuff{3};
numwalls = size(wall_coor, 1);
count = fwrite(fid, numwalls, 'int');
for i=1:numwalls
count = fwrite(fid, wall_coor(i, :), 'float');
count = fwrite(fid, wall_id(i, :), 'int');
end
ceil = room_stuff{4};
floor = room_stuff{5};
count = fwrite(fid, ceil(1)*-1, 'float');
count = fwrite(fid, floor(1)*-1, 'float');
count = fwrite(fid, ceil(2), 'int');
count = fwrite(fid, floor(2), 'int');
src = room_stuff{6};
s = size(src, 1);
mic = room_stuff{7};
m = size(mic, 1);
count = fwrite(fid, s+m, 'long');
for i=1:s+m
if i<=s
dum=src(i, :);
type=0;
else
dum=mic(i-s, :);
type=1;
end
dum(2) = -1*dum(2);
dum(2:3) = fliplr(dum(2:3));
count = fwrite(fid, dum, 'float');
count = fwrite(fid, type, 'long');
end
az = room_stuff{8};
el = room_stuff{9};
for i=1:s
count = fwrite(fid, az{i}, 'float');
count = fwrite(fid, el{i}, 'float');
end
fclose(fid);
save 'temp\temp_room_stuff.mat' room_stuff;
set(handles.room_name, 'string', strcat(path, file));
function samp_Callback(hObject, eventdata, handles)
% hObject handle to samp (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of samp as text
% str2double(get(hObject,'String')) returns contents of samp as a double
% --- Executes during object creation, after setting all properties.
function samp_CreateFcn(hObject, eventdata, handles)
% hObject handle to samp (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function scan_Callback(hObject, eventdata, handles)
% hObject handle to scan (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of scan as text
% str2double(get(hObject,'String')) returns contents of scan as a double
% --- Executes during object creation, after setting all properties.
function scan_CreateFcn(hObject, eventdata, handles)
% hObject handle to scan (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in run_sim.
function run_sim_Callback(hObject, eventdata, handles)
% hObject handle to run_sim (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%create a temporary room file in case the current room is not saved
room='temp\temporary_room.mig';
fid = fopen(room, 'w');
load 'temp\temp_mod_room_stuff.mat';
count = fwrite(fid, 'KenS', 'char');
wall_coor = room_stuff{2};
wall_id = room_stuff{3};
numwalls = size(wall_coor, 1);
count = fwrite(fid, numwalls, 'int');
for i=1:numwalls
count = fwrite(fid, wall_coor(i, :), 'float');
count = fwrite(fid, wall_id(i, :), 'int');
end
ceil = room_stuff{4};
floor = room_stuff{5};
count = fwrite(fid, ceil(1)*-1, 'float');
count = fwrite(fid, floor(1)*-1, 'float');
count = fwrite(fid, ceil(2), 'int');
count = fwrite(fid, floor(2), 'int');
src = room_stuff{6};
s = size(src, 1);
mic = room_stuff{7};
m = size(mic, 1);
count = fwrite(fid, s+m, 'long');
for i=1:s+m
if i<=s
dum=src(i, :);
type=0;
else
dum=mic(i-s, :);
type=1;
end
dum(2) = -1*dum(2);
dum(2:3) = fliplr(dum(2:3));
count = fwrite(fid, dum, 'float');
count = fwrite(fid, type, 'long');
end
az = room_stuff{8};
el = room_stuff{9};
for i=1:s
count = fwrite(fid, az{i}, 'float');
count = fwrite(fid, el{i}, 'float');
end
fclose(fid);
save 'temp\temp_room_stuff.mat' room_stuff;
load 'temp\temp_mod_room_stuff.mat';
fs = str2num(get(handles.samp, 'string'));
fs_real = fs;
if fs~=20000
fs = 20000;
end
scan_dist=str2num(get(handles.scan, 'string'));
srcs = get(handles.src_list, 'value');
mics = get(handles.mic_list, 'value');
mic_locs = room_stuff{7}/100;
mic_locs = mic_locs(mics, :);
src_locs = room_stuff{6}/100;
src_locs = src_locs(srcs, :);
az_list = room_stuff{8};
az_list = az_list(srcs);
el_list = room_stuff{9};
el_list = el_list(srcs);
wall_stuff = room_stuff{3};
ceiling = room_stuff{4};
flooring = room_stuff{5};
wall_stuff = wall_stuff(:, 2);
wall_stuff(length(wall_stuff)+1) = ceiling(2);
wall_stuff(length(wall_stuff)+1) = flooring(2);
wall_index = wall_stuff(1);
p=1;
for i=2:length(wall_stuff);
if length(find(wall_index==wall_stuff(i)))==0
p=p+1;
wall_index(p) = wall_stuff(i);
end
end
load 'utils\wall_data.mat'
wall_data = wall_stuffing{3};
for i=1:length(wall_index)
wall_coeffs(i, :) = 1-wall_data{wall_index(i), 2};
end
% wall_coeffs = 1-wall_data(wall_index, :);
for srcind=1:size(src_locs, 1)
source = src_locs(srcind, :);
az_or = az_list{srcind};
el_or = el_list{srcind};
stf_r_s;
end
% % % % % % now all responses are created let's export them
checkLabels = cell(1, size(src_locs, 1));
varNames = cell(1, size(src_locs, 1));
dum = 'items={';
for srcind=1:size(src_locs, 1)
checkLabels{srcind} = ['Export Responses for Source ' num2str(srcind)];
varNames{srcind} = ['src' num2str(srcind)];
dum = strcat(dum, 'output_src', num2str(srcind), ',');
end
dum = strcat(dum, '};');
eval(dum);
export2wsdlg(checkLabels,varNames,items,'Save Responses to Workspace');
% % % % % and write them into a separate file
fid = fopen('output\output.txt', 'wt');
for srcind=1:size(src_locs, 1)
count = fprintf(fid, 'Source %g \n-----------\n', srcind);
for mic_ind=1:size(mic_locs, 1)
eval(strcat('avram=', 'output_src', num2str(srcind),'(', num2str(mic_ind), ', :);'));
count = fprintf(fid, 'Mic %g \n', mic_ind);
count = fprintf(fid, 'Dist %3.4f Az %3.4f El %3.4f\n', avram{1}, avram{2}, avram{3});
count = fprintf(fid, 'Direct Resp\n');
count = fprintf(fid, '%1.4f ', avram{4});
count = fprintf(fid, '\n');
count = fprintf(fid, 'Total Resp\n');
count = fprintf(fid, '%1.4f ', avram{5});
count = fprintf(fid, '\n');
end
count = fprintf(fid, '\n\n');
end
fclose(fid);
% --- Executes on button press in mod_source.
function mod_source_Callback(hObject, eventdata, handles)
% hObject handle to mod_source (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
load 'temp\temp_mod_room_stuff.mat'
sel = get(handles.src_list, 'value')
src = room_stuff{6};
az = room_stuff{8};
el = room_stuff{9};
for i=1:length(sel)
def{1} = num2str(src(sel(i), 1)/100);
def{2} = num2str(src(sel(i), 2)/100);
def{3} = num2str(src(sel(i), 3)/100);
def{4} = num2str(az{sel(i)});
def{5} = num2str(el{sel(i)});
prompt = {'x', 'y', 'z', 'az', 'el'};
dum = inputdlg(prompt, 'Enter Source Info', 1, def);
if size(dum, 1)==0
warndlg('Modify Source Cancelled - None of the changes taken effect','Modify Source');
return
end
src(sel(i), 1) = str2num(dum{1})*100;
src(sel(i), 2) = str2num(dum{2})*100;
src(sel(i), 3) = str2num(dum{3})*100;
az{sel(i)} = str2num(dum{4});
el{sel(i)} = str2num(dum{5});
end
room_stuff{6} = src;
room_stuff{8} = az;
room_stuff{9} = el;
save 'temp\temp_mod_room_stuff.mat' room_stuff;
place_room_stuff;
plot_room_in_figure;
function search_text_Callback(hObject, eventdata, handles)
% hObject handle to search_text (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of search_text as text
% str2double(get(hObject,'String')) returns contents of search_text as a double
load 'utils\wall_data.mat';
load 'utils\freqs.mat';
on_screen = wall_stuffing{1};
text = wall_stuffing{2};
wall_data = wall_stuffing{3};
clear on_screen
text = get(handles.search_text, 'string');
s = length(text);
if s>0
p=0;
for i=1:size(wall_data, 1)
wall_name = wall_data{i, 1};
q=0;
while q+s<=length(wall_name)
if strncmpi(wall_name(q+1:q+s), text, s)==1
p=p+1;
on_screen(p) = i;
q = length(wall_name);
else
q=q+1;
end
end
end
else
on_screen = [1:size(wall_data, 1)];
end
wall_stuffing{1} = on_screen;
wall_stuffing{2} = text;
for i=1:length(on_screen)
dum = num2str(on_screen(i));
dum = [dum ' - ' wall_data{on_screen(i), 1}];
list{i, 1} = dum;
end
set(handles.wall_list, 'string', list);
save 'utils\wall_data.mat' wall_stuffing;
set(handles.wall_list, 'value', 1);
axes(handles.wall_axes)
val = wall_data{on_screen(1), 2};
plot(freq_walls, 1-val, 'MarkerEdgeColor','r','MarkerFaceColor','b','MarkerSize',3);
xlabel('frequency - hz')
ylabel('Reflection');
title('Wall Frequency Response');
set(gca, 'ytick', 0:0.1:1);
for i=0:1:10
ytcklbl{i+1} = [num2str(i*10) '%'];
end
set(gca, 'yticklabel', ytcklbl);
axis([0 8000 -0.2 1.2]);
% --- Executes during object creation, after setting all properties.
function search_text_CreateFcn(hObject, eventdata, handles)
% hObject handle to search_text (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in pushbutton12.
function pushbutton12_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton12 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on selection change in wallVertex.
function wallVertex_Callback(hObject, eventdata, handles)
% hObject handle to wallVertex (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = get(hObject,'String') returns wallVertex contents as cell array
% contents{get(hObject,'Value')} returns selected item from wallVertex
load 'temp\temp_mod_room_stuff.mat';
plot_room_in_figure;
% --- Executes during object creation, after setting all properties.
function wallVertex_CreateFcn(hObject, eventdata, handles)
% hObject handle to wallVertex (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: listbox controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in addVertex.
function addVertex_Callback(hObject, eventdata, handles)
% hObject handle to addVertex (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
load 'temp\temp_mod_room_stuff.mat'
wall_coor = room_stuff{2};
wall_data = room_stuff{3};
sel = get(handles.wallVertex, 'value');
for i=1:length(sel)
l = size(wall_coor, 1);
chosen = sel(i)+i-1;%updates the number to the increased wall_data
if chosen>l
errordlg('Adding a vertex after floor or ceiling is not possible', 'Add Vertex');
return
end
prompt = {'x', 'z'};
dum = inputdlg(prompt, 'Enter Vertex Coordinates (m)', 1);
%update wall_coor
wall_coor(chosen+2:l+1, :) = wall_coor(chosen+1:l, :);
wall_coor(chosen+1, :) = [str2num(dum{1})*100 str2num(dum{2})*100];
%update wall_data
wall_data(chosen+2:l+1, :) = wall_data(chosen+1:l, :);
wall_data(chosen+1, :) = [chosen+1 1];
wall_data(chosen+2:l, 1) = wall_data(chosen+2:l, 1)+1;
end
room_stuff{2} = wall_coor;
room_stuff{3} = wall_data;
save 'temp\temp_mod_room_stuff.mat' room_stuff;
place_room_stuff;
plot_room_in_figure;
% --- Executes on button press in modifyVertex.
function modifyVertex_Callback(hObject, eventdata, handles)
% hObject handle to modifyVertex (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
load 'temp\temp_mod_room_stuff.mat'
wall_coor = room_stuff{2};
ceil_ = room_stuff{4};
floor_ = room_stuff{5};
l = size(wall_coor, 1);
sel = get(handles.wallVertex, 'value');
for i=1:length(sel)
chosen = sel(i);
if chosen-l==1
prompt = {'Ceiling'};
dum = inputdlg(prompt, 'Enter Ceiling Height (m)', 1);
ceil_(1) = str2num(dum{1})*100;
elseif chosen-l==2
prompt = {'Floor'};
dum = inputdlg(prompt, 'Enter Floor Coordinate (m)', 1);
floor_(1) = str2num(dum{1})*100;
else
prompt = {'x', 'z'};
dum = inputdlg(prompt, 'Enter Vertex Coordinates (m)', 1);
wall_coor(chosen, :) = [str2num(dum{1})*100 str2num(dum{2})*100];
end
end
room_stuff{2} = wall_coor
room_stuff{4} = ceil_;
room_stuff{5} = floor_;
save 'temp\temp_mod_room_stuff.mat'
place_room_stuff;
plot_room_in_figure;
% --- Executes on button press in deleteVertex.
function deleteVertex_Callback(hObject, eventdata, handles)
% hObject handle to deleteVertex (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
load 'temp\temp_mod_room_stuff.mat'
wall_coor = room_stuff{2};
wall_data = room_stuff{3};
sel = get(handles.wallVertex, 'value');
if size(wall_coor, 1)-length(sel)<=2
errordlg('You must have at least 3 vertices, please modify instead of delete', 'Delete Vertex')
return
end
sel = get(handles.wallVertex, 'value');
for i=1:length(sel)
l = size(wall_coor, 1);
chosen = sel(i)-i+1;%updates the number to the decreased wall_data
if chosen-l==1
errordlg('You cannot delete the ceiling, please modify it to make changes', 'Delete Vertex')
return
elseif chosen-l==2
errordlg('You cannot delete the floor, please modify it to make changes', 'Delete Vertex')
return
end
wall_coor(chosen:l-1, :) = wall_coor(chosen+1:l, :);
wall_coor = wall_coor(1:l-1, :);
wall_data(chosen:l-1, :) = wall_data(chosen+1:l, :);
wall_data(chosen:l-2, 1) = wall_data(chosen:l-2, 1)-1;
wall_data = wall_data(1:l-1, :);
end
room_stuff{2} = wall_coor;
room_stuff{3} = wall_data;
save 'temp\temp_mod_room_stuff.mat' room_stuff;
place_room_stuff;
plot_room_in_figure;
% --- Executes on button press in newRoom.
function newRoom_Callback(hObject, eventdata, handles)
% hObject handle to newRoom (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
prompt = {'Number of Walls'};
dum = inputdlg(prompt, 'Please Enter the number of walls', 1);
num_of_walls = str2num(dum{1});
if num_of_walls<3
errordlg('Please Enter at least 3 walls', 'New Room');
return
end
%get info on the wall vertices
for i=1:num_of_walls
prompt = {'x', 'z'};
dum = inputdlg(prompt, strcat('Please Enter coordinates of wall ', num2str(i)), 1);
wall_coor(i, 1) = str2num(dum{1})*100;
wall_coor(i, 2) = str2num(dum{2})*100;
wall_data(i, 1) = mod(i, num_of_walls);
wall_data(i, 2) = 1;
end
%get info on ceiling
prompt = {'Ceiling'}
dum = inputdlg(prompt, 'Please enter ceiling height', 1)
ceil(1) = str2num(dum{1})*100;
ceil(2) = 1;
%get info on floor
prompt = {'Floor'}
dum = inputdlg(prompt, 'Please enter floor height', 1)
floor(1) = str2num(dum{1})*100;
floor(2) = 1;
prompt = {'Number of Sources'};
dum = inputdlg(prompt, 'Please Enter the number of Sources', 1);
num_of_src = str2num(dum{1});
if num_of_walls<1
errordlg('Please Enter at least 1 Source', 'New Room');
return
end
for i=1:num_of_src
prompt = {'x', 'y', 'z', 'az', 'el'};
dum = inputdlg(prompt, strcat('Please Enter for Source ', num2str(i)), 1);
src(i, :) = [str2num(dum{1})*100 str2num(dum{2})*100 str2num(dum{3})*100];
az{i} = str2num(dum{4});
el{i} = str2num(dum{5});
end
prompt = {'Number of Mics'};
dum = inputdlg(prompt, 'Please Enter the number of Mics', 1);
num_of_mic = str2num(dum{1});
if num_of_walls<1
errordlg('Please Enter at least 1 Mic', 'New Room');
return
end
for i=1:num_of_mic
prompt = {'x', 'y', 'z'};
dum = inputdlg(prompt, strcat('Please Enter for Mic ', num2str(i)), 1);
mic(i, :) = [str2num(dum{1})*100 str2num(dum{2})*100 str2num(dum{3})*100];
end
room_stuff{1} = '';
room_stuff{2} = wall_coor;
room_stuff{3} = wall_data;
room_stuff{4} = ceil;
room_stuff{5} = floor;
room_stuff{6} = src;
room_stuff{7} = mic;
room_stuff{8} = az;
room_stuff{9} = el;
save 'temp\temp_mod_room_stuff.mat' room_stuff;
place_room_stuff;
plot_room_in_figure;
% --- Executes on button press in useHuman.
function useHuman_Callback(hObject, eventdata, handles)
% hObject handle to useHuman (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of useHuman