docstr: Test approximate noise field with white noise as the input noise.
          
docstr_tok: ["Test","approximate","noise","field","with","white","noise","as","the","input","noise","."]
code: def test_generate_approximate_noise_field(
      self,
      num_mics: int,
      mic_spacing: float,
      fft_length: int,
      sample_rate: float,
      field: str,
      save_figures: bool = False,
  ):
      """Test approximate noise field with white noise as the input noise."""
      duration_in_sec = 20
      relative_mse_tol_dB = -30
      relative_mse_tol = 10 ** (relative_mse_tol_dB / 10)
  
      num_samples = sample_rate * duration_in_sec
      noise_signal = np.random.rand(num_samples, num_mics)
      # random channel-wise power scaling
      noise_signal *= np.random.randn(num_mics)
  
      # assume linear arrray
      mic_positions = np.zeros((num_mics, 3))
      mic_positions[:, 0] = mic_spacing * np.arange(num_mics)
  
      # UUT
      noise_field = generate_approximate_noise_field(
          mic_positions,
          noise_signal,
          sample_rate=sample_rate,
          field=field,
          fft_length=fft_length,
      )
  
      # Compare the estimated coherence with the theoretical coherence
  
      # reference
      golden_coherence = theoretical_coherence(
          mic_positions,
          sample_rate=sample_rate,
          field=field,
          fft_length=fft_length,
      )
  
      # estimated
      N = librosa.stft(noise_field.transpose(), n_fft=fft_length)
      # (channel, subband, frame) -> (subband, frame, channel)
      N = N.transpose(1, 2, 0)
      uut_coherence = estimated_coherence(N)
  
      # Check difference
      relative_mse_real = np.mean(
          (uut_coherence.real - golden_coherence) ** 2
      )
      assert relative_mse_real < relative_mse_tol
      relative_mse_imag = np.mean((uut_coherence.imag) ** 2)
      assert relative_mse_imag < relative_mse_tol
  
      if save_figures:
          # For debugging and visualization template
          figure_dir = os.path.expanduser("~/_coherence")
          if not os.path.exists(figure_dir):
              os.mkdir(figure_dir)
  
          freq = librosa.fft_frequencies(
              sr=sample_rate, n_fft=fft_length
          )
          freq = freq / 1e3  # kHz
  
          plt.figure(figsize=(7, 10))
          for n in range(1, num_mics):
              plt.subplot(num_mics - 1, 2, 2 * n - 1)
              plt.plot(
                  freq, golden_coherence[:, 0, n].real, label="golden"
              )
              plt.plot(
                  freq, uut_coherence[:, 0, n].real, label="estimated"
              )
              plt.title(f"Real(coherence), p=0, q={n}")
              plt.xlabel("f / kHz")
              plt.grid()
              plt.legend(loc="upper right")
  
              plt.subplot(num_mics - 1, 2, 2 * n)
              plt.plot(golden_coherence[:, 0, n].imag, label="golden")
              plt.plot(uut_coherence[:, 0, n].imag, label="estimated")
              plt.title(f"Imag(coherence), p=0, q={n}")
              plt.xlabel("f / kHz")
              plt.grid()
              plt.legend(loc="upper right")
  
          plt.tight_layout()
          plt.savefig(
              os.path.join(
                  figure_dir,
                  f"num_mics_{num_mics}_sample_rate_{sample_rate}_fft_length_{fft_length}_{field}.png",
              )
          )
          plt.close()
  
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 2 for calling the TestGenerateApproximateNoiseField obj's underlying member method code with example usage: obj.test_generate_approximate_noise_field(num_mics, mic_spacing, fft_length, sample_rate, field, save_figures) without return types