Live data from Hacker News

Transcribing Piano Rolls, the Pythonic Way

zulko.github.io

21–30 of 38 posts

Re: Transcribing Piano Rolls, the Pythonic Way

#21

The faster way of doing this: def fourier_transform(signal, period, tt): """ See http://en.wikipedia.org/wiki/Fourier_transform How come Numpy and Scipy don't implement this ??? """ f = lambda func : (signal*func(2*pi*tt/period)).sum() return f(cos)+ 1j*f(sin) is using the FFT. What you want is the power spectral density in the discrete case, called the power spectrum. It can be calculated by multiplying the discrete…

I knew I was going to have this remark :) Now correct me if I am wrong, but I think the FFT (which computes the discrete Fourier transform) cannot replace the continous fourier transform in my case, because the optimal periods I find are non-integer values. In the first case, the holes are separated by 7.5 pixels. The FFT could only have told me that they are separated by 7 or 8 pixels, which is not precise enough. Same thing for the tempo, a beat corresponds to 7.1 frames of the video, and a FFT would have told me 7.

If someone knows a way to use the FFT to get non-integer periods (apart from oversampling the signal) I'll gladly change the code.

Re: Transcribing Piano Rolls, the Pythonic Way

#22
post #21

The faster way of doing this: def fourier_transform(signal, period, tt): """ See http://en.wikipedia.org/wiki/Fourier_transform How come Numpy and Scipy don't implement this ??? """ f = lambda func : (signal*func(2*pi*tt/period)).sum() return f(cos)+ 1j*f(sin) is using the FFT. What you want is the power spectral density in the discrete case, called the power spectrum. It can be calculated by multiplying the discrete…

I knew I was going to have this remark :) Now correct me if I am wrong, but I think the FFT (which computes the discrete Fourier transform) cannot replace the continous fourier transform in my case, because the optimal periods I find are non-integer values. In the first case, the holes are separated by 7.5 pixels. The FFT could only have told me that they are separated by 7 or 8 pixels, which is not precise enough. S…

[deleted]

Re: Transcribing Piano Rolls, the Pythonic Way

#23
post #21

The faster way of doing this: def fourier_transform(signal, period, tt): """ See http://en.wikipedia.org/wiki/Fourier_transform How come Numpy and Scipy don't implement this ??? """ f = lambda func : (signal*func(2*pi*tt/period)).sum() return f(cos)+ 1j*f(sin) is using the FFT. What you want is the power spectral density in the discrete case, called the power spectrum. It can be calculated by multiplying the discrete…

I knew I was going to have this remark :) Now correct me if I am wrong, but I think the FFT (which computes the discrete Fourier transform) cannot replace the continous fourier transform in my case, because the optimal periods I find are non-integer values. In the first case, the holes are separated by 7.5 pixels. The FFT could only have told me that they are separated by 7 or 8 pixels, which is not precise enough. S…

The maximum frequency you can detect is limited by your sampling rate, but there's not a limit on the precision with which you can break those frequencies up.

It's controlled by a parameter NFFT -- the PSD will compute (NFFT/2+1) values evenly spaced between 0 and the Nyquist frequency.

So say the frame rate is 15Hz and you compute with NFFT=2048, then PSD[970] contains the amplitude at 7.09Hz.

This was a really cool project by the way!

Re: Transcribing Piano Rolls, the Pythonic Way

#24
post #21

Earlier quoted context omitted.

I knew I was going to have this remark :) Now correct me if I am wrong, but I think the FFT (which computes the discrete Fourier transform) cannot replace the continous fourier transform in my case, because the optimal periods I find are non-integer values. In the first case, the holes are separated by 7.5 pixels. The FFT could only have told me that they are separated by 7 or 8 pixels, which is not precise enough. S…

The maximum frequency you can detect is limited by your sampling rate, but there's not a limit on the precision with which you can break those frequencies up. It's controlled by a parameter NFFT -- the PSD will compute (NFFT/2+1) values evenly spaced between 0 and the Nyquist frequency. So say the frame rate is 15Hz and you compute with NFFT=2048, then PSD[970] contains the amplitude at 7.09Hz. This was a really cool…

Thanks, I learned something. I will try it and amend the blog when I have time.

Re: Transcribing Piano Rolls, the Pythonic Way

#25
What a fascinating convergence of math, music and Python. Many people I meet who don't specialize in math but have taken university-level courses in it seem to remember the Fourier transform as a highlight, probably because of its many applications.

Re: Transcribing Piano Rolls, the Pythonic Way

#29
post #27

What if you tried to transcribe the music solely from Fourier transform of the audio source? I expect the piano has an abundance of harmonics, but there should be some way to distinguish them from the keys. Hasn't someone done it already?

It's certainly hard

However, this case would be one of the best cases for it, it's a single instrument, and you could make a careful recording out of it

Re: Transcribing Piano Rolls, the Pythonic Way

#30
post #21

Earlier quoted context omitted.

I knew I was going to have this remark :) Now correct me if I am wrong, but I think the FFT (which computes the discrete Fourier transform) cannot replace the continous fourier transform in my case, because the optimal periods I find are non-integer values. In the first case, the holes are separated by 7.5 pixels. The FFT could only have told me that they are separated by 7 or 8 pixels, which is not precise enough. S…

The maximum frequency you can detect is limited by your sampling rate, but there's not a limit on the precision with which you can break those frequencies up. It's controlled by a parameter NFFT -- the PSD will compute (NFFT/2+1) values evenly spaced between 0 and the Nyquist frequency. So say the frame rate is 15Hz and you compute with NFFT=2048, then PSD[970] contains the amplitude at 7.09Hz. This was a really cool…

Also, it's not as widely known as the FFT, but if you know roughly the frequency of interest you can use the Goertzel algorithm to calculate a chosen number of bins around that specific freq and then pick the max of them to find the freq of interest, instead of when using the FFT having to calculate a bunch of bins using a large nFFT in order to get enough freq resolution and then discarding 99% of the results. Going further, compared to the original Goertzel, the Generalized Goertzel algorithm does the same thing but allows you to query non-integer multiples of the fundamental frequency: http://asp.eurasipjournals.com/content/2012/1/56
Post reply on HN