Advertisement
Guest User

Untitled

a guest
Oct 20th, 2017
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.98 KB | None | 0 0
  1. clear all
  2. close all
  3. clc
  4.  
  5. %% Create filters
  6. fs=48e3;
  7. N = 16; % filter order
  8. ThirdOct = octaveFilter(1000,'1/3 octave','SampleRate',fs);
  9. F0 = getANSICenterFrequencies(ThirdOct);
  10. F0(F0<100) = [];
  11. F0(F0>16e3) = [];
  12. Nfc = length(F0);
  13.  
  14. for i=1:Nfc
  15.     oneThirdOctaveFilterBank{i} = octaveFilter('FilterOrder', N, ...
  16.         'CenterFrequency', F0(i), 'Bandwidth', '1/3 octave',...
  17.         'SampleRate', fs);
  18. end
  19.  
  20.  
  21. %% Init of PlayRec
  22. AutoPlayrecInit(fs)
  23.  
  24. %% Generate Pink Noise
  25. T=2;
  26. pinkDuration = fs*T;
  27. pinkNoise = dsp.ColoredNoise(1,pinkDuration,1);
  28. rng default;
  29. pinkPlay = pinkNoise();
  30. stimuli=pinkPlay.*0.5;
  31.  
  32. %% Play pink noise and record response
  33. out=playrec('playrec',[stimuli stimuli],[1 2],length(stimuli)+1500,1);
  34. playrec('block',out);
  35. x = playrec('getRec',out);
  36.  
  37. pause(1);
  38.  
  39. %% Apply 1/3 octave band filters on signal x
  40. for i=1:Nfc
  41.         L(:,i) = oneThirdOctaveFilterBank{i}(x);
  42. end
  43.  
  44. %% Convert to dB SPL re 20 uPa
  45. LdB = 20*log10(rms(L)/20e-6);
  46.  
  47. LdB'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement