DSPRelated.com
Forums

Java Audio question - PLEASE HELP

Started by cppt...@yahoo.com April 13, 2008
On Apr 22, 11:33 pm, "Ron N." <rhnlo...@yahoo.com> wrote:
> You also never answered whether you tried plotting your > data after the type conversion to make sure you didn't > clip or wrap it.
I did plot the data, after the type conversion. I find the following (typical data sample length 2048 doubles): 1. a few spikes at the start - most probably due to a large DC offset being introduced somewhere. 2. a large sequence of zeros - about 250 - 300 samples long 3. the sinusoidal curve that one would expect - a little bit noisy, but still okay.
On Apr 23, 4:18 am, "John E. Hadstate" <jh113...@hotmail.com> wrote:

> Even (especially) after reading your later post, I don't > understand what you are saying. From your later post, it seems > that 7 Hz is your bin resolution, so the first bin corresponds > to 7 Hz, the 2nd to 14 Hz, etc. Are you saying that you don't > see a spike near bin 71 (500/7)? Perhaps the amplitude of your > injected tone is too low compared to the amplitude of your > other signal (so the spike is there, it's just lost in the > noise). What exactly is the problem?
The problem is, as I mentioned in a posting just before, that when I plot the data, I see a long sequence of zeros, about 250 - 300 sample points long, before I see the sinusoidal signal. There are a few sharp and large spikes at the start, which might be due to DC offset, but I do not understand the sequence of zeros. The total sample size of the collected data is 2048.
On Apr 22, 11:04 pm, Lew <l...@lewscanon.com> wrote:

> > fs = sample rate in Hz > > dT = 1/fs = interval between samples > > N = number of samples taken > > T = N x dT = total time period > > > f1 = 1/T = frequency of the first harmonic in Hz > > So if you accumulated twice as many samples, over twice as long, your > fundamental frequency would be halved? That is not sensible. > > -- > Lew
That is precisely the case. Please check the definitions above. Please note that f1 is the first harmonic if I were to calculate an FFT with the collected samples. The fundamental frequency is 500.0 Hz, and stays that way.
cpptutor2000@yahoo.com wrote:
> With reference to all the postings I am sorry I have caused confusion > about what I meant by the 'fundamental frequency' etc., May I give a > simple example? > > For a given signal being sampled for analysis, the number of points > obtained and the time between samples combine to determine the total > length of time taken to examine the signal. The following definitions > apply: > fs = sample rate in Hz > dT = 1/fs = interval between samples > N = number of samples taken > T = N x dT = total time period > > f1 = 1/T = frequency of the first harmonic in Hz > Keeping these points in mind, I have found that f1 in my case is > around 7 Hz. I am NOT measuring 7 Hz. If I were to take an FFT of the > collected data, then I can expect to get peaks that are harmonics of 7 > Hz. That is if I were to detect if the 500.0 Hz signal of the tone > generator was being picked up, I would have look for the 500/7 > harmonic of 7 Hz. I hope I have made myself clear about what I am > trying to do.
Pete, It would help if you used the same terms that the rest of us do. In particular, it is important to avoid using standard words in non-standard ways without the sort of glossary you provided here. *Fundamental* applies not to an FFT, but to the longest-period component of a periodic waveform. What *you* have called the fundamental is often referred to as bin width or resolution. If your signal repeats every 2 ms, then its fundamental is 500 Hz. It may have harmonics at 1000, 1500, 2000Hz, etc. Jerry -- Engineering is the art of making what you want from things you can get. &#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;
On Apr 23, 6:06 am, "cpptutor2...@yahoo.com" <cpptutor2...@yahoo.com>
wrote:
> On Apr 23, 4:18 am, "John E. Hadstate" <jh113...@hotmail.com> wrote: > > > Even (especially) after reading your later post, I don't > > understand what you are saying. From your later post, it seems > > that 7 Hz is your bin resolution, so the first bin corresponds > > to 7 Hz, the 2nd to 14 Hz, etc. Are you saying that you don't > > see a spike near bin 71 (500/7)? Perhaps the amplitude of your > > injected tone is too low compared to the amplitude of your > > other signal (so the spike is there, it's just lost in the > > noise). What exactly is the problem? > > The problem is, as I mentioned in a posting just before, that when I > plot the data, I see a long sequence of zeros, about 250 - 300 sample > points long, before I see the sinusoidal signal. There are a few sharp > and large spikes at the start, which might be due to DC offset, but I > do not understand the sequence of zeros. The total sample size of the > collected data is 2048.
It could be a data header. Or it could be how long it takes your mic or ADC to initialize. Why not just ignore this header or turn-on transient? Does your sinusoid have roughly balanced positive and negative values? Or do you have a DC offset of your sinusoid?
cpptutor2000@yahoo.com wrote:
> On Apr 23, 4:18 am, "John E. Hadstate" <jh113...@hotmail.com> wrote: > >> Even (especially) after reading your later post, I don't >> understand what you are saying. From your later post, it seems >> that 7 Hz is your bin resolution, so the first bin corresponds >> to 7 Hz, the 2nd to 14 Hz, etc. Are you saying that you don't >> see a spike near bin 71 (500/7)? Perhaps the amplitude of your >> injected tone is too low compared to the amplitude of your >> other signal (so the spike is there, it's just lost in the >> noise). What exactly is the problem? > > The problem is, as I mentioned in a posting just before, that when I > plot the data, I see a long sequence of zeros, about 250 - 300 sample > points long, before I see the sinusoidal signal. There are a few sharp > and large spikes at the start, which might be due to DC offset, but I > do not understand the sequence of zeros. The total sample size of the > collected data is 2048.
Look to the acquisition software. It's unlikely that there's a startup-transient that large in the hardware, but there may be an offser between the pointers that write the data and retrieve it. Jerry -- Engineering is the art of making what you want from things you can get. &#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;
Jerry Avins wrote:
cpptutor2000@yahoo.com wrote:
> On Apr 23, 4:18 am, "John E. Hadstate" <jh113...@hotmail.com> wrote: > >> Even (especially) after reading your later post, I don't >> understand what you are saying. From your later post, it seems >> that 7 Hz is your bin resolution, so the first bin corresponds >> to 7 Hz, the 2nd to 14 Hz, etc. Are you saying that you don't >> see a spike near bin 71 (500/7)? Perhaps the amplitude of your >> injected tone is too low compared to the amplitude of your >> other signal (so the spike is there, it's just lost in the >> noise). What exactly is the problem? > > The problem is, as I mentioned in a posting just before, that when I > plot the data, I see a long sequence of zeros, about 250 - 300 sample > points long, before I see the sinusoidal signal. There are a few sharp > and large spikes at the start, which might be due to DC offset, but I > do not understand the sequence of zeros. The total sample size of the > collected data is 2048.
Look to the acquisition software. It's unlikely that there's a startup transient that large in the hardware, but there may be an offset between the pointers that write and retrieve the data. Jerry -- Engineering is the art of making what you want from things you can get. &#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;
<cpptutor2000@yahoo.com> wrote in message 
news:a1d43b38-854e-470e-adbf-e514cf982960@a70g2000hsh.googlegroups.com...
> On Apr 23, 4:18 am, "John E. Hadstate" <jh113...@hotmail.com> > wrote: > >> Even (especially) after reading your later post, I don't >> understand what you are saying. From your later post, it >> seems >> that 7 Hz is your bin resolution, so the first bin >> corresponds >> to 7 Hz, the 2nd to 14 Hz, etc. Are you saying that you >> don't >> see a spike near bin 71 (500/7)? Perhaps the amplitude of >> your >> injected tone is too low compared to the amplitude of your >> other signal (so the spike is there, it's just lost in the >> noise). What exactly is the problem? > > The problem is, as I mentioned in a posting just before, that > when I > plot the data, I see a long sequence of zeros, about 250 - > 300 sample > points long, before I see the sinusoidal signal. There are a > few sharp > and large spikes at the start, which might be due to DC > offset, but I > do not understand the sequence of zeros. The total sample > size of the > collected data is 2048. >
I'll second Ron's motion and add that some file formats that I'm familiar with reserve the first 512-byte block (or more) for "metadata"; that is, special labels that identify things about the data like the sample rate, the number of bits per sample, the endian-ness, whether stereo or mono, the number of channels, etc. Since these things don't often consume all the allocated space, the remaining bytes ("reserved for future expansion" is a favorite phrase here) are often set to zero. As long as identifiable data starts at a constant offset from the beginning of the file and assuming that you don't need the metadata, my advice would be to read it and discard it.
cpptutor2000@yahoo.com wrote:
> On Apr 22, 11:04 pm, Lew <l...@lewscanon.com> wrote: > >>> fs = sample rate in Hz >>> dT = 1/fs = interval between samples >>> N = number of samples taken >>> T = N x dT = total time period >>> f1 = 1/T = frequency of the first harmonic in Hz >> So if you accumulated twice as many samples, over twice as long, your >> fundamental frequency would be halved? That is not sensible. >> >> -- >> Lew > That is precisely the case. Please check the definitions above. Please > note that f1 is the first harmonic if I were to calculate an FFT with > the collected samples. The fundamental frequency is 500.0 Hz, and > stays that way.
No, that doesn't make sense. If I recorded a pure 1000 Hz sine wave, that is the frequency whether I take 44000 samples for one second or 88000 samples over two seconds. The frequency isn't affected by how long I record it. -- Lew
Jerry Avins wrote:
> cpptutor2000@yahoo.com wrote: >> With reference to all the postings I am sorry I have caused confusion >> about what I meant by the 'fundamental frequency' etc., May I give a >> simple example? >> >> For a given signal being sampled for analysis, the number of points >> obtained and the time between samples combine to determine the total >> length of time taken to examine the signal. The following definitions >> apply: >> fs = sample rate in Hz >> dT = 1/fs = interval between samples >> N = number of samples taken >> T = N x dT = total time period >> >> f1 = 1/T = frequency of the first harmonic in Hz >> Keeping these points in mind, I have found that f1 in my case is >> around 7 Hz. I am NOT measuring 7 Hz. If I were to take an FFT of the >> collected data, then I can expect to get peaks that are harmonics of 7 >> Hz. That is if I were to detect if the 500.0 Hz signal of the tone >> generator was being picked up, I would have look for the 500/7 >> harmonic of 7 Hz. I hope I have made myself clear about what I am >> trying to do. > > Pete, > > It would help if you used the same terms that the rest of us do. In > particular, it is important to avoid using standard words in > non-standard ways without the sort of glossary you provided here. > > *Fundamental* applies not to an FFT, but to the longest-period component > of a periodic waveform. What *you* have called the fundamental is often > referred to as bin width or resolution. > > If your signal repeats every 2 ms, then its fundamental is 500 Hz. It > may have harmonics at 1000, 1500, 2000Hz, etc.
No wonder I was confused. It was a case of, "There's glory for you!" (Carroll, Lewis, /Through the Looking-Glass/, Chapter VI, "Humpty Dumpty", <http://www.gutenberg.org/etext/12>). -- Lew