logo

Sample Assignment on Acoustics

27 Pages6777 Words113 Views
   

Added on  2021-04-16

Sample Assignment on Acoustics

   Added on 2021-04-16

ShareRelated Documents
Running Head: ACOUSTICSAcousticsStudent’s NameInstitution
Sample Assignment on Acoustics_1
ACOUSTICS2IM_SETUP [this is the setup defining environmental parameters for simulation basis]function [OutStruc] = IMSetup()OutStruc.Fs = 16000; % frequency samplingOutStruc.c = 343; % acoustic propagation speed in m/sOutStruc.room = [3 4 2.5]; % room’s dimensions in metersOutStruc.micpos = [1.6 1 1.5; % [x y z] microphone array positioning 1.4 1 1.5];OutStruc.beta = [ones(1,6)*0.8]; % range of coefficient reflection [0 ... 1[OutStruc.straj = [linspace(1,2,50).' ones(50,1)*3 ones(50,1)*1.5]; % [x y z] source trajectory position in m % mic pair straight line at 50 source points
Sample Assignment on Acoustics_2
ACOUSTICS3RESPONSE [Computes the transfer function from source to receiver in the set simulation parameters]function [FilterCoeffs,SpectrumVec] = MakeIMResp(Fs,beta,X_src,X_rcv,room,cc,LimAtten_dB,measT60,silentflag)global SpectrumVec FreqPoints % avoids passing %---- Checking user input:if X_rcv(1)>=room(1) | X_rcv(2)>=room(2) | X_rcv(3)>=room(3) | X_rcv(1)<=0 | X_rcv(2)<=0 | X_rcv(3)<=0, error('Receiver must be within the room boundaries.');elseif X_src(1)>=room(1) | X_src(2)>=room(2) | X_src(3)>=room(3) | X_src(1)<=0 | X_src(2)<=0 | X_src(3)<=0, error('Source must be within the room boundaries.');elseif ~isempty(find(beta>=1)) | ~isempty(find(beta<0)), error('Parameter ''beta'' must be in range [0...1[.');endif nargin<9, silentflag = 0; % set to 1, disables on-screen messagesendX_src = X_src(:); % location of sourceX_rcv = X_rcv(:); % location of receiverbeta = beta(:);Rr = 2*room(:); % room’s dimensionsDPdel = norm(X_rcv - X_src)/cc; % direct delay of path in [s]%---- Defining frequency points if ~isequal(beta,zeros(6,1)), if isempty(measT60), % if lacking practical T60 measurement, use Sabine estimate
Sample Assignment on Acoustics_3
ACOUSTICS4 V = prod(room); aa_sab = (2-beta(1)^2-beta(2)^2)*room(2)*room(3) + (2-beta(3)^2-beta(4)^2)*room(1)*room(3) + (2-beta(5)^2-beta(6)^2)*room(1)*room(2); T60val = 0.161*V/aa_sab; % Sabine's reverberation time in [s] else T60val = measT60; % practical T60 measurement determines real energy decay in TF! end foo = LimAtten_dB * T60val / 60; % desired length of TF (TF decays by 60dB for T60 seconds after direct path delay) MaxDelay = DPdel + foo; % maximum delay in TF: direct path plus TForderelse MaxDelay = 2*DPdel; % anechoic case: allow for 2 times direct path in TF endTForder = ceil(MaxDelay*Fs); % total TF lengthFreqPoints = linspace(0,Fs/2,TForder).';SpectrumVec = zeros(TForder,1);%---- summing room dimensions:if ~silentflag, fprintf(' [MakeIMResp] Computing transfer function '); end;for a = 0:1 for b = 0:1 for d = 0:1 if ~silentflag, fprintf('.'); end; m = 1; % Checking delay values in m=1 and above FoundLValBelowLim = Check_lDim(a,b,d,m,X_rcv,X_src,Rr,cc,MaxDelay,beta); while FoundLValBelowLim==1, m = m+1;
Sample Assignment on Acoustics_4
ACOUSTICS5 FoundLValBelowLim = Check_lDim(a,b,d,m,X_rcv,X_src,Rr,cc,MaxDelay,beta); end m = 0; % Checking delay values in m=0 and below FoundLValBelowLim = Check_lDim(a,b,d,m,X_rcv,X_src,Rr,cc,MaxDelay,beta); while FoundLValBelowLim==1, m = m-1; FoundLValBelowLim = Check_lDim(a,b,d,m,X_rcv,X_src,Rr,cc,MaxDelay,beta); end end endendif ~silentflag, fprintf('\n'); end;%---- Inversing the Fourier transform:SpectrumVec(1) = SpectrumVec(1)/2; % removing DC component that result to time coefficients.freqvec = -i*2*pi*linspace(0,1/2,TForder);FilterCoeffs = zeros(TForder,1);for ii=1:TForder, freq = exp((ii-1)*freqvec); FilterCoeffs(ii) = real(freq*SpectrumVec);endFilterCoeffs = FilterCoeffs/TForder;%============function [FoundLValBelowLim] = Check_lDim(a,b,d,m,X_rcv,X_src,Rr,cc,MaxDelay,beta)FoundLValBelowLim = 0;
Sample Assignment on Acoustics_5
ACOUSTICS6l = 1; % Check delay values for l=1 and aboveFoundNValBelowLim = Check_nDim(a,b,d,l,m,X_rcv,X_src,Rr,cc,MaxDelay,beta);while FoundNValBelowLim==1, l = l+1; FoundNValBelowLim = Check_nDim(a,b,d,l,m,X_rcv,X_src,Rr,cc,MaxDelay,beta);endif l~=1, FoundLValBelowLim = 1; end;l = 0; % Checking delay values in l=0 and belowFoundNValBelowLim = Check_nDim(a,b,d,l,m,X_rcv,X_src,Rr,cc,MaxDelay,beta);while FoundNValBelowLim==1, l = l-1; FoundNValBelowLim = Check_nDim(a,b,d,l,m,X_rcv,X_src,Rr,cc,MaxDelay,beta);endif l~=0, FoundLValBelowLim = 1; end;%============function [FoundNValBelowLim] = Check_nDim(a,b,d,l,m,X_rcv,X_src,Rr,cc,MaxDelay,beta)global SpectrumVec FreqPointsFoundNValBelowLim = 0;n = 1; % Checking delay values for n=1 and abovedist = norm( [2*a-1; 2*b-1; 2*d-1].*X_src + X_rcv - Rr.*[n;l;m] );foo_time = dist/cc;while foo_time<=MaxDelay, % if delay is below TF length limit for n=1, check n=2,3,4... foo_amplitude = prod(beta.^abs([n-a; n; l-b; l; m-d; m])) / (4*pi*dist); SpectrumVec = SpectrumVec + foo_amplitude * exp(i*2*pi*foo_time*FreqPoints); n = n+1;
Sample Assignment on Acoustics_6

End of preview

Want to access all the pages? Upload your documents or become a member.