Measure guitar sound with phyphox audio spectrum

I recorded guitar sounds audio spectra with phyphox(Physical Phone Experiments).

1. I recorded audio spectra of the following acoustic guitar by plucking the 1st and 6th string.

2. I clicked the buttons pointed with the green boxes in the following phyphox screenshots. I started recording by pushing ▶ button in the 2nd picture and stop recording by pushing the stop button in the 3rd picture.

We can save and send recorded data with Excel files by following the procedure described here.

3. I checked the “Raw Data” sheet of the Excel file exported from phyphox and confirmed that the sound data were recorded every 20.833 microseconds. (I used iPhone SE(1st generation).)

4. The following snapshots are the measured audio spectra when I plucked the 1st string of the acoustic guitar. I plucked the open string by tuning 1st string to E4(329.628 Hz).

The 1st picture shows the peak frequency 328.12 Hz that is close to E4(329.628 Hz). The horizontal axis is the audio frequency and the vertical axis is the amplitudes of the sounds corresponding to the frequencies of the horizontal axis. Both vertical and horizontal axes are logarithmic scales. Not only the fundamental frequency E4 (328.628 Hz) but also the 2nd (659.256 Hz) and 3rd (985.884 Hz) harmonics have large amplitudes.
The FFT (Fast Fourier Transform) sampling rate and the operation time are shown at the bottom of the 1st picture. The Raw sound data are recorded with the intervals of 20.833 microseconds. MEMS microphones are used to record the sound pressure with the smartphone. The FFT operation time is 42.67 milliseconds that is 20.833 microseconds multiplied by 2,048 sampling rate.

The graph located at the middle of the 2nd picture is the history of the audio spectra. The vertical axis is the time elapsed from the start of the measurement. The horizontal axis is the audio frequency. The color shows the amplitudes of the frequency components indicated by the horizontal axis. The white color indicates the large amplitude and the black color indicates the small amplitude. The guitar sound began to appear after 0.6 seconds because I plucked the string after I pushed start button with phyphox.

The graph located at the bottom of the 2nd picture shows the time variation of the peak frequency. The peak frequency has the value 680 Hz that is close to 2nd harmonic (659.256 Hz) when the elapsed time is around 0.6 to 0.7 seconds. It becomes around 328 Hz that is close to the fundamental frequency (329.628 Hz) after 0.75 seconds.

As you can see in the 3rd image, we can also change the number of sampling data used in FFT (Fast Fourier Transform). The larger the number of samples, the better the frequency resolution (finer intervals between the frequencies on the horizontal axis). However, it takes more time to acquire and update the data.

The 4th image shows the time series of sound pressure measured by the MEMS microphone every 20.833 microseconds.

5. The graph below is the audio spectrum plotted with Google Charts. The data is same as section 4. Unlike the 1st figure in section 4, the plot is not logarithmic.
The maximum frequency (Nyquist frequency) that can be measured is 24,000 Hz, half the sampling rate of the sound pressure (48,000 Hz). The maximum frequency on the horizontal axis is 23,977 Hz, that is close to 24,000 Hz.

The human audible range is from about 20 Hz to 20,000 Hz. The graph includes frequencies in this range.

6. The horizontal axis of the graph below is logarithmic scale. The data is same as section 5.
The frequency of a note doubles in an octave and the frequencies of the 12 notes within an octave increase by a factor of $\sqrt[12]{2}=2^{\frac1{12}}$. Therefore, it is easier to make the horizontal axis correspond to the musical notes when frequency axes are displayed in logarithmic scale.

Note : 12 notes within an octave

 1 2 3 4 5 6 7 8 9 10 11 12 C C# D$\flat$ D D# E$\flat$ E F F# G$\flat$ G G# A$\flat$ A A# B$\flat$ B ド ド# レ$\flat$ レ レ# ミ$\flat$ ミ ファ ファ# ソ$\flat$ ソ ソ# ラ$\flat$ ラ ラ# シ$\flat$ シ

7. The figure below shows the time variation of the peak frequency.
The peak frequency has the value 679.6875 Hz that is close to 2nd harmonic (659.256 Hz) when the elapsed time is around 0.6 to 0.7 seconds. It becomes around 328.125 Hz that is close to the fundamental frequency (329.628 Hz) after 0.75 seconds.

8. Next, the audio spectrum was measured with phyphox by plucking the 6th open string of an acoustic guitar. The 6th open string was tuned with a pitch of E2 (82.407 Hz). The number of samples used to calculate FFT (Fast Fourier Transform) was 2,048 and the operating time was 42.67 milliseconds.
The graph below shows the audio spectrum plotted with Google Charts.

9. The horizontal axis of the graph below is logarithmic scale. The data is same as section 8.
There is a large peak frequency at about 164 Hz, that is the 2nd harmonic of E2 (82.407 Hz). 70.3125 Hz and 93.75 Hz, which are close to E2 (82.407 Hz), also have large values. The frequency components at 234.375 Hz and 257.8125 Hz, which are close to the 3rd harmonic (247.221 Hz), are also significant.
Since the frequency resolution seemed to be insufficient in the frequency range below 300 Hz, which is the target frequency range, I increased the number of samples used in the FFT (Fast Fourier Transform) calculation to 32,768 and re-measured.

10. The graph below shows the audio spectrum measured by increasing the number of samples used to calculate FFT (Fast Fourier Transform) to 32,768. The horizontal axis is on a log scale. The peak frequency is not at the fundamental frequency E2 (about 82 Hz) but at a frequency closer to the 2nd harmonic (E3: about 165 Hz).

Note 2: I searched the Web for the audio spectrum of a guitar with the 6th string tuned to E2 (82.407Hz). I could not find any audio spectra in which the fundamental frequency E2 (about 82Hz) were peak frequencies. However, I found several audio spectra showing the 2nd harmonic (E3: about 165Hz) or 3rd harmonic (B3:247Hz) as peak frequencies.

Note 3: Time series data of sound pressure recorded on the sheet “Raw Data”
The Excel file exported from phyphox contains time series data of sound pressure on the sheet “Raw Data”. Only a part of the time series data is recorded. The number of recorded time series data is close to the number of input samples for one FFT (32,768 rows when the sampling rate is 32,768).
The time interval at which the time series of sound pressure is recorded is 1/48,000 second (about 0.00002083 seconds).
I found that the topic is discussed in this forum.

The following JavaScript was used.

<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">

drawFFTSpectrumWithSpecifiedIds(query_1st_string, 'audio_spectrum_1st_string', 'audio_spectrum_1st_string_logx');

drawPeakHistoryWithSpecifiedId(query_1st_string_peak_history, 'peak_history_1st_string');

drawFFTSpectrumWithSpecifiedIds(query_6th_string, 'audio_spectrum_6th_string', 'audio_spectrum_6th_string_logx');

drawPeakHistoryWithSpecifiedId(query_peak_history_6th_string, 'peak_history_6th_string');

drawFFTSpectrumWithSpecifiedIds(query_32768_samples_6th_string, 'audio_spectrum_32768_samples_6th_string', 'audio_spectrum_32768_samples_6th_string_logx');

drawPeakHistoryWithSpecifiedId(query_peak_history_32768_samples_6th_string, 'peak_history_32768_samples_6th_string');
}

function drawFFTSpectrumWithSpecifiedIds(query, graph_id, graph_id_logx) {

query.send( function(response) {
const data = response.getDataTable();

// audio spectrum
const options = {title: 'phyphox audio spectrum',
hAxis: {title: 'Frequency [Hz]'},
vAxis: {title: 'FFT Magnitude'}};
chart.draw(data, options);

// audio spectrum : horizontal axis is logarithmic scale
const options_logx = {title: 'phyphox audio spectrum : horizontal axis is logarithmic scale',
hAxis: {title: 'Frequency [Hz]', scaleType: 'log'},
vAxis: {title: 'FFT Magnitude'}};
chart_logx.draw(data, options_logx);
});
}

function drawPeakHistoryWithSpecifiedId(query, graph_id) {

query.send( function(response) {
const data = response.getDataTable();

// Peak History
const options = {title: 'phyphox peak history',
hAxis: {title: 'Time [s]'},
vAxis: {title: 'Peak Frequency [Hz]'}};