DROP TABLE formantsemitones_fm;

SELECT 
f1_fm.id AS id, 
12*ln(f1_fm.time2)/ln(2.0) AS F1ST, 
12*ln(f2_fm.time2)/ln(2.0) AS F2ST,
12*ln(f3_fm.time2)/ln(2.0) AS F3ST,
12*(ln(f1_fm.time2) -  ln(350.0))/ln(2.0) AS F1dist,
12*(ln(f2_fm.time2) -  ln(1450.0))/ln(2.0) AS F2dist,
12*(ln(f3_fm.time2) -  ln(2500.0))/ln(2.0) AS F3dist,
12*sqrt((ln(f1_fm.time2) -  ln(350.0))^2 +
        (ln(f2_fm.time2) -  ln(1450.0))^2)/ln(2.0) AS F12dist

INTO
formantsemitones_fm
FROM 
f1_fm, f2_fm, f3_fm
WHERE 
f1_fm.id = f2_fm.id
AND f2_fm.id = f1_fm.id
AND f1_fm.id = f3_fm.id
AND f3_fm.id = f1_fm.id
AND f3_fm.id = f2_fm.id
AND f2_fm.id = f3_fm.id;

CREATE INDEX formantsemitones_fm_index on formantsemitones_fm (id);

GRANT SELECT on formantsemitones_fm TO PUBLIC;

DROP TABLE formantsemitones_hm;

SELECT 
f1_hm.id AS id, 
12*ln(f1_hm.time2)/ln(2.0) AS F1ST, 
12*ln(f2_hm.time2)/ln(2.0) AS F2ST,
12*ln(f3_hm.time2)/ln(2.0) AS F3ST,
12*(ln(f1_hm.time2) -  ln(350.0))/ln(2.0) AS F1dist,
12*(ln(f2_hm.time2) -  ln(1450.0))/ln(2.0) AS F2dist,
12*(ln(f3_hm.time2) -  ln(2500.0))/ln(2.0) AS F3dist,
12*sqrt((ln(f1_hm.time2) -  ln(350.0))^2 +
        (ln(f2_hm.time2) -  ln(1450.0))^2)/ln(2.0) AS F12dist

INTO
formantsemitones_hm
FROM 
f1_hm, f2_hm, f3_hm
WHERE 
f1_hm.id = f2_hm.id
AND f2_hm.id = f1_hm.id
AND f1_hm.id = f3_hm.id
AND f3_hm.id = f1_hm.id
AND f3_hm.id = f2_hm.id
AND f2_hm.id = f3_hm.id;

CREATE INDEX formantsemitones_hm_index on formantsemitones_hm (id);

GRANT SELECT on formantsemitones_hm TO PUBLIC;

