Modified for irregular frequencies: see Main_Channel_freq.m