\r
% Author: Guillaume Pellerin <guillaume.pellerin@cnam.fr>\r
\r
-% Last Modified by GUIDE v2.5 08-Apr-2008 16:23:22
+% Last Modified by GUIDE v2.5 08-Apr-2008 18:19:43
\r
% CNAQ, by itself, creates a new CNAQ or raises the existing\r
% singleton*.\r
set(handles.channels_in,'String','1|1 2|1 2 3|1 2 3 4|1 2 3 4 5 6 7 8');\r
set(handles.channels_out,'String','1|1 2|1 2 3|1 2 3 4|1 2 3 4 5 6 7 8');\r
\r
-set(handles.mes_type,'String','Transfert function|Impulse response');\r
+set(handles.analysis_type,'String','Default');\r
+set(handles.analysis_method,'String','Transfert function|Deconvolution');\r
+set(handles.analysis_domain,'String','Frequency|Time');\r
set(handles.in_on_off,'UserData',device);\r
set(handles.save_button,'UserData',latency);\r
\r
% MEASUREMENT\r
%============================================\r
\r
-function mes_type_Callback(hObject, eventdata, handles)\r
+function analysis_method_Callback(hObject, eventdata, handles)\r
\r
-function mes_type_CreateFcn(hObject, eventdata, handles)\r
+function analysis_method_CreateFcn(hObject, eventdata, handles)\r
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))\r
set(hObject,'BackgroundColor','white');\r
end\r
% set(handles.time_value,'String',num2str(time));\r
\r
\r
+
+
+% --- Executes on selection change in analysis_type.
+function analysis_type_Callback(hObject, eventdata, handles)
+% hObject handle to analysis_type (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 analysis_type contents as cell array
+% contents{get(hObject,'Value')} returns selected item from analysis_type
+
+
+% --- Executes during object creation, after setting all properties.
+function analysis_type_CreateFcn(hObject, eventdata, handles)
+% hObject handle to analysis_type (see GCBO)
+% eventdata reserved - to be defined in a future version of MATLAB
+% handles empty - handles not created until after all CreateFcns called
+
+% Hint: popupmenu 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 analysis_domain.
+function analysis_domain_Callback(hObject, eventdata, handles)
+% hObject handle to analysis_domain (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 analysis_domain contents as cell array
+% contents{get(hObject,'Value')} returns selected item from analysis_domain
+
+
+% --- Executes during object creation, after setting all properties.
+function analysis_domain_CreateFcn(hObject, eventdata, handles)
+% hObject handle to analysis_domain (see GCBO)
+% eventdata reserved - to be defined in a future version of MATLAB
+% handles empty - handles not created until after all CreateFcns called
+
+% Hint: popupmenu 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
+
+
f_s = get_fs(fs_id);
nbits = get_nbits(nb_id);
time = get(handles.time_gen,'Value');
- voices_out = get_voices_out(handles);
- %voice_first = voices_out(1);
- %voice_last = voices_out(length(voices_out));
+ ch_out_id = get(handles.channels_out,'Value');
+ channels_out = get_channels_in(ch_out_id);
gain_out = get(handles.gain_out,'Value');
gain_out = 10^(gain_out/20);
t = [0:1/f_s:time];
end
sig_out = [];
- for i=1:length(voices_out)
+ for i=1:length(channels_out)
sig_out(:,i) = sig';
end
% Matlab way (needs Data Acquisition Toolbox)
% ao = analogoutput('winsound', 0);
-% addchannel(ao, voices_out);
+% addchannel(ao, channels_out);
% set(ao, 'StandardSampleRates', 'Off');
% set(ao, 'SampleRate', f_s);
%
-function f_s = get_fs(fs_ind)
+function f_s = get_fs(fs_id)
- if fs_ind == 1
+ if fs_id == 1
f_s = 44100;
- elseif fs_ind == 2
+ elseif fs_id == 2
f_s = 48000;
- elseif fs_ind == 3
+ elseif fs_id == 3
f_s = 88200;
- elseif fs_ind == 4
+ elseif fs_id == 4
f_s = 96000;
- elseif fs_ind == 5
+ elseif fs_id == 5
f_s = 192000;
end
-function nbits = get_nbits(nb_ind)
+function nbits = get_nbits(nb_id)
- if nb_ind == 1
+ if nb_id == 1
nbits = 16;
- elseif nb_ind == 2
+ elseif nb_id == 2
nbits = 24;
end
-function [ri, spec] = get_spec_ri(f, sig_exc, sig_mes, f_s, mes_type)
+function [ri, spec] = get_spec_ri(f, sig_exc, sig_mes, f_s, method)
% Return the impulse response and the spectrum compute with the given method
- if mes_type == 1
+ if method == 1
% Frequency method
[ri, spec] = fonc_trans(f, sig_exc, sig_mes, f_s);
- elseif mes_type == 2
+ elseif method == 2
% Temporal method
[ri, spec] = RI_FT(f, sig_exc, sig_mes, f_s);
end
freq = 2*(f_max-f_min)/buffer;
f = [0:f_s/buffer:f_s/2];
f = f(1:length(f)-1);
- voices_in = get_voices_in(handles);
- voice_first = voices_in(1);
- voice_last = voices_in(length(voices_in));
+ ch_in_id = get(handles.channels_in,'Value');
+ channels_in = get_channels_in(ch_in_id);
+ channel_first = channels_in(1);
+ channel_last = channels_in(length(channels_in));
while get(handles.in_on_off,'Value') == 1
% TIME_GEN
%sig_in = wavrecord(buffer,f_s,2);
- sig_in = pa_wavrecord(voice_first, voice_last, buffer, f_s, device, 'asio');
+ sig_in = pa_wavrecord(channel_first, channel_last, buffer, f_s, device, 'asio');
sig_in = sig_in(:,1);
axes(handles.plot_in_temp);
cla;
username = get(handles.username,'String');
comment = get(handles.comment,'String');
id = get(handles.ID,'String');
- mes_type = get(handles.mes_type,'Value');
-
+ type = get(handles.analysis_type,'Value');
+ method = get(handles.analysis_method,'Value');
+ domain = get(handles.analysis_domain,'Value');
+
% Compute excitation spectrum
- [rep_imp_exc, spec_exc] = get_ri_spec(f, sig_exc, sig_exc, f_s, mes_type);
+ [rep_imp_exc, spec_exc] = get_ri_spec(f, sig_exc, sig_exc, f_s, method);
len_spec_exc = length(spec_exc);
spec_exc = spec_exc(1:len_spec_exc/2);
% Compute all Ris and specs
for i=1:n_col_sig_mes
- voice = num2str(i);
- [rep_imp_mes, spec_mes] = get_ri_spec(f, sig_exc, sig_mes(:,i), f_s, mes_type);
+ channel = num2str(i);
+ [rep_imp_mes, spec_mes] = get_ri_spec(f, sig_exc, sig_mes(:,i), f_s, method);
len_spec_mes = length(spec_mes);
spec_mes = spec_mes(1:len_spec_mes/2);
% Plot results
f_lin = [0:f_s/len_spec_mes:f_s/2];
f_lin = f_lin(1:length(f_lin)-1);
- plot_mes(t, f_lin, f_s, f_min, f_max, sig_exc, sig_mes(:,i), rep_imp_mes, spec_mes, spec_exc, id, voice, username, comment, i);
+ plot_mes(t, f_lin, f_s, f_min, f_max, sig_exc, sig_mes(:,i), rep_imp_mes, spec_mes, spec_exc, id, channel, username, comment, i, domain);
end
set(handles.close_button,'UserData',f_lin');
-function plot_mes(t, f, f_s, f_min, f_max, sig_exc, sig_mes, rep_imp_mes, spec_mes, spec_exc, id, channel, group, comment, i);\r
+function plot_mes(t, f, f_s, f_min, f_max, sig_exc, sig_mes, rep_imp_mes, spec_mes, spec_exc, id, channel, group, comment, i, domain);\r
\r
len_spec_mes = length(spec_mes);\r
%spec = spec(1:len_spec);\r
\r
-% Time\r
-figure;\r
-subplot(2,1,1);\r
-plot(t, sig_mes);\r
-%semilogx(t, sig_mes);\r
-axis([0 t(length(t)) min(sig_mes)-0.01 max(sig_mes)+0.01]);\r
-%axis([1 t(length(t)) min(sig_mes)-0.01 max(sig_mes)+0.01]);\r
-xlabel('Time (s)');\r
-ylabel('Amplitude');\r
-title(['Measured temporal signal (group: ' group ', id: ' id ', channel : ' channel ')']);\r
-grid on;\r
-\r
-subplot(2,1,2);\r
-len_ri = length(rep_imp_mes);\r
-t_ri = [(-len_ri)/(2*f_s):1/f_s:(len_ri)/(2*f_s)];\r
-%t_ri = [0:1/f_s:len_ri/f_s];\r
-t_ri = t_ri(1:length(t_ri)-1);\r
-plot(t_ri,rep_imp_mes);\r
-axis([-t_ri(len_ri) t_ri(len_ri) min(rep_imp_mes)-0.01 max(rep_imp_mes)+0.01]);\r
-xlabel('Time (s)');\r
-ylabel('Amplitude');\r
-title(['Measured impulse response (group: ' group ', id: ' id ', channel : ' channel ')']);\r
-grid on;\r
-\r
-\r
-% Freq\r
-f_max_list = find(f > f_max);\r
-f_max_ind = f_max_list(1);\r
-f_min_list = find(f < f_min);\r
-f_min_ind = f_min_list(length(f_min_list));\r
-\r
-figure;\r
-subplot(2,1,1);\r
-spec_mes_log = 10*log10(abs(spec_mes));\r
-semilogx(f, spec_mes_log);\r
-axis([f_min f_max min(spec_mes_log(f_min_ind:f_max_ind-1000))-6 max(spec_mes_log(f_min_ind:f_max_ind))+6]);\r
-xlabel('Frequency (Hz)');\r
-ylabel('Amplitude (dB)');\r
-title(['Modulus of the transfert function (group: ' group ', id: ' id ', channel : ' channel ')']);\r
-grid on;\r
-\r
-subplot(2,1,2);\r
-angle_exc = angle(spec_exc);\r
-angle_mes = angle(spec_mes);\r
-ang = unwrap(angle_mes - angle_exc) + 2*pi;\r
-semilogx(f, ang);\r
-axis([f_min f_max min(ang(f_min_ind:f_max_ind)) max(ang(f_min_ind:f_max_ind))]);\r
-grid on;\r
-xlabel('Fréquence (Hz)');\r
-ylabel('Phase (rad)');\r
-title(['Phasis of the transfert function (group: ' group ', id: ' id ', channel : ' channel ')']);\r
+if domain == 1\r
+ % Freq\r
+ f_max_list = find(f > f_max);\r
+ f_max_ind = f_max_list(1);\r
+ f_min_list = find(f < f_min);\r
+ f_min_ind = f_min_list(length(f_min_list));\r
+\r
+ figure;\r
+ subplot(2,1,1);\r
+ spec_mes_log = 10*log10(abs(spec_mes));\r
+ semilogx(f, spec_mes_log);\r
+ axis([f_min f_max min(spec_mes_log(f_min_ind:f_max_ind-1000))-6 max(spec_mes_log(f_min_ind:f_max_ind))+6]);\r
+ xlabel('Frequency (Hz)');\r
+ ylabel('Amplitude (dB)');\r
+ title(['Modulus of the transfert function (group: ' group ', id: ' id ', channel : ' channel ')']);\r
+ grid on;\r
+\r
+ subplot(2,1,2);\r
+ angle_exc = angle(spec_exc);\r
+ angle_mes = angle(spec_mes);\r
+ ang = unwrap(angle_mes - angle_exc) + 2*pi;\r
+ semilogx(f, ang);\r
+ axis([f_min f_max min(ang(f_min_ind:f_max_ind)) max(ang(f_min_ind:f_max_ind))]);\r
+ grid on;\r
+ xlabel('Fréquence (Hz)');\r
+ ylabel('Phase (rad)');\r
+ title(['Phasis of the transfert function (group: ' group ', id: ' id ', channel : ' channel ')']);\r
+\r
+elseif domain == 2\r
+ % Time\r
+ figure;\r
+ subplot(2,1,1);\r
+ plot(t, sig_mes);\r
+ %semilogx(t, sig_mes);\r
+ axis([0 t(length(t)) min(sig_mes)-0.01 max(sig_mes)+0.01]);\r
+ %axis([1 t(length(t)) min(sig_mes)-0.01 max(sig_mes)+0.01]);\r
+ xlabel('Time (s)');\r
+ ylabel('Amplitude');\r
+ title(['Measured temporal signal (group: ' group ', id: ' id ', channel : ' channel ')']);\r
+ grid on;\r
+\r
+ subplot(2,1,2);\r
+ len_ri = length(rep_imp_mes);\r
+ t_ri = [(-len_ri)/(2*f_s):1/f_s:(len_ri)/(2*f_s)];\r
+ %t_ri = [0:1/f_s:len_ri/f_s];\r
+ t_ri = t_ri(1:length(t_ri)-1);\r
+ plot(t_ri,rep_imp_mes);\r
+ axis([-t_ri(len_ri) t_ri(len_ri) min(rep_imp_mes)-0.01 max(rep_imp_mes)+0.01]);\r
+ xlabel('Time (s)');\r
+ ylabel('Amplitude');\r
+ title(['Measured impulse response (group: ' group ', id: ' id ', channel : ' channel ')']);\r
+ grid on;\r
+\r
+end\r
+\r
+\r
\r
f_min = str2double(get(handles.f_gen_min,'String'));
f_max = str2double(get(handles.f_gen_max,'String'));
time = get(handles.time_gen,'Value');
- voices_in = get_voices_in(handles);
+ channels_in = get_channels_in(handles);
gain_in = get(handles.gain_in,'Value');
- voices_out = get_voices_out(handles);
+ channels_out = get_channels_out(handles);
gain_out = get(handles.gain_out,'Value');
% Save it