DiyMobileAudio.com Car Stereo Forum banner

1 - 8 of 8 Posts

·
Registered
Joined
·
49 Posts
Discussion Starter #1
I have a reference-calibrated microphone, a good quality ADC (hopefully I can find the Windows drivers for it), and professional version of MATLAB.

I plan on recording the raw data file with the ADC (I think it's an older Presonus Firebox. luckily I have a firewire port on my laptop), and do all the signal processing manually inside of MATLAB since real time analysis isn't necessary for this application. Correct me if this may be untrue.

A few questions:
  1. What window function should I apply to the FFT of the time-domain sweep? I was leaning toward the general purpose hanning window.
  2. Will doing a sweep give me an accurate representation or will I need to do some postprocessing smoothing? Or anything else to consider?

I also have a Daqarta license. Even though I'm not really doing RTA (and I don't have that much faith in my stock sound card), should I still use this instead of doing things in MATLAB? It's been over a year since I used it, but I was struggling how to figure out performing processing on prerecorded audio files.
 

·
Registered
Joined
·
115 Posts
anybody else out there do their own spectrum analysis?
Yes.

I use the equipment described below:


I would encourage you to do your own analysis in MATLAB; that way you know exactly what is going on. I neither like nor really understand the descriptions of the windows linked above. The windows are well-defined mathematical objects; therefore they have definitive properties that you can read about. For example, the Fourier transform (FT) of the "flat top" window has the narrowest main lobe among all windows of equal length (contrary to what the linked description suggests based on the way I read it); the FT of the "flat top" window suffers from relatively high side lobes however. (Recall that "windowing" can be thought of as convolving the FT of the window with the FT of the periodic extension of the recorded signal). You can use "wintool" or "wvtool" in MATLAB to examine several different windows visually. If you want to develop your own intuition about the windows I'd encourage you to use several and compare the results. If you're using long recording times (e.g. 10 or more seconds) I doubt you'll notice an advantage of the narrower main-lobe of the FT of the "Flat top" because for long windows the main lobe of any reasonable window should be narrow enough; you may notice a disadvantage of the high side lobes of the "Flat top" however (I use hanning).

For my analyses I used both chirps (sweeps) and white noise. I ended up relying mostly on white noise but I can't remember why (this was last summer). The analyses worked well and helped me improve the sound in my car.

Based on what you wrote I think you'll be fine. I suggest you just start doing it and once you get some results you may be able to ask more specific questions.
 

·
Registered
Joined
·
49 Posts
Discussion Starter #5
Yes.

I use the equipment described below:


I would encourage you to do your own analysis in MATLAB; that way you know exactly what is going on. I neither like nor really understand the descriptions of the windows linked above. The windows are well-defined mathematical objects; therefore they have definitive properties that you can read about. For example, the Fourier transform (FT) of the "flat top" window has the narrowest main lobe among all windows of equal length (contrary to what the linked description suggests based on the way I read it); the FT of the "flat top" window suffers from relatively high side lobes however. (Recall that "windowing" can be thought of as convolving the FT of the window with the FT of the periodic extension of the recorded signal). You can use "wintool" or "wvtool" in MATLAB to examine several different windows visually. If you want to develop your own intuition about the windows I'd encourage you to use several and compare the results. If you're using long recording times (e.g. 10 or more seconds) I doubt you'll notice an advantage of the narrower main-lobe of the FT of the "Flat top" because for long windows the main lobe of any reasonable window should be narrow enough; you may notice a disadvantage of the high side lobes of the "Flat top" however (I use hanning).

For my analyses I used both chirps (sweeps) and white noise. I ended up relying mostly on white noise but I can't remember why (this was last summer). The analyses worked well and helped me improve the sound in my car.

Based on what you wrote I think you'll be fine. I suggest you just start doing it and once you get some results you may be able to ask more specific questions.
Thanks for the reply!

I have that exact same microphone also calibrated from Cross Spectrum Labs.

Did your Fast Track come with the appropriate software to access the raw audio files?
 

·
Registered
Joined
·
115 Posts
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;
 

·
Registered
Joined
·
1 Posts
Hello. Thanks for posting all this code and explaining your measurement methodology. I don't understand why you chose to use white noise bands instead of chirps (sweeps). It seems to me that using chirps (or successive frequency increasing tones) is less sensitive to some defects in the audio channel. Do you remember what made you prefer this method ?

Additionnaly did you try the "Maximum Length Sequence" technique to evaluate the impulse response ? This technique seems more complex to implement, but might be more effective.
 

·
Registered
Joined
·
115 Posts
I don't understand why you chose to use white noise bands instead of chirps (sweeps)... Do you remember what made you prefer this method ?
I think maybe I was worried about transient start-ups -- not so much in terms of theory (which I'm nonetheless not completely comfortable with), but with the hardware I am using: at the beginning of a sound my laptop seemed to do some strange things, and with a sweep that means the early frequencies -- typically the low tones -- are selectively distorted. In contrast, with several trials of white noise hardware imposed start-up and stopping distortions should not be correlated with specific frequencies (this also applies to the speakers). In addition, I like the idea of speakers being exposed to inputs that are not nearly pure sinusoidal oscillations, although I have no technical basis for such a preference.

I also need to think carefully about the theoretical implications of windowing a chirp to be sure I understand the difference between window artifacts and system distortion. I wrote much of the code posted above "on the fly" while I was in my car measuring, and just defaulting to white noise presents a more comfortable situation for me in terms of interpreting results and separating processing artifact from audio system attributes (e.g. once again the possibility of frequency dependent windowing artifact due to the time-frequency correlation inherent in a sweep).

It seems to me that using chirps (or successive frequency increasing tones) is less sensitive to some defects in the audio channel.
I'm unfamiliar with whatever issues might be associated with the statement above.

Additionnaly did you try the "Maximum Length Sequence" technique to evaluate the impulse response ? This technique seems more complex to implement, but might be more effective.
This is an interesting idea and I thank you for posting it. Because of the reflective environment in automobiles I have been working towards impulse response methods because I think there could be benefits to considering phase (timing) in addition to the frequency magnitude response that I have examined up until now. I think however that phase corrections will be ineffective at "high" frequencies (> ~500 Hz) because corrections for short wavelength sounds will apply only to volumes of space that are small relative to typical head movements; on the other hand I want to try to correct for reflections at lower frequencies where wavelengths are longer and one correction will be approximately invariant over a relatively large swath of space. Hence the need to consider phase (timing).

Before going too far however I need the processing power to implement arbitrary phase responses at low frequencies. I use Analog Devices ADAU1442 for processing and for the 20-500 Hz range I need multiple processors that are running at a lower than typical clock (8 kHz fs instead of a more usual 48, 96 or 192 kHz fs). I built an initial processor for my my car using one ADAU1442 that I described with photos here. I'm in the process of building a new processor that uses three ADAU1442's with two running at 8 kHz fs. When this is finished I will get more serious about code for impulse response measurements. One step at a time because although I am interested in audio it is not even in the top ten of priorities in my life right now.

I want to thank you again for the "Maximum Length Sequence" idea because in addition to being a flat magnitude input that affords the opportunity for measuring phase it also appears to obviate the need to clip the occasional "outlier" values that are produced with Gaussian distributed samples.
 
1 - 8 of 8 Posts
Top