Reply by August 31, 20072007-08-31
@Markus
Darn... I forgot to mention that I am actually working on the
application written in Java (but even similar things would be good -
e.g. C, C++, C#). I am sorry about that. What I can hope is that this
will help somebody else looking for the solution in Matlab.

>But please don't use it in elevators, pacemakers or thermonuclear
missiles. < Darn... :))))) Just kidding, this is, as you said, "It will work just fine in an arts project or whatever. "-type of thing. @Rune
> Then read a book on the subject, contemplate what you read,
and become less confused. < You think the book is the only solution? Is there something smaller for the start? Look at the end of the post for the reasons why. Look at my previous post for at least one solution that is not a book.
> Sure. And I would just love to find that pile of gold everybody
knows is where the ranbow ends. < Oh, come on! As if it never happened to you that you did something that was hard much easier then you thought (and it worked). I am not searching for a gold fish granting me three wishes (although one would be good :). As the matter of fact, you should have read my previous post before writing your own. I already found the solution and gave a link to it. It's quite simple (one web page), took me 2 hours to swallow (together with researching other things), I am implementing it now and it is working as a charm for what I need.
> Maybe you don't want that, but that's a brilliant
way to start, if you want to learn something. < Maybe. Read my previous post to see what I want.
> You are really something, aren't you? How much maths
can you learn in two days? < Nope, unfortunately... :( That is why I would like to avoid the maths as much as possible. Since everybody else is telling me this is not a good way, maybe it definitely is not. Although, I had one very big thing behind myself that I also asked on Google groups (not comp.dsp) some time ago and everyone was telling me it's just not going to work as I proposed, but it actually worked much better then I imagined. I am so happy I did it as I thought and it worked. It wasn't pure luck it worked - it's a huge system, luck just doesn't happen with these.
> I might have one or two suggestions, but they would require
some actual *work* on your part. reading books, working through the mats, playing with code examples. You have already excluded all of that from your list of acceptable activities, so mentioning such options is a mere waiste of time. Rune < I agree with all you said. I seem to be completely misunderstood on the matter. I am not excluding all that, I am just searching for the easiest solution. Propose me a few solutions - I would choose the one that I think is better. If it takes a year to do it, I just cannot invest that much into this - is this so hard to understand?. I am OK with doing all the stuff you mentioned, but if you understand me - I rather wouldn't. If it's a must, then... Is this clearer right now? Why are you people so pessimistic? Instead of telling somebody what to do, you are telling some sarcastic philosophy stories. Maybe I wanted too much, maybe I didn't explain myself well, maybe this, maybe that, but - why do you think everything somebody else does is not working hard enough, not doing it right, not smart enough, not this, not that? If you think I am wrong, good - tell me as you did. However, your post is equally worthless if you don't tell me how to do it better. You told me - read a book. Yes, I am so dumb I couldn't have figured that by myself? Thanks. You always think there are no other reasons for somebody not doing something than what is directly obvious to you. You told me - work. As if I don't know that is a necessity? Anyway, this is also a rant by me - just had to :) Key: if you want to help, help. Not only me - this is a public group, many people will find this useful. Help, but in the right way. If you see somebody asking a question, somebody who doesn't know how to do something, tell him how to do it and/or how to do it better. Don't tell him he doesn't know how to do it - he wouldn't have asked the question if he knew the answer.
Reply by mnentwig August 31, 20072007-08-31
Hello,

Here's a matlab / octave example that picks the peak from the spectrum.
Read the disclaimers from previous posts. 

It will work just fine in an arts project or whatever. 
But please don't use it in elevators, pacemakers or thermonuclear
missiles.

A "test signal" (C3):
http://www.elisanet.fi/mnentwig/note.wav

Below the program. It also plots the spectrum.

Cheers

Markus


% read wave file
close all; clear all;
[y, fs, bits]=wavread('note.wav');
[n, nChan]=size(y);

% calculate the frequency corresponding to each FFT bin.
% this includes negative frequencies!
freqbase=fs*(mod(((0:n-1)+floor(n/2)), n)-floor(n/2))/n;

% apply window and get FFT. "Hamming" could be omitted
spectrum=fft(y .* hamming(n)); 

% get power (square of bins)
spectrum=spectrum .* conj(spectrum);

% pick out the audible range (for plotting)
bin1=min(find(freqbase > 16));
bin2=min(find(freqbase > 16000)-1);
spectrum=spectrum(bin1:bin2);
freqbase=freqbase(bin1:bin2);

% plot
plot(freqbase, 10*log10(spectrum+1e-15)); xlabel('f/Hz'); ylabel('p/dB');

% peak search
peak=find(spectrum==max(spectrum));
fPeak=freqbase(peak)

% the example note is a keyhole C => 9 semitones below 440 Hz "A"
fActual=440*power(2, -9/12)

Reply by Ron N. August 31, 20072007-08-31
On Aug 30, 8:45 pm, wi...@yahoo.com wrote:
> >Alas, you picked some sounds that are not at all > simple, nor single frequency, even though you might > think they are. The notes a piano makes can be far > more spectrally complicated, than, say, a tuning > fork or flute. Same with may car horns and buzzers. > > Might want to start out by looking at these sound > waveforms on a 'scope, or spectrum analyzer. > < > Yes. To correct myself - by "single frequency" I meant "single strong > frequency". Maybe I am still wrong, but I think most of these have a > very strong frequency which I called "main frequency" in my previous > posts, while the other frequencies are much weaker. Although I know > they cannot be left aside, the other frequencies have the strength > that can be distinguished from the stronger main frequency. Is this > correct? If it is not, how often do you encounter these cases in real > life? If it's < 5% of time, it's OK for me to just disregard them.
For the low third or so of a piano keyboard, the "stronger main frequency" is different from the note of the piano key more often than 5% of the time, at least with my cheap piano and when using a built-in laptop mic. Of course, YMMV. -- http://www.nicholson.com/rhn/dsp.html
Reply by August 31, 20072007-08-31
@VLV
> If you want a solution that works good...
< How do you define "good"?
> No, you don't:
"but I wouldn't like to spend more then a day or two learning the maths and so" Judjung on your extremely naive questions, you will have to spend another year or two. < How do you know what I mean by "something"? Maybe "something" is much different then your presumption that I want to learn something from your field of specialization. Obviously, you are wrong. Not everything I learn must be related to deep math. If I could, I would like to compare this to the very same computers we use to write these posts. Many people have absolutely no idea how 99% of them work, what they contain, how they are built, etc. However, almost everybody can run programs. My questions are in this range. I don't know 99% of DSP-related stuff. I can learn some little piece to solve my problem, but that doesn't have to include solving differential equations. I want to learn how to use, not how to build. I want to learn why this is better then the other one. I want to learn how much time I need to implement something. To answer all questions I posted, somebody skillful might need no more then 30 minutes. That is what I needed. Some people gave some good things to search for and quickly analyze. Anyway, don't take this personally, but I think your attitude of "You are stupid, I know everything and can sell you the right solution" is a little off. Thanks for the offer, I will choose not to have you help me. @Mark
>Actually many car horns are 2 tones...
< Didn't know that... Well, disregard this in that case - or record only one-tone horns :) Or bikes? @Ron N.
>The OP did not say that a professional or academic research
grade (or homework grade :) solution was required. He hasn't defined his measure of "goodness" yet, and it might be surprisingly different from your more professionally oriented definition. < Correct. In fact, I think it's obvious that I want almost completely the opposite - a simple solution with just the quality I need...
>I seem to remember visiting a science museum as a grade
school child. They had a oscilloscope hooked up to an audio frequency generator (or two?). One could eyeball relative frequencies by holding a tape-measure up to the display. < :)))
>Alas, you picked some sounds that are not at all
simple, nor single frequency, even though you might think they are. The notes a piano makes can be far more spectrally complicated, than, say, a tuning fork or flute. Same with may car horns and buzzers. Might want to start out by looking at these sound waveforms on a 'scope, or spectrum analyzer. < Yes. To correct myself - by "single frequency" I meant "single strong frequency". Maybe I am still wrong, but I think most of these have a very strong frequency which I called "main frequency" in my previous posts, while the other frequencies are much weaker. Although I know they cannot be left aside, the other frequencies have the strength that can be distinguished from the stronger main frequency. Is this correct? If it is not, how often do you encounter these cases in real life? If it's < 5% of time, it's OK for me to just disregard them. All of you guys, thanks a lot for a discussion. At the end, I found one relatively simple FFT-based way to do it. Although I didn't implement the solution, I think this will work fine. Here is the link to the explanation: http://local.wasp.uwa.edu.au/~pbourke/other/dft/. This is a good, layman's explanation I needed. I might need something more, but this is a good start.
Reply by Ron N. August 30, 20072007-08-30
On Aug 30, 5:48 am, wi...@yahoo.com wrote:
> @VLV > Are you trying to sell something? I am trying to learn something. > > @all others > Thanks to all of you. I will take a look at these, hopefully I will > find something that is not so hard to implement. I don't really > require it to work very precisely (it's not a neurosurgery type of > thing). Consider, for example, recording some audio which contains > very simple single frequency sounds (besides all the noise) - like > playing, one at a time, notes on a piano or recording car honking (one > car) or baby alarm buzzers or such.
Alas, you picked some sounds that are not at all simple, nor single frequency, even though you might think they are. The notes a piano makes can be far more spectrally complicated, than, say, a tuning fork or flute. Same with may car horns and buzzers. Might want to start out by looking at these sound waveforms on a 'scope, or spectrum analyzer. IMHO. YMMV. -- rhn A.T nicholson d.0.t C-o-M
Reply by robert bristow-johnson August 30, 20072007-08-30
On Aug 30, 3:21 am, Rob <robert.bie...@xponaut.se> wrote:
> On Aug 30, 3:29 am, wi...@yahoo.com wrote: > > > @r b-j > > > but if the OP wants to know the fundamental frequency of a reasonably > > > harmonic musical note, the thing he/she wants is called a "pitch > > > detector". > > > > This seems interesting. Do you have any pointers where I can learn > > this from (i.e. something you consider a good thing for a start)? > > Check for: Autocorrelation, AMDF (average mean difference function),
i think it's "magnitude" instead of "mean".
> Peak picking in the FFT is good.
unless there is no energy at the fundamental (but there is for other odd harmonics).
> Wavelets should work to (but I > have no idea how because I consider them too abstract, but that's just > me) > > All of these alas do require some checking of the math, but more > importantly (several years ago when I asked > the group almost the same question, and r b-j said I asked the right > questions :)
all of life's anwers are questions. r b-j
Reply by Ron N. August 30, 20072007-08-30
On Aug 30, 6:09 am, "Vladimir Vassilevsky"
<antispam_bo...@hotmail.com> wrote:
> <wi...@yahoo.com> wrote in message > > news:1188478089.466491.118320@r34g2000hsd.googlegroups.com... > > > @VLV > > Are you trying to sell something? > > If you want a solution that works good...
The OP did not say that a professional or academic research grade (or homework grade :) solution was required. He hasn't defined his measure of "goodness" yet, and it might be surprisingly different from your more professionally oriented definition.
> > I am trying to learn something. > > No, you don't: > > "but I wouldn't like to spend more then a day or two learning > the maths and so" > > Judjung on your extremely naive questions, you will have to > spend another year or two.
I seem to remember visiting a science museum as a grade school child. They had a oscilloscope hooked up to an audio frequency generator (or two?). One could eyeball relative frequencies by holding a tape-measure up to the display. IMHO. YMMV. -- rhn A.T nicholson d.0.t C-o-M
Reply by robert bristow-johnson August 30, 20072007-08-30
On Aug 29, 10:32 pm, "Vladimir Vassilevsky"
<antispam_bo...@hotmail.com> wrote:
> "robert bristow-johnson" <r...@audioimagination.com> wrote in message > > news:1188434404.548513.153610@r34g2000hsd.googlegroups.com... > > > On Aug 29, 8:24 pm, glen herrmannsfeldt <g...@ugcs.caltech.edu> wrote: > > > wi...@yahoo.com wrote: > > but if the OP wants to know the fundamental frequency of a reasonably > > harmonic musical note, the thing he/she wants is called a "pitch > > detector". > > Pitch detector! Magic word! You said it! > Topes! Topezz! Where is Topezzz?
you mean D'mitry? i think it's Terez.
Reply by Mark August 30, 20072007-08-30
 Consider, for example, recording some audio which contains
> very simple single frequency sounds (besides all the noise) - like > playing, one at a time, notes on a piano or recording car honking (one > car) ....
Actually many car horns are 2 tones... Mark
Reply by Vladimir Vassilevsky August 30, 20072007-08-30
<wimxa@yahoo.com> wrote in message
news:1188478089.466491.118320@r34g2000hsd.googlegroups.com...
> @VLV > Are you trying to sell something?
If you want a solution that works good...
> I am trying to learn something.
No, you don't: "but I wouldn't like to spend more then a day or two learning the maths and so" Judjung on your extremely naive questions, you will have to spend another year or two.
> thing). Consider, for example, recording some audio which contains > very simple single frequency sounds (besides all the noise) - like > playing, one at a time, notes on a piano or recording car honking (one > car) or baby alarm buzzers or such. I just need to determine their > frequencies - quite simple requirements.
What is the purpose of that?
> I am not at all into DSP yet > (I don't even know if I will ever be), that's why all these options > seem all good and all bad at the same time - I just don't understand > why some is better then the others, takes some experience for that.
It depends. Better for what? VLV