## 2 Materials and Methods
### Methods of Simulation
This code was thus of length 54,415 samples, and with a 100 MHz clock required 0.54 ms to transmit. Figure 3 below shows the process flow diagram of the system used for imaging. Order 128 HAPI codes are first generated according to the algorithm described above. The bandwidth of the codes is then matched to the bandwidth of the transducer by performing a Kronecker product with a sequence of 10 ones. This ensures that a coded excitation pulse width (10 ns) is half the center frequency period (20 ns for 5 MHz). The bandwidth-matched codes are then transmitted in parallel from each transmit element (128 elements). Then, each HAPI code is cross-correlated with the receive signals from the receive elements to obtain each transmit-receive combination. The decoded transmit-receive aperture data are then beamformed to produce 128 low-resolution images. Finally, the images are then combined to produce one high-resolution image. To characterize imaging performance, both point spread functions and scattering phantoms were simulated. The scattering phantoms consist of five hypoechoic cysts and five high scattering regions. The cysts and high scattering regions in the phantom are used to calculate the contrast-to-speckle ratio (CSR) as proposed by [PERSON] and [PERSON] [35], the contrast-to-noise ratio (CNR), and the signal-to-noise ratio (SNR) in order to evaluate the contrast-lesion detection capability. The phantom contains 50,000 scatterers that are randomly assigned a Gaussian distributed amplitude. The amplitude of the scatterers in the cyst regions are set to zero, while the amplitude of the scatterers in the high scattering regions are set to 10 times the previously assigned Gaussian distributed amplitude. Figure 3: Flow diagram of imaging with HAPI codes. First, 128 HAPI codes are generated. Then they are bandwidth-matched to improve correlation properties. The codes are then transmitted in parallel from all elements and echo signals are received. Decoding is then performed on the echo signals using cross-correlation to recover the full synthetic aperture dataset. Beamforming and summing are then performed on the full recovered dataset to form a high-resolution image. The CSR, CNR, and SNR were calculated using the following formulas for each of the five targets as shown in Equations (8)-(10). \[CSR=\frac{S_{in}-S_{bg}}{\sqrt{\sigma_{in}^{2}+\sigma_{bg}^{2}}} \tag{8}\]  
\[CNR=20\log_{10}\biggl{(}\frac{S_{in}-S_{bg}}{\sigma_{n}}\biggr{)} \tag{9}\]  
\[SNR=20\log_{10}\biggl{(}\frac{S_{bg}}{\sigma_{n}}\biggr{)} \tag{10}\]  
where \(S_{in}\) is the mean signal in the target, \(S_{bg}\) is the mean signal in the background, \(\sigma_{in}\) and \(\sigma_{bg}\) are the standard deviations inside the target and for the background, respectively, and \(\sigma_{n}\) is the standard deviation of the noise. Theoretically, synthetic aperture imaging with order N HAPI codes should provide a maximum increase in SNR of \(20\log_{10}(N)\) compared to traditional synthetic aperture imaging, where \(N\) is the number of non-zero code bits, in our case also equal to the number of elements in the imaging array. In order to realize this improvement when imaging, the bandwidth of the transducer has to be matched to the bandwidth of the autocorrelation of the HAPI code. This is achieved by performing a Kronecker product on the HAPI code with a sequence of repeated ones as described above. With this adjustment, the bandwidth is closely matched, and the simulations produced the maximum theoretical SNR increase. The phantoms were simulated using an HAPI synthetic aperture method which is not bandwidth-matched to the transducer and an HAPI synthetic aperture method which is bandwidth-matched to the transducer. For comparison, with linear arrays, we also simulated a coherent compounded plane wave imaging method (7 angles), a full synthetic aperture method (firing from each element in succession), and a fast synthetic aperture method (using 3 sub-apertures of 12 elements each).