From: yomguy Date: Tue, 8 Apr 2008 16:19:40 +0000 (+0000) Subject: * Global voice -> channel X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=351aec677366238398324f2d68d8c2c09bdf2f5b;p=cnaq.git * Global voice -> channel * Add analysis spec : type, method, domain git-svn-id: http://svn.parisson.org/svn/CNAQ/trunk@178 5fc3e0e6-29bc-4d03-b52b-c088cb822bde --- diff --git a/CNAQ.fig b/CNAQ.fig index d4f963f..45880fb 100644 Binary files a/CNAQ.fig and b/CNAQ.fig differ diff --git a/CNAQ.m b/CNAQ.m index d52b03b..9e30e41 100644 --- a/CNAQ.m +++ b/CNAQ.m @@ -34,7 +34,7 @@ function varargout = CNAQ(varargin) % Author: Guillaume Pellerin -% Last Modified by GUIDE v2.5 08-Apr-2008 16:23:22 +% Last Modified by GUIDE v2.5 08-Apr-2008 18:19:43 % CNAQ, by itself, creates a new CNAQ or raises the existing % singleton*. @@ -169,7 +169,9 @@ set(handles.sig_type,'String','Sinus|Chirp|White noise|Pink noise'); set(handles.channels_in,'String','1|1 2|1 2 3|1 2 3 4|1 2 3 4 5 6 7 8'); set(handles.channels_out,'String','1|1 2|1 2 3|1 2 3 4|1 2 3 4 5 6 7 8'); -set(handles.mes_type,'String','Transfert function|Impulse response'); +set(handles.analysis_type,'String','Default'); +set(handles.analysis_method,'String','Transfert function|Deconvolution'); +set(handles.analysis_domain,'String','Frequency|Time'); set(handles.in_on_off,'UserData',device); set(handles.save_button,'UserData',latency); @@ -357,9 +359,9 @@ function gen_on_off_Callback(hObject, eventdata, handles) % MEASUREMENT %============================================ -function mes_type_Callback(hObject, eventdata, handles) +function analysis_method_Callback(hObject, eventdata, handles) -function mes_type_CreateFcn(hObject, eventdata, handles) +function analysis_method_CreateFcn(hObject, eventdata, handles) if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end @@ -421,3 +423,51 @@ function load_Callback(hObject, eventdata, handless) % set(handles.time_value,'String',num2str(time)); + + +% --- 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 + + diff --git a/tools/generator.m b/tools/generator.m index f2165a3..af3801b 100644 --- a/tools/generator.m +++ b/tools/generator.m @@ -9,9 +9,8 @@ function generator(handles) 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]; @@ -32,13 +31,13 @@ function generator(handles) 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); % diff --git a/tools/get_fs.m b/tools/get_fs.m index 41815d4..e8be091 100644 --- a/tools/get_fs.m +++ b/tools/get_fs.m @@ -1,14 +1,14 @@ -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 diff --git a/tools/get_nbits.m b/tools/get_nbits.m index 8fae0f8..2b83943 100644 --- a/tools/get_nbits.m +++ b/tools/get_nbits.m @@ -1,8 +1,8 @@ -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 diff --git a/tools/get_ri_spec.m b/tools/get_ri_spec.m index 21efd8a..eff6c73 100644 --- a/tools/get_ri_spec.m +++ b/tools/get_ri_spec.m @@ -1,10 +1,10 @@ -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 diff --git a/tools/monitor.m b/tools/monitor.m index 0160c59..e19cee6 100644 --- a/tools/monitor.m +++ b/tools/monitor.m @@ -13,14 +13,15 @@ function monitor(handles) 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; diff --git a/tools/plot_main.m b/tools/plot_main.m index 38b3d43..5350094 100644 --- a/tools/plot_main.m +++ b/tools/plot_main.m @@ -18,23 +18,25 @@ function plot_main(handles) 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'); diff --git a/tools/plot_mes.m b/tools/plot_mes.m index 06d3ce2..77e2e7a 100644 --- a/tools/plot_mes.m +++ b/tools/plot_mes.m @@ -1,57 +1,62 @@ -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); +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); len_spec_mes = length(spec_mes); %spec = spec(1:len_spec); -% Time -figure; -subplot(2,1,1); -plot(t, sig_mes); -%semilogx(t, sig_mes); -axis([0 t(length(t)) min(sig_mes)-0.01 max(sig_mes)+0.01]); -%axis([1 t(length(t)) min(sig_mes)-0.01 max(sig_mes)+0.01]); -xlabel('Time (s)'); -ylabel('Amplitude'); -title(['Measured temporal signal (group: ' group ', id: ' id ', channel : ' channel ')']); -grid on; - -subplot(2,1,2); -len_ri = length(rep_imp_mes); -t_ri = [(-len_ri)/(2*f_s):1/f_s:(len_ri)/(2*f_s)]; -%t_ri = [0:1/f_s:len_ri/f_s]; -t_ri = t_ri(1:length(t_ri)-1); -plot(t_ri,rep_imp_mes); -axis([-t_ri(len_ri) t_ri(len_ri) min(rep_imp_mes)-0.01 max(rep_imp_mes)+0.01]); -xlabel('Time (s)'); -ylabel('Amplitude'); -title(['Measured impulse response (group: ' group ', id: ' id ', channel : ' channel ')']); -grid on; - - -% Freq -f_max_list = find(f > f_max); -f_max_ind = f_max_list(1); -f_min_list = find(f < f_min); -f_min_ind = f_min_list(length(f_min_list)); - -figure; -subplot(2,1,1); -spec_mes_log = 10*log10(abs(spec_mes)); -semilogx(f, spec_mes_log); -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]); -xlabel('Frequency (Hz)'); -ylabel('Amplitude (dB)'); -title(['Modulus of the transfert function (group: ' group ', id: ' id ', channel : ' channel ')']); -grid on; - -subplot(2,1,2); -angle_exc = angle(spec_exc); -angle_mes = angle(spec_mes); -ang = unwrap(angle_mes - angle_exc) + 2*pi; -semilogx(f, ang); -axis([f_min f_max min(ang(f_min_ind:f_max_ind)) max(ang(f_min_ind:f_max_ind))]); -grid on; -xlabel('Fréquence (Hz)'); -ylabel('Phase (rad)'); -title(['Phasis of the transfert function (group: ' group ', id: ' id ', channel : ' channel ')']); +if domain == 1 + % Freq + f_max_list = find(f > f_max); + f_max_ind = f_max_list(1); + f_min_list = find(f < f_min); + f_min_ind = f_min_list(length(f_min_list)); + + figure; + subplot(2,1,1); + spec_mes_log = 10*log10(abs(spec_mes)); + semilogx(f, spec_mes_log); + 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]); + xlabel('Frequency (Hz)'); + ylabel('Amplitude (dB)'); + title(['Modulus of the transfert function (group: ' group ', id: ' id ', channel : ' channel ')']); + grid on; + + subplot(2,1,2); + angle_exc = angle(spec_exc); + angle_mes = angle(spec_mes); + ang = unwrap(angle_mes - angle_exc) + 2*pi; + semilogx(f, ang); + axis([f_min f_max min(ang(f_min_ind:f_max_ind)) max(ang(f_min_ind:f_max_ind))]); + grid on; + xlabel('Fréquence (Hz)'); + ylabel('Phase (rad)'); + title(['Phasis of the transfert function (group: ' group ', id: ' id ', channel : ' channel ')']); + +elseif domain == 2 + % Time + figure; + subplot(2,1,1); + plot(t, sig_mes); + %semilogx(t, sig_mes); + axis([0 t(length(t)) min(sig_mes)-0.01 max(sig_mes)+0.01]); + %axis([1 t(length(t)) min(sig_mes)-0.01 max(sig_mes)+0.01]); + xlabel('Time (s)'); + ylabel('Amplitude'); + title(['Measured temporal signal (group: ' group ', id: ' id ', channel : ' channel ')']); + grid on; + + subplot(2,1,2); + len_ri = length(rep_imp_mes); + t_ri = [(-len_ri)/(2*f_s):1/f_s:(len_ri)/(2*f_s)]; + %t_ri = [0:1/f_s:len_ri/f_s]; + t_ri = t_ri(1:length(t_ri)-1); + plot(t_ri,rep_imp_mes); + axis([-t_ri(len_ri) t_ri(len_ri) min(rep_imp_mes)-0.01 max(rep_imp_mes)+0.01]); + xlabel('Time (s)'); + ylabel('Amplitude'); + title(['Measured impulse response (group: ' group ', id: ' id ', channel : ' channel ')']); + grid on; + +end + + diff --git a/tools/save_mes.m b/tools/save_mes.m index 2df08d5..8ea5952 100644 --- a/tools/save_mes.m +++ b/tools/save_mes.m @@ -18,9 +18,9 @@ function save_mes(handles) 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