1% Copyright (c) 2012 The Chromium OS Authors. All rights reserved. 2% Use of this source code is governed by a BSD-style license that can be 3% found in the LICENSE file. 4% 5% This is an octave script. 6% It reads impulse response from "ir.dat" and plots frequency response. 7% Both x-axis and y-axis is in log scale. 8h=load("ir.dat"); 9N=columns(h); 10K=rows(h)/2; 11NQ=44100/2; 12% This tries to match the labels in the audio tuning UI. 13xticks=[22050, 11025, 5513, 2756, 1378, 689, 345, 172, 86, 43, 21]; 14xticklabels={"22050Hz", "11025Hz", "5513Hz", "2756Hz", "1378Hz", \ 15"689Hz", "345Hz", "172Hz", "86Hz", "43Hz", "21Hz"}; 16yticks=[18,12,6,0,-6,-12,-18,-24]; 17yticklabels={"18dB","12dB","6dB","0dB","-6dB","-12dB","-18dB","-24dB"}; 18xyrange=[21,22050,-24,18]; 19xrange=[21,22050]; 20 21for i=1:N 22 figure(i); 23 title('fftl'); 24 fr = fft(h(:,i))(1:K); 25 subplot(2, 1, 1); 26 semilogx(NQ*(1:K)/K, 20*log10(abs(fr))); 27 xlabel('Frequency'), ylabel('Magnitude'), grid; 28 set (gca, "xtick", xticks); 29 set (gca, "xticklabel", xticklabels); 30 set (gca, "ytick", yticks); 31 set (gca, "yticklabel", yticklabels); 32 axis(xyrange); 33 subplot(2, 1, 2); 34 semilogx(NQ*(1:K)/K,180/pi*unwrap(angle(fr))); 35 xlabel('Frequency'), ylabel('Phase (degrees)'), grid; 36 set (gca, "xtick", xticks); 37 set (gca, "xticklabel", xticklabels); 38 axis(xrange); 39end 40pause 41