\documentclass{article}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{listings}
\usepackage{xcolor}
\graphicspath{{images/}}

\title{Module 2}
\author{Sebastian Koranda}
\date{September 2025}

\definecolor{codegreen}{rgb}{0,0.6,0}
\definecolor{codegray}{rgb}{0.5,0.5,0.5}
\definecolor{codepurple}{rgb}{0.58,0,0.82}
\definecolor{backcolour}{rgb}{0.95,0.95,0.92}

\lstdefinestyle{code}{
    backgroundcolor=\color{backcolour},   
    commentstyle=\color{codegreen},
    keywordstyle=\color{magenta},
    numberstyle=\tiny\color{codegray},
    stringstyle=\color{codepurple},
    basicstyle=\ttfamily\footnotesize,
    breakatwhitespace=false,         
    breaklines=true,                 
    captionpos=b,                    
    keepspaces=true,                 
    numbers=left,                    
    numbersep=5pt,                  
    showspaces=false,                
    showstringspaces=false,
    showtabs=false,                  
    tabsize=2
}

\lstset{style=code}

\begin{document}
\maketitle

\section*{Exercise 1: Sound Speed and Wave Fundamentals}
\includegraphics[width=\textwidth]{fig1_1.pdf} \\
$$c_{soft-tissue} = 1540 \, \text{m/s}$$
$$c_{water} = 1500 \, \text{m/s}$$
$$c_{bone} = 3200 \, \text{m/s}$$
\pagebreak

\subsection*{Task 1: Basic Sound Speed Calculations}
    \subsubsection*{A)}
    ONE-WAY travel time for ultrasound to reach a target 25 mm deep in soft tissue:
    $$t = \frac{d}{c} = \frac{0.025 \, \text{m}}{1540 \, \text{m/s}} \approx 1.62 \times 10^{-5} \, \text{s} = 16.2 \, \mu\text{s}$$

    \subsubsection*{B)}
    ROUND-TRIP travel time for the same target (25 mm deep):
    $$t_{round-trip} = 2 \times t = 2 \times 16.2 \, \mu\text{s} = 32.4 \, \mu\text{s}$$

    \subsubsection*{C)}
    Given a round-trip time of 52 µs, the depth of the target in soft tissue:
    $$d = \frac{c \cdot t_{round-trip}}{2} = \frac{1540 \, \text{m/s} \cdot 52 \times 10^{-6} \, \text{s}}{2} \approx 0.04004 \, \text{m} = 40.04 \, \text{mm}$$

\subsection*{Task 2: Wave Calculations}
    \includegraphics[width=\textwidth]{fig1_2.pdf} \\

    \subsubsection*{A)}
    Wavelength of 5 MHz ultrasound in soft tissue:
    $$\lambda = \frac{c}{f} = \frac{1540 \, \text{m/s}}{5 \times 10^6 \, \text{Hz}} = 3.08 \times 10^{-4} \, \text{m} = 0.308 \, \text{mm}$$

    \subsubsection*{B)}
    Frequency of a wave with a wavelength of 0.4 mm in soft tissue:
    $$f = \frac{c}{\lambda} = \frac{1540 \, \text{m/s}}{0.4 \times 10^{-3} \, \text{m}} = 3.85 \times 10^6 \, \text{Hz} = 3.85 \, \text{MHz}$$

\subsection*{Task 3: Material Comparison}
    \subsubsection*{A)}
    Round-trip travel time for ultrasound to reach a target 30 mm depth in:
    \begin{itemize}
        \item Soft tissue:
        $$t_{soft} = \frac{2 \times 0.03 \, \text{m}}{1540 \, \text{m/s}} \approx 3.90 \times 10^{-5} \, \text{s} = 39.0 \, \mu\text{s}$$
        
        \item Water:
        $$t_{water} = \frac{2 \times 0.03 \, \text{m}}{1500 \, \text{m/s}} = 4.00 \times 10^{-5} \, \text{s} = 40.0 \, \mu\text{s}$$
        
        \item Bone:
        $$t_{bone} = \frac{2 \times 0.03 \, \text{m}}{3200 \, \text{m/s}} = 1.875 \times 10^{-5} \, \text{s} = 18.75 \, \mu\text{s}$$
    \end{itemize}

    \subsubsection*{B)}
    Wavelength of 3MHz ultrasound in:
    \begin{itemize}
        \item Soft tissue:
        $$\lambda_{soft} = \frac{c_{soft}}{f} = \frac{1540 \, \text{m/s}}{3 \times 10^6 \, \text{Hz}} \approx 5.13 \times 10^{-4} \, \text{m} = 0.513 \, \text{mm}$$

        \item Water:
        $$\lambda_{water} = \frac{c_{water}}{f} = \frac{1500 \, \text{m/s}}{3 \times 10^6 \, \text{Hz}} \approx 5.00 \times 10^{-4} \, \text{m} = 0.500 \, \text{mm}$$

        \item Bone:
        $$\lambda_{bone} = \frac{c_{bone}}{f} = \frac{3200 \, \text{m/s}}{3 \times 10^6 \, \text{Hz}} \approx 1.07 \times 10^{-3} \, \text{m} = 1.07 \, \text{mm}$$
    \end{itemize}

\subsection*{Task 4: Clinical Understanding}
    \includegraphics[width=\textwidth]{fig1_3.pdf} \\

    \subsubsection*{A)}
    We use LOW frequencies (2-5 MHz) for deep abdominal imaging because lower frequencies have longer wavelengths, which allows them to penetrate deeper into the body tissues with less attenuation. Higher frequencies, while providing better resolution, are absorbed more quickly and thus cannot reach deeper structures effectively.

    \subsubsection*{B)}
    We use HIGH frequencies (10-15 MHz) for superficial structures because higher frequencies provide better resolution due to their shorter wavelengths. This allows for more detailed imaging.

    \subsubsection*{C)}
    The trade-off between frequency, resolution, and penetration depth in ultrasound imaging is a balance that must be managed based on the application. Higher frequencies yield better resolution but have limited penetration depth due to increased attenuation. Conversely, lower frequencies penetrate deeper but at the cost of image resolution. One must choose the appropriate frequency based on the target depth and the required image detail.

\subsection*{Task 5: Problem Solving}
    \subsubsection*{A)}
    An ultrasound system is calibrated for soft tissue (c = 1540 m/s). You image through water (c = 1480 m/s) and measure 40 mm depth.
    The true depth in the water is:
    $$d_{true} = \frac{c_{water}}{c_{soft}} \times d_{measured} = \frac{1480 \, \text{m/s}}{1540 \, \text{m/s}} \times 40 \, \text{mm} \approx 38.44 \, \text{mm}$$

    \subsubsection*{B)}
    For lateral resolution better than 0.2 mm in soft tissue, the minimum frequency required is:
    $$r = \frac{\lambda}{2} \Rightarrow \lambda = 2r$$
    $$f_{min} = \frac{c}{2r} = \frac{1540 \, \text{m/s}}{0.4 \times 10^{-3} \, \text{m}} = 3.85 \times 10^6 \, \text{Hz} = 3.85 \, \text{MHz}$$
\pagebreak

\section*{Exercise 2: Receive Beamforming}
\subsection*{Part I: Receive Delay Calculation}
\begin{lstlisting}[language=Octave]
% Element positions
x_element_position = channel_data.probe.x;
z_element_position = channel_data.probe.z;

% Pixel positions
x_pixels = reshape(scan.x, scan.N_x_axis, scan.N_z_axis);
z_pixels = reshape(scan.z', scan.N_x_axis, scan.N_z_axis);

% Analytic signal
ch_data = hilbert(channel_data.data);

% Empty variables of correct dimension
receive_delay = zeros(scan.N_x_axis,scan.N_z_axis,channel_data.N_elements);
delayed_data = zeros(scan.N_x_axis,scan.N_z_axis,channel_data.N_elements);
img = zeros(scan.N_x_axis,scan.N_z_axis);

for rx = 1:channel_data.N_elements
    % Calculate the receive delay for each pixel and each element
    receive_delay(:,:,rx) = ((x_pixels - x_element_position(rx)).^2 + (z_pixels - z_element_position(rx)).^2).^0.5 ./ 1500;
    delayed_data(:,:,rx) = interp1(channel_data.time,ch_data(:,rx),receive_delay(:,:,rx),'linear',0);
    img = img + delayed_data(:,:,rx);
end
\end{lstlisting}
\includegraphics[width=\textwidth]{fig2_1_2.pdf}

\subsection*{Part II: 16 Elements}
The source point is more easily interpreted from an image created with 16 probe elements: \\
\includegraphics[width=\textwidth]{fig2_2_1.pdf}
The ``gaussian\_pulse'' transmit signal argument produces a single pulse, whereas the ``sinus'' argument produces a repeated, sinusoidal pattern. This results in a less clear image, as seen below: \\
\includegraphics[width=\textwidth]{fig2_2_2.pdf}
\pagebreak

\subsection*{Part III: Channel Data Before and After Delay}
\begin{lstlisting}[language=Octave]
psf_x_loc = -0.2/1000;
psf_z_loc = 24/1000;

[~,scatter_pos_indx_x] = min(abs(scan.x_axis-psf_x_loc))
[~,scatter_pos_indx_z] = min(abs(scan.z_axis-psf_z_loc))
\end{lstlisting}
\includegraphics[width=\textwidth]{fig2_3_1.pdf}
We must compensate for each sensor's offset from the reference point (0,0), so that each signal will add constructively and improve the resulting signal-to-noise ratio.

\subsection*{Part IV: Analysis of the Partial and Final Results}
\includegraphics[width=\textwidth]{fig2_4_1.pdf}
\includegraphics[width=\textwidth]{fig2_4_2.pdf}
We use the envelope of the signal, effectively the outline of the extremes of the oscillating signal, to represent the amplitude of the received signal. This is because the raw signal oscillates around zero, a frequency component that is not useful for image representation. The envelope provides a smoother representation of the signal's intensity, which is more relevant for imaging purposes.
    
\end{document}

