# Separate key-related frequencies from audio signal

I have various samples of various instruments sound, and I'm trying to classify them using pyAudioAnalysis and various Machine Learning algorithms. The samples record the instrument playing different notes, which obviously alters their frequency spectrum. I am looking for a way to separate the information about the note, ideally by reducing the harmonics of the relevant frequency, so that the feature extraction step does not give relevance to this information. Does it make sense? Is there a "simple" way to achieve this?

• i can't figure out what you mean. what "information about the note" are you trying to filter out? and, by "filter out", do you mean remove to get rid of, or to extract this information from the recorded audio. – robert bristow-johnson Dec 16 '16 at 6:31
• For instance, an instrument playing a 440Hz A note will have a "strong" harmonic around 440Hz, plus various harmonics at 220Hz, 880Hz etc. I would like to remove this information as far as possible, in order to avoid misclassification due to the "note" similarity (eg. two samples from different instruments playing the same note classified as the same instrument). – phagio Dec 16 '16 at 8:10
• well, no, it is possible for a musical note to lack energy at it's fundamental, as long as it has energy in other harmonics. and 220 Hz would be a sub-harmonic to 440 Hz. if there was any appreciable energy at 220 Hz, it would sound like A below middle C not the A above it. so, again, what is the "information" you want removed? its pitch? are you trying to classify instruments independent of their pitch? – robert bristow-johnson Dec 16 '16 at 8:15
• Pitch is the word! Basically yes, since the first attempts of classification yielded sometimes unaccurate results I wanted to verify if removing the pitch information would improve the accuracy. – phagio Dec 16 '16 at 8:23
• You could try to find the fundamental and then shift everything in frequency domain so that all fundamental frequencies are mapped to the same frequency (e.g. 0Hz). But: there'd still be the harmonic "spacing", and that happens to be the same frequency and multiples thereof. – Marcus Müller Dec 16 '16 at 9:29

Attenuating the harmonics of your instruments isn't really a viable option, because you'll end up annihilating the signal itself. The harmonics here are what are sampling the behaviour of your instrument.

I'm not sure if I'd call it simple, but a possible solution to separating the contribution of pitch in such a classification system might be cepstral liftering.

This is, calculate a cepstral representation of the recording of each instrument (the Fourier transform of the logarithm of the frequency response) and separate the periodic components (pitch) from the aperiodic (perhaps timbre?). Such separation is known as liftering - the analog of filtering in the cepstral domain.

The separated signals should roughly correspond to a periodic signal and an impulse response better characterising the instrument.

This is an approach used in to separate the harmonics of speech (carrying pitch information) from the transfer function of the vocal tract (which generates a filter forming vowels amongst other characteristics).

I'm not sure if this will work in your case, but I think it would be worth exploring.

• Thank you for your suggestions, Speedy! I've read around the web about liftering. Do you know about any library around (such as python speech features which would actually be able to 'lifter' these components? – phagio Dec 16 '16 at 15:43
• I'm afraid not, but there's a number of libraries out there that perform the calculation of the cepstrum (such as python-acoustics). If you follow some of the tutorials around on the web the liftering stage should be fairly straightforward to implement. – Speedy Dec 16 '16 at 16:27
• I've just noticed that python_speech_features has a function called ceplifter. This might be what you're looking for? – Speedy Dec 16 '16 at 16:44
• Thank you again, Speedy :) I will delve in these libraries and look for clues. – phagio Dec 18 '16 at 9:33