\chapter{Research Background}

\section{Theoretical and Musical Context}

The process of modulation has been an integral aspect of music theory and composition for centuries, playing a crucial role in the structural and emotional development of musical pieces. Modulation allows composers to shift between different keys or tonal centers, providing emotional contrast, dynamic movement, and variety within a piece. It serves as a powerful tool to sustain listener engagement by introducing new harmonic colors, expanding the expressive range, and creating a sense of development and resolution \cite{23}. 

In Western classical music, modulation is typically analyzed in terms of key relationships, harmonic functions, and formal structures. The study of tonal harmony has placed significant emphasis on the rules governing diatonic and chromatic harmony, cadence progressions, and \glspl{mp} that define the transitions between keys \cite{24}. These modulations are often guided by harmonic sequences, chord progressions, and pivot chords that ensure smooth key changes while maintaining coherence \cite{25}.

\subsection{Modulation in Persian Classical Music}
In Persian classical music, modulation plays a more nuanced role, shaped by the specific characteristics of its scales, the use of \glspl{mt}, and the unique modal system it employs \cite{26}. Unlike Western classical music, which relies heavily on harmonic relationships, modulation in Persian music is primarily melodic and microtonal, emphasizing the continuous flow of melodic phrases rather than harmonic progression \cite{27}. 

The concept of modulation in this tradition is deeply rooted in the Radif, a structured collection of melodic motifs and modal structures passed down through generations \cite{28}. The Radif provides both a theoretical framework and a practical guide for composition and improvisation, outlining the relationships between different melodic units and establishing the conventions for modulation within the Persian musical system \cite{29}. 

The Radif consists of a series of "\acrfull{gs}" or smaller melodic motifs, that are grouped into larger modal systems called "Dastgah." Each "Dastgah" represents a unique tonal and emotional space, and the transitions between "\glspl{gs}" within a "Dastgah" or between different "Dastgah"s form the basis for modulation \cite{30}.

\subsection{Computational Approaches to Modulation Analysis}
Despite the rich theoretical foundation of modulation in Persian music, there has been limited computational exploration of how \glspl{mp} can be systematically mapped and analyzed \cite{33}. Traditionally, musicians and composers have relied on their deep understanding of the Radif and the inherent emotional qualities of different scales to make intuitive decisions about modulation \cite{34}. 

With advancements in computational tools and \glspl{ai}, new opportunities have emerged for analyzing musical structures in an objective and systematic manner \cite{35}. The development of machine learning models, particularly neural networks, has enabled researchers to identify patterns in musical data, classify different tonal relationships, and explore new approaches to music analysis \cite{36}.

\subsection{Self-Organizing Maps (SOM) in Music Analysis}
Among these computational techniques, the \glspl{som} algorithm has shown particular promise in clustering and visualizing complex relationships between different musical elements \cite{37}. Developed by Teuvo Kohonen, \glspl{som} are a type of unsupervised \glspl{ai} neural network designed for dimensionality reduction and pattern recognition \cite{38}. 

\glspl{som} have been widely applied in fields such as image processing, speech recognition, and financial forecasting, but their use in music theory and analysis remains relatively novel \cite{39}. The ability of \glspl{som} to cluster data based on similarity makes them a powerful tool for organizing musical modes into structured maps, revealing hidden relationships between different tonal systems \cite{40}. 

\subsection{Research Objectives and Contributions}
This research seeks to address the gap by leveraging \glspl{som} to generate a structured, visual representation of modes based on their intervallic relationships \cite{44}. The goal is to provide a computational tool that can identify smooth \glspl{mp}, taking into account both Western and Persian musical traditions \cite{45}. 

Furthermore, this study introduces an innovative method for evaluating \glspl{mp} by analyzing the distances between adjacent steps in the modulation process \cite{46}. The research also incorporates qualitative evaluations through field surveys, helping validate the effectiveness of the proposed \glspl{mp} \cite{50}. 

Additionally, the study considers the potential applications of these findings in both compositional practice and music education \cite{51}. By providing composers with a structured framework for exploring modulations, this research offers practical tools that can enhance the creative process \cite{52}.

\section{Research Objectives and Scope}

The primary objective of this research is to explore and develop a computational framework for understanding, analyzing, and generating \glspl{mp} between musical scales, with a particular focus on Persian and Western music traditions. Modulation, as a crucial element in musical composition, enables composers to transition between different tonal centers, providing dynamic contrast and emotional depth. This study employs the \glspl{som} algorithm to systematically map musical scales and their relationships by considering key elements such as tonic, dominant, and axis notes, while also taking into account the \glspl{mt} nature of Persian music. Through this approach, the study aims to bridge traditional theoretical knowledge with modern computational methods.

To achieve this overarching goal, the research is structured around the following key objectives:

\begin{enumerate}
    \item Examine the Neighborhood of Keys and \glspl{gs} in Persian Music.
    \item Analyze Interval Changes and Clustering of Key Classes.
    \item Apply the \glspl{som} Algorithm to Musical Scales.
    \item Evaluate the Effectiveness of \gls{ai}-Generated \glspl{mp}.
    \item Investigate the Role of the Evident Note (Shahed) in Modulations.
    \item Compare Traditional and Computational Approaches to Modulations.
    \item Develop a Practical Application for Composers and Music Theorists.
\end{enumerate}

\subsection{Scope of the Research}

The scope of this research encompasses both Persian and Western musical traditions, focusing specifically on how modulation operates within these systems. In Persian music, the emphasis lies in understanding microtonal transitions and the unique modal structures defined by the Radif and Dastgah frameworks. For Western music, the study examines harmonic progressions and key relationships based on diatonic and chromatic principles.

The computational aspect of the research involves the application of \glspl{som} for dimensionality reduction and visualization of tonal relationships. By combining quantitative evaluations, such as \acrfull{qe}, \acrfull{te}, and \acrfull{rp}, with qualitative assessments from musicians and listeners, this research ensures a holistic understanding of modulation. The ultimate goal is to develop practical tools that support both compositional creativity and theoretical exploration, bridging traditional insights with modern computational techniques.


\section{Modulation in Music Theory}

Modulation refers to the process of changing the key or tonal center in a piece of music. It is a key concept in both Western and non-Western musical traditions. It allows composers to explore different emotional landscapes, expand musical possibilities, and create contrast in a musical composition. Modulations provide a sense of progression and transformation, and increase the emotional depth of a piece. It is a technique that enables the composer to develop musical ideas by changing the tonal center, creating a sense of movement and variety. Modulations can occur in a variety of ways, smoothly or abruptly, with the latter typically creating a more dramatic effect that can evoke stronger emotional responses. Modulations are often intended to evoke a sense of change or development. They guide the listener's emotional journey and add a dynamic quality to the music. The transition between keys can highlight contrasts between different emotional states, giving rise to feelings of tension, release, or resolution \cite{60}.

Figure \ref{fig:figure1} illustrates the number of the smallest musical units, called commas, between each musical note within an octave, totaling 53 commas. Altering the spacing of notes within the octave generates a new algorithm, evoking various emotional and psychological responses in the listener. Additionally, a fundamental condition for forming a musical scale is that, in any configuration of note intervals within an octave of that scale, there must always be 53 commas \cite{61}.

\begin{figure}[H]
    \centering
    \includegraphics[width=0.7\linewidth]{images/chapter2/Figure (1).png}
    \caption{The intervals between musical notes create a distinct pattern.}
    \label{fig:figure1}
\end{figure}

In Western classical music, modulations are traditionally achieved through a variety of techniques. These include the pivot chord method, direct modulation, and common-tone modulation. In the pivot chord method, a chord common to both the current key and the new key is used to bridge two tonal centers. Direct modulation involves an immediate and clear change from one key to another, often without any transitional chords, resulting in an abrupt but often effective change. Common-tone modulations use a single note or tone that remains constant while the surrounding harmonies change, making the change less noticeable. These techniques help ensure that modulations are smooth and consistent, allowing for a seamless transition from one key to another. The smoothness of modulations is considered crucial to maintaining the flow of the music and ensuring that the listener does not perceive the change as jarring or disruptive. This ability to modulate smoothly enhances the emotional continuity of the music, providing a sense of unity even as the tonal center changes \cite{61}.

Figure \ref{fig:figure2} illustrates that the position of each note can be represented as an index in an array, where each index corresponds to a comma of spacing. Any musical scale depicted in this system assigns the tonic note a fixed index of 0. For example, if the second degree of the scale has an index of 9 and the third degree has an index of 13, there is a distance of 4 commas (equivalent to a musical semitone) between them. In this figure, the pattern of the A minor scale is visible, with each degree having an index corresponding to its position \cite{62}.
\begin{figure}[H]
    \centering
    \includegraphics[width=0.9\linewidth]{images/chapter2/Figure (2).png}
    \caption{Example of the A minor scale, showing the index of each degree on the list of available commas.}
    \label{fig:figure2}
\end{figure}

In Persian classical music, known as Radif, modulations is similarly an essential element for emotional expression. The Radif consists of a series of musical phrases and melodic patterns that serve as a structure for improvisation and composition. These phrases are organized in a way that guides the performer in creating music that is both structured and free-flowing. The concept of modulations in Persian music, however, differs from Western practices, as it involves shifts between various modes, called "Dastgah." These Dastgah are distinct melodic structures that define the emotional and tonal landscape of a piece. The use of \glspl{mt}, which are intervals smaller than those found in the Western tuning system, plays a key role in the modulations process. Persian music often involves modulating between Dastgah that are similar in terms of their intervallic relationships, creating subtle changes in tone without abrupt shifts. The smoothness of modulations in Persian music is largely dependent on the degree of similarity between different Dastgah, which influences how pleasant or abrupt the modulations feels to the listener. When the transition between two Dastgah is smooth and gradual, it enhances the emotional impact of the music, providing a sense of continuity and development. However, if the modulations is less smooth, it can create a sense of tension or surprise, adding dramatic effect to the piece.

Therefore, while the basic concept of modulations is common in both Western and Persian music, the methods and effects of modulations differ significantly due to distinct musical structures and cultural contexts. The use of \glspl{mt} and the emphasis on smooth transitions in Persian classical music offer unique challenges and opportunities for composers and performers, distinguishing it from the approaches used in Western classical traditions. These differences underscore the richness of modulations as a tool for emotional expression, as it allows musicians to explore the full range of tonal possibilities within their respective musical systems \cite{63}.

\section{Bresenham's Algorithm}

Bresenham's Algorithm, developed by Jack Bresenham in 1962, is a highly efficient algorithm used to draw straight lines on a raster grid (pixel-based grid). It is an integer-based algorithm that minimizes the need for floating-point operations, making it particularly useful in computer graphics, especially on devices with limited processing power. This section provides a step-by-step explanation of the algorithm, including the relevant mathematical formulas and key steps of the method. The details of Bresenham's Algorithm can be found in \cite{81}.

\subsection{Step 1: Initialization}

The first step in Bresenham’s line-drawing algorithm is to initialize the decision parameters. Given two points \((x_0, y_0)\) and \((x_1, y_1)\) that define the line, the algorithm computes the differences in the x and y directions:

\begin{equation}
\Delta x = x_1 - x_0, \quad \Delta y = y_1 - y_0,
\end{equation}

where \(\Delta x\) is the horizontal change and \(\Delta y\) is the vertical change between the two endpoints.

Next, the initial decision parameter \(p_0\) is computed. This parameter helps to determine the next pixel to be selected. The initial decision parameter is given by:

\begin{equation}
p_0 = 2 \Delta y - \Delta x.
\end{equation}

This decision parameter is used to determine whether the next pixel will be directly to the right of the current pixel (horizontal step) or one pixel up and one pixel to the right (diagonal step).

\subsection{Step 2: Iterative Process}

Starting from the initial pixel \((x_0, y_0)\), the algorithm determines the next pixel to plot by checking the value of the decision parameter \(p_k\), which is updated at each step. If \(p_k\) is less than zero, the next pixel is chosen horizontally (i.e., one step to the right). If \(p_k\) is greater than or equal to zero, the next pixel is chosen diagonally (i.e., one step up and to the right).

The decision parameter is updated as follows:

\begin{equation}
p_{k+1} = p_k + 2 \Delta y, \quad \text{if} \quad p_k < 0,
\end{equation}
\begin{equation}
p_{k+1} = p_k + 2 (\Delta y - \Delta x), \quad \text{if} \quad p_k \geq 0.
\end{equation}

This process continues until the endpoint \((x_1, y_1)\) is reached.

\subsection{Step 3: Symmetry Considerations}

Bresenham’s algorithm is symmetric, meaning that the same principles can be applied to lines with different slopes (positive, negative, shallow, or steep). Depending on the values of \(\Delta x\) and \(\Delta y\), the algorithm can be adapted to handle lines that go in different directions:

For lines with a slope less than 1 (shallow lines), the algorithm prioritizes horizontal movement, and the decision parameter is updated based on \(\Delta x\).
For lines with a slope greater than 1 (steep lines), the algorithm prioritizes vertical movement, and the decision parameter is updated based on \(\Delta y\).

To handle these cases, the algorithm swaps \(\Delta x\) and \(\Delta y\) accordingly, ensuring that the process works for all types of lines.

\subsection{Step 4: Algorithm Termination}

The algorithm continues the iterative process until it reaches the final point \((x_1, y_1)\). At each step, it selects the appropriate pixel based on the decision parameter and updates the decision parameter according to the formula provided. Once the final point is reached, the line has been successfully drawn between the two given points.

The final output is a set of pixels that approximate a straight line between the points \((x_0, y_0)\) and \((x_1, y_1)\). The simplicity and efficiency of the algorithm make it an excellent choice for real-time line drawing in raster-based graphics systems.

\subsection{Example}

To illustrate the algorithm, let’s consider an example where the starting point is \((x_0, y_0) = (2, 3)\) and the ending point is \((x_1, y_1) = (10, 7)\). The steps are as follows:

\begin{itemize}
    \item Initialize: \(\Delta x = 10 - 2 = 8\), \(\Delta y = 7 - 3 = 4\), and \(p_0 = 2 \times 4 - 8 = 0\).
    \item At each step, update the decision parameter and choose the appropriate pixel (either horizontal or diagonal).
    \item Continue this process until the line reaches the endpoint \((10, 7)\).
\end{itemize}

This approach ensures that the line is drawn efficiently, pixel by pixel, while minimizing floating-point operations.

\subsection{Advantages of Bresenham’s Algorithm}

Bresenham’s Algorithm offers several advantages over other line-drawing algorithms:

\begin{itemize}
    \item Efficiency: The algorithm uses only integer arithmetic, making it very fast and suitable for hardware implementation.
    \item Accuracy: It produces a visually accurate approximation of a straight line.
    \item Simplicity: The algorithm is simple to implement and has a low computational cost.
\end{itemize}

These advantages have made Bresenham’s Algorithm widely used in computer graphics, especially in raster graphics editors like in Figure \ref{fig:figure_bresenham}, rendering engines, and real-time graphics applications \cite{81}.

\begin{figure}[H]
    \centering
    \includegraphics[width=0.8\linewidth]{images/chapter2/Figure_bresenham.png}
    \caption{A graphical representation of the line drawn using Bresenham's Algorithm \cite{81}.}
    \label{fig:figure_bresenham}
\end{figure}

\section{\glspl{mt} in Persian Classical Music}

\glspl{mt} are intervals smaller than a semitone and play a significant role in Persian classical music. Persian music scales often include intervals that fall between the notes of the Western chromatic scale, creating a distinct sound that is not typically present in Western music. These \glspl{mt} are an essential part of the Persian musical system, and their use enables composers and performers to create more subtle tonal variations, adding layers of emotional depth and nuance to the music. \glspl{mt} provide the musician with the ability to explore fine gradations of pitch, which allows for a richer and more varied emotional expression. The flexibility of \glspl{mt} opens up a broader spectrum of tonal possibilities, giving the music a unique character that can be both intricate and profoundly expressive.

In Persian classical music, the term "Dastgah" refers to a system of modes, each characterized by a particular arrangement of intervals that define the mood and atmosphere of the music. These Dastgah are the building blocks of Persian music and serve as a guide for improvisation and composition. Each Dastgah contains a series of \glspl{mt}, such as quarter tones and other intervals that lie between the standard Western pitches. The use of these \glspl{mt} allows Persian music to achieve subtle tonal variations that evoke a range of emotions, from serenity to intensity, making the music deeply emotional and engaging. These microtonal shifts create a sense of fluidity in the tonal landscape, where the pitch can gently bend and flow, enhancing the expressive qualities of the performance.

The "Shahed" (evident note) plays a pivotal role in many Dastgah, serving as a reference note around which the melody revolves. This note acts as an anchor point in the tonal structure of the piece, providing both stability and direction. The Shahed is crucial for defining the emotional and tonal center of the piece, guiding the listener's emotional journey and providing a sense of resolution when the melody returns to it. The role of the Shahed is central to the overall expressiveness of the music, as it helps to shape the mood and character of the performance. It is around this note that the performer improvises, creating variations and embellishments that highlight the unique characteristics of the Dastgah \cite{64}.

In music, the central note of a melody is represented by its scale degree. For example, in Figure \ref{fig:figure3}, the second degree of the A minor scale is shown as the central note. The second degree of the A minor scale is the note B. Therefore, the scale degree chosen as the central note is determined based on the tonic of the scale.

\begin{figure}[H]
    \centering
    \includegraphics[width=0.9\linewidth]{images/chapter2/Figure (5).png}
    \caption{The "Shahed" (axis) note in Persian music.}
    \label{fig:figure3}
\end{figure}

The presence of \glspl{mt} in Persian music challenges the standard Western theory of modulations, which is based on the assumption of equal-tempered tuning and fixed intervals between notes. Traditional methods of modulation used in Western music, such as axial chords and common-note modulations, rely on the concept of fixed intervals between notes. However, the \glspl{mt} in Persian music do not fit neatly into the Western system of tuning, making it difficult to apply these standard techniques directly. As such, understanding the nature of \glspl{mt} and how they influence modulations in Persian classical music is crucial for developing a model that can effectively handle modulations between Persian and Western music scales. This requires a more flexible approach that accounts for the unique characteristics of \glspl{mt} and their role in shaping the emotional and tonal qualities of Persian music. A deeper understanding of how \glspl{mt} function in modulations will provide valuable insights into how Persian and Western music can interact and how modulations can occur smoothly between the two systems.

By recognizing the importance of \glspl{mt} in Persian classical music, this research seeks to bridge the gap between Western and Persian music theory, developing a framework that respects the nuances of both traditions. The study aims to provide a comprehensive understanding of how microtonal shifts impact the modulations process and how they can be incorporated into a unified model for analyzing and generating \gls{mp} across different musical systems.

\section{\gls{som} Algorithm}

The \gls{som} algorithm, developed by Teuvo Kohonen in the 1980s, is an unsupervised learning method used for clustering and dimensionality reduction. \gls{som} maps high-dimensional data into a lower-dimensional grid while preserving topological relationships. This section will describe the \gls{som} algorithm step by step, with mathematical formulas and detailed explanations of each phase of the algorithm. The details of the algorithm, as well as its application in various fields, can be found in the work of Kohonen and other studies \cite{67}.

\subsection{Step 1: Initialization}

The first step in the \gls{som} algorithm is to initialize the weights of the grid nodes. Each node in the grid has an associated weight vector, which has the same dimension as the input data vectors. The weight vectors are typically initialized with small random values. Let the weight vector of node \(i\) at time \(t=0\) be denoted as:

\begin{equation}
\mathbf{w_i}(0) = \text{random initialization},
\end{equation}

where \( \mathbf{w_i}(0) \) is the weight vector for node \(i\), and the initialization values are chosen randomly from a small range. 

\subsection{Step 2: Competition Phase}

Once the weights are initialized, the next step is to determine the Best Matching Unit (BMU). The BMU is the node whose weight vector is closest to the input vector. The distance between the input vector \( \mathbf{x} \) and each node's weight vector \( \mathbf{w_i} \) is computed, typically using the Euclidean distance:

\begin{equation}
d(\mathbf{x}, \mathbf{w_i}) = \|\mathbf{x} - \mathbf{w_i}\|_2,
\end{equation}

where \( \mathbf{x} \) is the input vector, \( \mathbf{w_i} \) is the weight vector of node \(i\), and \( d(\mathbf{x}, \mathbf{w_i}) \) is the Euclidean distance between them. The BMU \( \mathbf{w_{bm}} \) is the node that minimizes this distance:

\begin{equation}
\mathbf{w_{bm}} = \arg\min_i d(\mathbf{x}, \mathbf{w_i}).
\end{equation}

\subsection{Step 3: Adaptation Phase}

After identifying the BMU, the next step is to update the weight vectors of the BMU and its neighboring nodes to make them more similar to the input vector. The update rule for the weights is given by:

\begin{equation}
\mathbf{w_i}(t+1) = \mathbf{w_i}(t) + \eta(t) h_{i, bm}(t) (\mathbf{x} - \mathbf{w_i}(t)),
\end{equation}

where:
\begin{itemize}
    \item \( \mathbf{w_i}(t) \) is the weight vector of node \(i\) at time \(t\).
    \item \( \mathbf{x} \) is the input vector.
    \item \( \eta(t) \) is the \acrfull{lr} at time \(t\).
    \item \( h_{i, bm}(t) \) is the neighborhood function that determines the influence of the BMU on neighboring nodes.
    \item \( t \) is the current iteration of the algorithm.
\end{itemize}

The neighborhood function \( h_{i, bm}(t) \) typically decreases over time, meaning that the influence of the BMU on neighboring nodes becomes smaller as the algorithm progresses. A common form of \( h_{i, bm}(t) \) is:

\begin{equation}
h_{i, bm}(t) = \exp\left( -\frac{d(i, bm)^2}{2 \sigma(t)^2} \right),
\end{equation}

where \( d(i, bm) \) is the distance between node \(i\) and the BMU, and \( \sigma(t) \) is the radius of the neighborhood, which also decreases over time.

Figure \ref{fig:figure13} illustrates a graphical representation of sigma (neighborhood radius) and the \gls{lr}, showing how updates affect neighboring nodes based on their distance to the center.

\begin{figure}[H]
    \centering
    \includegraphics[width=0.7\linewidth]{images/chapter2/Figure (22).png}
    \caption{A graphical representation of sigma (neighborhood radius) and \gls{lr} (the effect of updates on neighboring nodes based on distance to the center).}
    \label{fig:figure13}
\end{figure}

\subsection{Step 4: Iteration and Convergence}

The \gls{som} algorithm proceeds iteratively. In each iteration, a new input vector \( \mathbf{x} \) is presented to the network, and the BMU and weight updates are computed. Over time, the \gls{lr} \( \eta(t) \) and the neighborhood radius \( \sigma(t) \) decrease, and the map becomes more refined. The \gls{lr} typically follows a schedule such as:

\begin{equation}
\eta(t) = \eta_0 \exp\left(-\frac{t}{T}\right),
\end{equation}

where \( \eta_0 \) is the initial \gls{lr}, \( t \) is the current time step, and \( T \) is the total number of iterations.

The algorithm continues until the weight vectors converge, meaning that the positions of the nodes no longer change significantly with additional iterations.

\subsection{Step 5: Final Map}

Once the algorithm converges, the nodes in the network represent similar clusters. The input data points of the final map represent the underlying structure of the data. Similar data points are grouped together in the same or adjacent nodes. The SOM map can be visualized as a two-dimensional grid, where each node represents a cluster of input vectors. The organization of the network reflects the relationships between data points, with similar data points mapped to adjacent nodes.

\gls{som} algorithms are capable of discovering complex structures in the data, and the final map provides a clear visual representation of these structures, as illustrated in Figure \ref{fig:figure4}. This approach has been successfully applied to various fields, including music theory, where \gls{som} have been used to model the relationships between musical scales, harmony, and modulation pathways, as discussed in \cite{67}.

\begin{figure}[H]
    \centering
    \includegraphics[width=0.6\linewidth]{images/chapter2/Figure (17).png}
    \caption{A schematic representation of the \gls{som} network \cite{67}.}
    \label{fig:figure4}
\end{figure}

In the context of music theory, \gls{som} have been used to model various aspects of musical structure, such as harmony, tonality, and modulation. By clustering musical scales based on their intervallic structures, \gls{som} can reveal relationships between different musical modes and help identify smooth modulation pathways. This approach allows for a deeper understanding of how different scales are related and how modulations between them can occur seamlessly \cite{67}.
