docstr: Test calculation of a theoretical coherence matrix.
          
docstr_tok: ["Test","calculation","of","a","theoretical","coherence","matrix","."]
code: def test_theoretical_coherence_matrix(
      self,
      num_mics: int,
      mic_spacing: float,
      fft_length: int,
      sample_rate: float,
      field: str,
  ):
      """Test calculation of a theoretical coherence matrix."""
      # test setup
      max_diff_tol = 1e-9
  
      # golden reference: spherical coherence
      num_subbands = fft_length // 2 + 1
      angular_freq = (
          2
          * np.pi
          * sample_rate
          * np.arange(0, num_subbands)
          / fft_length
      )
      golden_coherence = np.zeros((num_subbands, num_mics, num_mics))
  
      for p in range(num_mics):
          for q in range(num_mics):
              if p == q:
                  golden_coherence[:, p, q] = 1.0
              else:
                  if field == "spherical":
                      dist_pq = abs(p - q) * mic_spacing
                      sinc_arg = angular_freq * dist_pq / sound_velocity
                      golden_coherence[:, p, q] = np.sinc(
                          sinc_arg / np.pi
                      )
                  else:
                      raise NotImplementedError(
                          f"Field {field} not supported."
                      )
  
      # assume linear arrray
      mic_positions = np.zeros((num_mics, 3))
      mic_positions[:, 0] = mic_spacing * np.arange(num_mics)
  
      # UUT
      uut_coherence = theoretical_coherence(
          mic_positions,
          sample_rate=sample_rate,
          fft_length=fft_length,
          field="spherical",
      )
  
      # Check difference
      max_diff = np.max(np.abs(uut_coherence - golden_coherence))
      assert max_diff < max_diff_tol
  
imports: import os
  from collections import namedtuple
  from typing import List, Type, Union
  import librosa
  import matplotlib.pyplot
  import numpy
  import pytest
  import scipy
  import soundfile
  import torch
  from nemo.collections.asr.parts.preprocessing.segment import AudioSegment
  from nemo.collections.asr.parts.utils.audio_utils import SOUND_VELOCITY
  from nemo.collections.asr.parts.utils.audio_utils import calculate_sdr_numpy, convmtx_mc_numpy, db2mag, estimated_coherence, generate_approximate_noise_field, get_segment_start, mag2db, pow2db, rms, select_channels, theoretical_coherence, toeplitz
label_desc: Use image node_id 1 for calling the TestGenerateApproximateNoiseField obj's underlying member method code with example usage: obj.test_theoretical_coherence_matrix(num_mics, mic_spacing, fft_length, sample_rate, field) without return types