File: diff_fft_mag.m

package info (click to toggle)
codec2 1.2.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 76,376 kB
  • sloc: ansic: 436,819; cpp: 2,091; objc: 1,736; sh: 1,510; python: 1,405; asm: 683; makefile: 605
file content (27 lines) | stat: -rw-r--r-- 811 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
% Compare the magnitude spectrum of two int16 raw files
function diff_fft_mag(filename1, filename2, threshdB = -40, ignore=1000)
  % load samples and ignore any start up transients
  s1 = load_raw(filename1)'; 
  s1 = s1(ignore:end);
  s2 = load_raw(filename2)'; 
  s2 = s2(ignore:end);

  len = min([length(s1) length(s2)]);
  s1 = s1(1:len); s2 = s2(1:len);
  
  S1 = abs(fft(s1.*hanning(length(s1))'));
  S2 = abs(fft(s2.*hanning(length(s2))'));
  
  figure(1): clf;
  plot(20*log10(S1)); hold on; plot(20*log10(S2)); plot(20*log10(abs(S1-S2)),'r'); hold off;
  error = S1 - S2;
  error_energy = error*error';
  ratio = error_energy/(S1*S1');
  ratio_dB = 10*log10(ratio);
  printf("ratio_dB: %4.2f\n", ratio_dB);
  if ratio_dB < threshdB
    printf('PASS\n');
  else
    printf('FAIL\n');
  end
endfunction