DROP TABLE microphonestdifference;

SELECT DISTINCT
formantsemitones_fm.id, 
formantsemitones_fm.F1ST   -formantsemitones_fm.F1ST    AS F1STdiff, 
formantsemitones_fm.F2ST   -formantsemitones_fm.F2ST    AS F2STdiff,
formantsemitones_fm.F3ST   -formantsemitones_fm.F3ST    AS F3STdiff,
formantsemitones_fm.F1dist -formantsemitones_fm.F1dist  AS F1distdiff,
formantsemitones_fm.F2dist -formantsemitones_fm.F2dist  AS F2distdiff,
formantsemitones_fm.F3dist -formantsemitones_fm.F3dist  AS F3distdiff,
formantsemitones_fm.F12dist-formantsemitones_fm.F12dist AS F12distdiff,
12*(ln(pitch_fm.time2) -  ln(pitch_hm.time2))/ln(2.0)   AS F0STdiff

INTO
microphonestdifference
FROM 
formantsemitones_fm,
formantsemitones_hm,
pitch_fm,
pitch_hm
WHERE 
formantsemitones_fm.id = formantsemitones_hm.id
AND formantsemitones_hm.id = formantsemitones_fm.id
AND pitch_fm.id = formantsemitones_fm.id
AND pitch_hm.id = formantsemitones_fm.id
AND pitch_fm.id = formantsemitones_hm.id
AND pitch_hm.id = formantsemitones_hm.id
AND pitch_fm.id = pitch_hm.id
AND pitch_hm.id = pitch_fm.id
;

CREATE INDEX microphonestdifference_index on  microphonestdifference(id);

GRANT SELECT on microphonestdifference TO PUBLIC;

