code: def export_freq(xfreq, filename, desc=None):
      
      heading_row_1 = ['Segment index',
                     'Start time',
                     'End time',
                     'Duration',
                     'Stitches',
                     'Stage',
                     'Cycle',
                     'Event type',
                     'Channel',
                     ]
      spacer = [''] * (len(heading_row_1) - 1)
      freq = list(xfreq[0]['data'].axis['freq'][0])
  
      with open(filename, 'w', newline='') as f:
          lg.info('Writing to ' + str(filename))
          csv_file = writer(f)
          csv_file.writerow(['Wonambi v{}'.format(__version__)])
          csv_file.writerow(heading_row_1 + freq)
  
          if desc:
              csv_file.writerow(['Mean'] + spacer + list(desc['mean']))
              csv_file.writerow(['SD'] + spacer + list(desc['sd']))
              csv_file.writerow(['Mean of ln'] + spacer + list(
                      desc['mean_log']))
              csv_file.writerow(['SD of ln'] + spacer + list(desc['sd_log']))
  
          idx = 0
          for seg in xfreq:
  
              for chan in seg['data'].axis['chan'][0]:
                  idx += 1
  
                  cyc = None
                  if seg['cycle'] is not None:
                      cyc = seg['cycle'][2]
  
                  data_row = list(seg['data'](chan=chan)[0])
                  csv_file.writerow([idx,
                                     seg['start'],
                                     seg['end'],
                                     seg['duration'],
                                     seg['n_stitch'],
                                     seg['stage'],
                                     cyc,
                                     seg['name'],
                                     chan,
                                     ] + data_row)
docs: Write frequency analysis data to CSV.
  
      Parameters
      ----------
      xfreq : list of dict
          spectral data, one dict per segment, where 'data' is ChanFreq
      filename : str
          output filename
      desc : dict of ndarray
          descriptives