• ### Recording 1 sec and then find frequency

Hi,

I am totally new to pure data.

I'm looking for a patch to record something (hit on a drum or glass etc.) for about 1 sec and then check the main frequency of that recording.

The fiddle object can only compute frequencies down to 53 hz, right?
But i need down to 20-30 hz.
And real time is not needed, so i think first record 1 sec and right after that
compute the frequency would be right.

How can this be achieved?

Thanks,

Frank

• Posts 11 | Views 4867
• If you increase the FFT size in [fiddle~], you can lower the frequency threshold. Just make sure the FFT size has enough samples to hold a full cycle (and maybe a bit extra) of the minimum frequency you need.

Just a heads up, you may not have the greatest success finding the "pitch" of drums and percussion since they don't have a harmonic spectrum.

Also, if real time is not needed, you might want to look at [sigmund~] instead. It's supposedly a little better than [fiddle~], anyway, and it will also quickly analyze sounds stored in arrays.

i'll look at sigmund~

But isn't there something like a main frequency in percussion and in general in all "objects"?

• It really depends on the instrument itself, and it's still worth a try.

In order for a sound to be truly considered "pitched", the frequencies should be harmonically related, meaning that all frequencies are integer multiples of the fundamental frequency. In reality, they aren't always perfectly integer multiples (for example, the length and thickness of piano strings causes some diffusion, so the frequencies are slightly stretched), but they're close enough.

Most common pitched instruments involve energy moving along a string or through air in a tube. In both cases, the energy is more or less following one path (i.e., it's one-dimensional). With percussion and "noisy" instruments, the energy goes in various directions along two or three dimensions, and the reflections back and forth are what determine the node that those frequencies resonate on. Those nodes aren't necessarily harmonically related since they don't all sit on the same path like they do on strings.

Percussion instruments that are considered pitched often sound pitched because there is a dominant frequency that ear latches onto, which may be imposed onto it by design (for example, xylophone blocks rest on nodes that cause non-harmonic frequencies to be muted). But in other "noisy" cases, it's just because one frequency is much loader, like band-pass filtered noise or the resonant frequency of a snare drum's body.

I'm pretty sure [fiddle~] tries to latch onto harmonically-related frequencies to determine the pitch. But if there is too much noise, it might get confused. So it might work, but it will depend on the design of the instrument. I wouldn't expect to get good results with snares or cymbals, but you might get something from toms or wood blocks.

• Thanks Maelstorm,

but as i know, Timpanies e.g. are really tuned

and that some drummers tune there drums in e.g. 5 semitones difference (toms)

or the bassdrum to the key of a song.

Maybe i shouldn't just use the ready-to-use object fiddle, but build a patch with rfft?

As i said I'm new to puredata and also new to dsp so i need a startingpoint.

I'm going to use libpd later on, so i could add some computations or controlling,
if necessary, once i got the spectral analyzing (right word?) and of course the knowhow;)

So this would be the steps:

• record 1 sec
• do the fft (real or complex??---totally new to dsp...)
• look at the data and find the fundamental (in the "host" of libpd, if needed, better in pure data itself)
• @newbie40 said:

isn't there something like a main frequency in percussion and in general in all "objects"?

hmm,

logically speaking, you would definitely have to say no.

if you just take a burst of random white noise, and run that through an envelope, it's going to sound something like a percussion hit. Really oldschool drum machines used not much more to create rudimentary drum sounds (snares, etc).

by definition, white noise is just a randomisation of all possible frequencies within the given bandwidth, so you really cannot say that there is any main frequency.

a lot of percussion contains such noise/randomisation elements, which certainly hinders the search for which 'tone' is most prominent.

then, you also run into the issue that the 'body' of percussion instruments will actually alter over time, thus creating a 'woop' upward moving tonality, or a 'doop' downward moving tonality. Old analogue drum modules usually have some sort of tone bend function to allow for this. If you try to do frequency analysis, then it's going to be hard, as the frequency does change over time.

something like your example of striking a glass is probably going to be your best bet to find a distinct tone, and in that case, you'll probably do well to ignore the first part of the sound, as the glass is first struck, and concentrate on the tail end of the sound where the glass resonates at its resonant frequency. You can use sigmund~. fiddle~, katja's new analysis tool she made (helmholtz~): http://puredata.hurleur.com/sujet-6776-helmholtz-guess
..or you could try to learn FFT and all that for yourself.

but it's a tricky one, i think....perhaps you should even start with just trying to analyze more traditionally 'tonal' sounds, and then see how you go from there? percussion would seem like just about the hardest thing you could possibly choose for a first project, i reckon.

• oh, and i might be wrong here, cos i haven't done a lot of this myself, but i don't think you need to record your audio first.

with any of the listed methods for pitch detection, you can set a window size for analysis, so if you want 1 second, then just use somewhere around 44100 samples. Usually i think you have to do window size as a power of 2, so maybe 32768 samples...or whatever. I have a feeling this might make your computer slow down a lot though, so experimentation might be the key. I just tried sigmund~ with a huge window like that though, and it worked ok here.

• @newbie40 said:

Maybe i shouldn't just use the ready-to-use object fiddle, but build a patch with rfft?

If you're new to dsp, you might be in over your head doing that. Pitch detection isn't the easiest thing in the world.

Again, I'm not saying you won't get the results your after, I'm just saying the algorithm for [fiddle~] and [sigmund~] is geared toward instruments with a harmonic spectrum. So you might not get good results (and I don't actually know what your samples sound like anyway). I was just trying to give you a heads up in case you were confused as to why it isn't working. But there's no sense in designing your own algorithm if you don't yet know if the ones provided will work for you. So just try it.

I would suggest to just try running your samples through [sigmund~] and sense what it gives you first. Try it in "pitch" mode and run the output through [osc~] and see if it sounds like the right pitch. If not, you could try it in "peaks" mode, which will output all of the detected frequencies in order of amplitude. That might help you determine the dominant frequency that gives the ear a sense of pitch even if the spectrum is not harmonic.

• It's funny that I stumbled upon this thread just after a few frustrating days trying to build a 'slice autotune' function.

For testing, I used a sound which to my ears couldn't be more clearly tuned: a wine glass. But the routine failed with unacceptable percentage. Initially I thought it was because of the transient having a different pitch than the decay. Then I started to write pitch messages into a graph, to get a visual pitch envelope. To my surprise, the 'wrong pitch' was not by definition in the transient phase, it could also happen somewhere else and it was well-defined. Apparently, a wine glass note has more than one trackable pitch. How come?

For the ear, there is only one pitch in a wine glass. So probably the other pitch is result of some reproducible modulation, the source of which I did not find yet.

In the end, it may be the case that a wine glass sound has some characteristics of a bell, which is known to be non-periodic. Still, even a bell has a perceived 'tone-height'. Would there be a way to track this? Considering the difficulties which are still encountered in regular pitch tracking of periodic sounds, I fear that tracking such psycho-acoustic aspects are not within reach of us dsp hobbyists. It's a fascinating topic though! I will continue my stubborn experiments.

Katja

• hi,
sorry for that late post, i was busy with other things and thanks for your answers.

I decided to first do it in java as I'm new to dsp and new to pure data but not so new to java.
So this is not really a pure data related question but a dsp related one, i hope you don't mind.

I focused on getting the fundamental frequency of a drum:
I record 65536 samples at 44100 hz and than do a fft with these samples.
When i plot the range from 0-1000hz (~the range of interest for drums),
i get 3-5 frequency-peaks. For human eyes it is simple to see the first (lowest frequency) peak, which would be the fundamental frequency.
But the first is not always the loudest , so i can't iterate over the fft output to find the bin with the strongest power.
So how do i get the first peak programmatically?
Or the 3-5 peaks mentioned above, so i could take the one with lowest frequency.
As said, the peaks are clear peaks, for eyes no problem to see the first (fundamental).
As the peaks a really clear it shouldn't be so difficult to get them---but how?
The question is, what is a peak in programmatic expression.
What does the human eye do when looking at the plot?

I hope someone could explain me in easy steps what to do with the fft output

Thanks very much

• Finally got back to this topic. After some more experiments I found that the wine glass has inharmonic content, like so many percussive sounds. The lowest component is by far the strongest, and therefore perceived as a clear pitch. However, the inharmonic overtones tend to spoil the pitch analysis, as they cause amplitude modulations, the periods of which are much longer than the lowest tone. So the pitch reports jump from this low erroneous pitch report to the pitch as perceived by the ear.

In this situation, it is easy to just ignore those lower pitch reports and calculate the average value for the higher pitch reports. See attached patch [notepitch] based on [sigmund~] (but I've also done it with my own pitch tracker [helmholtz~] which works equally well).

Katja

http://www.pdpatchrepo.info/hurleur/notepitch.zip

Posts 11 | Views 4867
Internal error.

Oops! Looks like something went wrong!