Using NMF for guitar pitch detection using fixed pitch template I've seen this guide showing a basic NMF of a spectrogram.

My aim is detect guitar pitch from the decomposition. I want to do this by explicitly create a fixed template of pitches and construct the W matrix from these.

I've seen some papers giving an overview of this, but I am not sure how it's practically done.

Do I record every note on the guitar, then do the FFT for each, take its spectrum, and paste it inside a matrix?

I guess my question is basically: how do I create the fixed W matrix, given a set of recordings with each pitch.

This paper says:


  The whole note sample k is first processed in a short-time sound
  representation supposed to be non-negative and approximatively
  additive (e.g. a shorttime magnitude spectrum). The representations
  are stacked in a matrix $V^{(k)}$ where each column $v^{(k)}_{j}$ is the sound
  representation of the j-th time-frame.


So, does that mean we compute the STFT of the recorded sample? Then we use the resulting spectrogram as $V^{(k)}$?

Also, does the duration of the sample matter? If there is absolute silence in the beginning of the sample, will that affect $v^{k}_{j}$?
The goal of non-negative matrix factorization (NMF) is to factorize (as the name says) a matrix, denoted by $\mathbf{X}\in\mathbb{R}^{(N\times K)}$ in the reference you mention, into the product of two matrices:
$$
\mathbf{W}\mathbf{H}\approx\mathbf{X},
$$
with $\mathbf{W}\in\mathbb{R}^{(N\times M)}$ the template, dictionary, or basis matrix and $\mathbf{H}\in\mathbb{R}^{(M\times K)}$ the activation matrix. The approximation sign ($\approx$) in the equation indicates that in many cases it is not possible to actually find a true factorization but rather an approximation.

Inspecting the above equation reveals that each column of $\mathbf{X}$ is approximated by a linear combination of columns of $\mathbf{W}$, with the coefficients of linear combination in $\mathbf{H}$. (Experimenting with some simple examples, e.g., with $N=3,\,M=3, K=5$ and $\mathbf{X}_{ij}\in\left\{0,\,1\right\}$, will surely help gaining insight into this fundamental behaviour).

In many cases it is desired, given a matrix $\mathbf{X}$, to determine both the dictionary matrix $\mathbf{W}$ and the activation matrix $\mathbf{H}$. Optionally, of course, only one can be estimated if the other is given.

Your goal, if I understand correctly, is to keep $\mathbf{W}$ fixed, estimate $\mathbf{H}$ and use the resulting activations to determine when which note has been played. That should work as a first attempt, I think.

After this coarse overview now for your questions:


You are right: to create the $\mathbf{W}$ matrix put an estimate of each note's power spectral density estimate (e.g., obtained with Welch's method) into a column of $\mathbf{W}$ (I'm not sure what you mean by "do the FFT for each, take its spectrum".).
Yes, the matrix $\mathbf{X}$ in the notation used in this answer ($V^{(k)}$ in the paper that you mention) contains the STDFT magnitude spectrogram of the full input recording.
Silence in the beginning of the recording will obviously have an influence on the first columns of $\mathbf{X}$ (or, respectively, $v_j^{(k)}$ for $j&lt;\text{some number}$). However, what do you guess will happen with $\mathbf{H}$ if the first columns of $\mathbf{X}$ contain zeros or only very small values? Correct: the first columns of $\mathbf{H}$ will also receive zeros or very small values.


I hope this answer helps in clarifying the basic functionality of the NMF algorithm. A rather intuitive description of the NMF idea is also given in this famous paper.