optimize stack_phv.m