Did your Fast Track come with the appropriate software to access the raw audio files?
Yes. I loaded the M-audio drivers and afterwards I was able to select the M-audio device as the default windows mic input (in Vista
Control Panel / hardware and sound / sound / recording tab).
Then in MATLAB it is possible to access the default (as well as other) sound inputs and outputs (I used an optical S/PDIF output on my laptop as the sound output).
For ideas for code I pasted below a MATLAB function I used (I wrote it in bits in pieces in my car as things progressed). It plays several trials of band-limited white noise and saves the recorded audio from each trial. I moved the mic around between trials to check for differences and so that I could perform spatial averaging in some cases. (Please note that I am not a computer programmer -- from the code below you can see the MATLAB functions I used and read about them in the MATLAB help files and perhaps write something better. I would like to see your code if you write something more polished. The raw data is in the variable "
yy", left and right channels with no time since the sample rate is known to be 44100 kHz in my case).
function rec_wn(s_dir,f_name,N_recs,rec_dur,f_min,f_max)
%
% PLAY BAND-LIMITED WHITE NOISE, RECORD AND WRITE RESULTS TO DISK
%
% rec_wn(s_dir,f_name,N_recs,rec_dur,f_min,f_max);
%
% function arguments
% ------------------
%
% s_dir -- sub-directory for storing recorded audio
% f_name -- file-name for storing recorded audio
% N_recs -- number of recording trials
% rec_dur --
duration of each recording trial
% f_min -- [Hz] lowest frequency of band-limited white noise
% f_max -- [Hz] highest frequency of band-limited white noise
%
F_SAM = 44100; % sample rate setting of M-audio fast track
d_dir = ['C:\Users\24th-Alchemist\all programming\Matlab\', ...
'car audio\test sounds\',s_dir,'\'];
% Get mic frequency response (45 degrees) for correction
load(['C:\Users\24th-Alchemist\all programming\Matlab\car audio\', ...
'narrow_band_response_45_degree.mat']);
% Prepare for data storage
if ~isdir(d_dir)
if ~mkdir(d_dir)
msg = ['Error creating data storage directory ', ...
d_dir, '.'];
disp(' '); disp(msg); disp(' '); beep;
return;
end
end
% Prepare title for plots
f_name_fig = [];
for nm = 1:length(f_name)
if ( (f_name(nm) == '_') || (f_name(nm) == '\') )
f_name_fig = [f_name_fig, '\'];
end
f_name_fig = [f_name_fig, f_name(nm)];
end
% Create a device object — analog input & output objects for sound card
if (~isempty(daqfind)), stop(daqfind); end
ai = analoginput('winsound');
ao = analogoutput('winsound');
% Add channels — Add two hardware channels to ai & ao.
addchannel(ai,1:2);
addchannel(ao,1:2);
% Configure property values
set(ai,'SampleRate',F_SAM);
set(ao,'SampleRate',F_SAM);
f_sam_rec = get(ai,'SampleRate');
f_sam_ply = get(ao,'SampleRate');
set(ai,'ManualTriggerHwOn','Trigger');
set(ai,'SamplesPerTrigger',rec_dur*f_sam_rec);
set([ai ao],'TriggerType','Manual')
% Create testing signals (generate white noise)
xx = 0.25*randn(ceil(rec_dur*f_sam_ply),1);
xx = [zeros(round(f_sam_ply/10),1); xx; zeros(round(f_sam_ply/10),1)];
% band limit to [f_min,f_max]
[b,a] = fir1(2048,[f_min,f_max]/(f_sam_ply/2));
xx = filtfilt(b,a,xx);
% Prepare for ploting
figure, subplot(2,1,1);
ylabel('\itmag [dB]\rm'); xlabel('\itfrequency [Hz]\rm');
subplot(2,1,2);
title({[' ']; ['Time Series']});
ylabel('\itamplitude\rm'); xlabel('\ittime [sec]\rm');
c_c = ['k','b','c','g','r'];
c_n = 1;
% Variables for running-average response
ff_avg = logspace(log10(f_min),log10(f_max),20000)';
fft_1_sum = zeros(size(ff_avg));
% Loop through white noise trials
for nn = 1:N_recs
% pause;
pause(2);
% rectify
xx(abs(xx)>.999) = .999*sign(xx(abs(xx)>.999));
% load data to sound output
putdata(ao,[xx,xx]);
% acquire data
start([ai ao]);
trigger([ao ai]);
wait(ai,rec_dur+1);
yy = getdata(ai);
stop([ao ai]);
% analyze data
[yy_psd_1,ff] = pwelch(yy
,1),8192,[],[],f_sam_rec);
yy_fft_1 = f_sam_rec*sqrt(yy_psd_1);
yy_fft_1_mag = 20*log10(abs(yy_fft_1));
% mic corrections
mic_resp_db = interp1(narrow_band_response_45_degree
,1), ...
narrow_band_response_45_degree
,2), ...
ff, 'linear', 0);
yy_fft_1_mag = yy_fft_1_mag - mic_resp_db;
% compute running average
NN = round(length(ff)/length(ff_avg));
if NN > 1
NN = min(NN,100);
b = hamming(NN);
b = b/sum(b);
fft_smth = filtfilt(b,1,yy_fft_1_mag);
else
fft_smth = yy_fft_1_mag;
end
fft_1_dns = interp1(ff,fft_smth,ff_avg,'linear');
fft_1_sum = fft_1_sum + fft_1_dns;
% display frequency response
subplot(2,1,1), hold on;
semilogx(ff(f_min<=ff & ff <= f_max), ...
yy_fft_1_mag(f_min<=ff & ff <= f_max),c_c(c_n));
title(['\bfWhite Noise Frequency Response Analysis: ', ...
num2str(nn), ' of ', num2str(N_recs), ...
'\it ', f_name_fig, ', ', ...
num2str(f_min), '-', num2str(f_max), ' [Hz]\rm']);
set(gca,'XScale','log');
axis('tight');
hold off;
subplot(2,1,2), hold on;
plot([0:1
size(yy,1)-1)]'/f_sam_rec,yy
,1),c_c(c_n));
hold off;
drawnow;
c_n = c_n + 1; if c_n > length(c_c) c_n = 1; end
% save data
save([d_dir, f_name, num2str(nn), '.mat'], ...
'yy', 'ff_avg', 'fft_1_dns', 'f_min', 'f_max', ...
'f_sam_rec');
end
% Plot average FR after all samples aquired
fft_1_avg = fft_1_sum/N_recs;
subplot(2,1,1), hold on;
semilogx(ff_avg,fft_1_avg,'m','LineWidth',3);
set(gca,'XScale','log');
axis('tight');
hold off;
% Save average FR with basename
save([d_dir, f_name, '.mat'], 'ff_avg', 'fft_1_avg', ...
'f_min', 'f_max', 'f_sam_rec');
% Clean up I/O objects
delete(ai);
delete(ao);
clear ai;
clear ao;