<jupyter_start><jupyter_text>Delay-and-Sum Beamformer - Linear Array of Infinite Length*This Jupyter notebook is part of a [collection of notebooks](../index.ipynb) in the masters course Selected Topics in Audio Signal Processing, Communications Engineering, Universität Rostock. Please direct questions and suggestions to [<EMAIL>](mailto:<EMAIL>).*  BeampatternIn this example the beampattern of a delay-and-sum (DSB) beamformer for a linear array of infinite length is computed and plotted for various steering angles. For numerical evaluation the array of infinite length is approximated by a long array of finite length. First, two functions are defined for computation and illustration of the beampattern, respectively.<jupyter_code>%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt

dx = 0.1  # spatial sampling interval (distance between microphones)
c = 343  # speed of sound

om = 2*np.pi * np.linspace(100, 8000, 1000)  # angular frequencies
theta_pw = np.linspace(0, np.pi, 181)  # angles of the incident plane waves


def compute_dsb_beampattern(theta, theta_pw, om, dx, nmic=5000):
    "Compute beampattern of a delay-and-sub beamformer for given steering angle"
    B = np.zeros(shape=(len(om), len(theta_pw)), dtype=complex)
    for n in range(len(om)):
        for mu in range(-nmic//2, nmic//2+1):
            B[n, :] += np.exp(-1j * om[n]/c * mu*dx * (np.cos(theta_pw) - np.cos(theta)))
            
    return B/nmic


def plot_dsb_beampattern(B, theta_pw, om):
    "Plot beampattern of a delay-and-sub beamformer"
    plt.figure(figsize=(10,10))
    plt.imshow(20*np.log10(np.abs(B)), aspect='auto', vmin=-50, vmax=0, origin='lower', \
               extent=[0, 180, om[0]/(2*np.pi), om[-1]/(2*np.pi)], cmap='viridis')
    plt.xlabel(r'$\theta_{pw}$ in deg')
    plt.ylabel('$f$ in Hz')
    plt.title('Beampattern')
    cb = plt.colorbar()
    cb.set_label(r'$|\bar{P}(\theta, \theta_{pw}, \omega)|$ in dB')<jupyter_output><empty_output><jupyter_text>Steering Angle $\theta = 90^\mathrm{o}$<jupyter_code>B = compute_dsb_beampattern(np.pi/2, theta_pw, om, dx)
plot_dsb_beampattern(B, theta_pw, om)<jupyter_output><empty_output><jupyter_text>Steering Angle $\theta = 45^\mathrm{o}$<jupyter_code>B = compute_dsb_beampattern(np.pi/4, theta_pw, om, dx)
plot_dsb_beampattern(B, theta_pw, om)<jupyter_output><empty_output><jupyter_text>Steering Angle $\theta = 0^\mathrm{o}$<jupyter_code>B = compute_dsb_beampattern(0, theta_pw, om, dx)
plot_dsb_beampattern(B, theta_pw, om)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13199369582348305, 'fraction_numerical': 0.02206461780929866, 'mean_word_length': 4.8637413394919164, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '34011', 'license': 'MIT', 'n_tokens_mistral': 962, 'n_tokens_neox': 906, 'n_words': 233, 'path': 'sound_field_analysis/delay_and_sum_infinite.ipynb', 'repo_name': 'spatialaudio/-selected-topics-in-audio-signal-processing-lecture-', 'size': '2578'}