Suppose I have a function that takes frequency (0 Hz < f < 22kHz), amplitude (0 to 1 inclusive), phase (any radian), sampling rate (Samps/ Sec) and Length (how many samples to generate). Suppose also that the function uses the fundamental function cosine to generate this "pure" wave. Suppose the discrete-time samples generated are of the double type (8 bytes, typical IEEE) and thus all 0<=y<=1. If the frequency is low enough (say 1Hz) and sampling rate high enough (say 44.1kHz) and enough samples are generated (say 99999 samples) then one could apply the inverse cosine function (typically acos) and see a triangle-wave pattern output where the maximum would be 3.14159... and the period of the triangle-wave would match that of the generated cosine wave. Now suppose we increase the frequency of the generated cosine wave (try >= 800 Hz with above example). If you apply the acos function, you still see a triangle-wave but the peaks are not all the same values. None of the peaks "reach" 3.14159... and a wave pattern can be seen in the peaks. The discrete-time generated cosine wave is skipping the samples that would cause the acos function to generate the maximum peak. Ok, finally my question (thanks for the patience)! I'd like to estimate the frequency, amplitude and phase only from the generated samples of an arbitrary "pure" wave (say 1024 consecutive samples). Given the outlined issues with directly applying acos, what would the best way to do this? I'm very concerned about speed. In my application, I'm given these "pure" generated waves as a result from another transform. All the "pure" waves I'm given are actually all the same frequency (and yes, the amplitudes are still doubles) but I'd still like to know a generalized solution. Typically, FFT or the like is utilized on discrete samples but this seems somewhat overkill. Not to mention working out the exact parameters from the FFT result, taper-windows, etc. Any ideas? It seems like there is a simple solution I'm missing and I'll probably find it but was wondering if anyone might have a good idea of the top of their head? It actually seems like it would be a rudimentary problem, although abit atypical. Thank you very much...
Determining Parameters of "Purely Generated" Discrete Sine Wave?
Started by ●July 17, 2009
Reply by ●July 17, 20092009-07-17
On 17 Jul, 09:17, Parlous <parlous2...@gmail.com> wrote:> Typically, FFT or the like is utilized on discrete samples but this > seems somewhat overkill. Not to mention working out the exact > parameters from the FFT result, taper-windows, etc.The simplest standard solution is: 1) Decide on a target accuracy of the frequency estimates 2) Zero-pad the data accordingly 3) FFT the sero-padded data 4) Correct for scaling coefficients No windows needed. The not-so-simple-but-still-standard solutions involve frequency estimators like MUSIC, ESPRIT etc. They can give more accurate results, but are both hard to implement and picky about the data. Rune
Reply by ●July 17, 20092009-07-17
Parlous <parlous2112@gmail.com> wrote:> Suppose I have a function that takes frequency (0 Hz < f < 22kHz), > amplitude (0 to 1 inclusive), phase (any radian), sampling rate (Samps/ > Sec) and Length (how many samples to generate). Suppose also that the > function uses the fundamental function cosine to generate this "pure" > wave. Suppose the discrete-time samples generated are of the double > type (8 bytes, typical IEEE) and thus all 0<=y<=1.(snip)> Ok, finally my question (thanks for the patience)! I'd like to > estimate the frequency, amplitude and phase only from the generated > samples of an arbitrary "pure" wave (say 1024 consecutive samples). > Given the outlined issues with directly applying acos, what would the > best way to do this?Nonlinear least squares fit to A sin(Bx + C).> I'm very concerned about speed.Do you want the right answer or not? OK, generate a systolic array in an FPGA. Probably not floating point, but fixed point values with the binary point on the left, you choose the length. OK, second thought. Interpolate around the zero crossings with an appropriate degree polynomial, then compute the appropriate parameters from the polynomial coefficients.> In my application, I'm given these "pure" generated waves as a result > from another transform. All the "pure" waves I'm given are actually > all the same frequency (and yes, the amplitudes are still doubles) but > I'd still like to know a generalized solution.> Typically, FFT or the like is utilized on discrete samples but this > seems somewhat overkill. Not to mention working out the exact > parameters from the FFT result, taper-windows, etc.FFT is not a good solution. FFT answers the question for a sum of many sin/cos functions with the appropriate periodicity. You don't seem to guarantee periodicity, and only have one sinusoidal function. -- glen
Reply by ●July 20, 20092009-07-20
On Jul 17, 5:38�am, glen herrmannsfeldt <g...@ugcs.caltech.edu> wrote:> Parlous <parlous2...@gmail.com> wrote: > > Suppose I have a function that takes frequency (0 Hz < f < 22kHz), > > amplitude (0 to 1 inclusive), phase (any radian), sampling rate (Samps/ > > Sec) and Length (how many samples to generate). Suppose also that the > > function uses the fundamental function cosine to generate this "pure" > > wave. Suppose the discrete-time samples generated are of the double > > type (8 bytes, typical IEEE) and thus all 0<=y<=1. > > (snip) > > > Ok, finally my question (thanks for the patience)! I'd like to > > estimate the frequency, amplitude and phase only from the generated > > samples of an arbitrary "pure" wave (say 1024 consecutive samples). > > Given the outlined issues with directly applying acos, what would the > > best way to do this? > > Nonlinear least squares fit to A sin(Bx + C).If the frequency f0 is known, use a LINEAR least squares fit to A*cos(w0*t) + B*sin(w0*t) Hope this helps. Greg
Reply by ●July 20, 20092009-07-20
On Jul 17, 2:28 am, Rune Allnor <all...@tele.ntnu.no> wrote:> On 17 Jul, 09:17, Parlous <parlous2...@gmail.com> wrote: > > > Typically, FFT or the like is utilized on discrete samples but this > > seems somewhat overkill. Not to mention working out the exact > > parameters from the FFT result, taper-windows, etc. > > The simplest standard solution is: > > 1) Decide on a target accuracy of the frequency estimates > 2) Zero-pad the data accordingly > 3) FFT the sero-padded data > 4) Correct for scaling coefficientsSomething is missing between 3) and 4). As Glen points out in his post "The FFT is not a good solution". Well the FFT alone isn't. I assume some form of peak picking of magnitude or power is intended here. Some kind of interpolation can be used about the peak to reduce the size of fft needed for a given accuracy.> > No windows needed.But zero extension applies a rectangular window to the data. The fact of deciding a number of samples to acquire, generate or use is a windowing process. This is misleading non-sense unless you mean to label the rectangular window as the :No Window". Then you would be correct that in your algorithm: The "No Window" is needed. Good accuracy can be achieved without zero extension to a large transform size by the careful use of an appropriate widow. Using the parabolic interpolation derived peak calculation on the log power spectrum of Gaussian windowed data gives a great improvement in accuracy without increase in transform size. the formulas to do this and a table of accuracy improvement examples are given in http://mgasior.web.cern.ch/mgasior/pap/biw2004_poster.pdf This is referred to as "Gaussian interpolation" in the reference. Many other windows can provide good accuracy, but it is necessary to use a peak calculation algorithm that is a proper match to the window used. Many treatments of fft interpolation algorithms fail to apply this principle or make this point. Dale B. Dalrymple
Reply by ●July 20, 20092009-07-20
On 20 Jul, 21:59, dbd <d...@ieee.org> wrote:> On Jul 17, 2:28 am, Rune Allnor <all...@tele.ntnu.no> wrote: > > > On 17 Jul, 09:17, Parlous <parlous2...@gmail.com> wrote: > > > > Typically, FFT or the like is utilized on discrete samples but this > > > seems somewhat overkill. Not to mention working out the exact > > > parameters from the FFT result, taper-windows, etc. > > > The simplest standard solution is: > > > 1) Decide on a target accuracy of the frequency estimates > > 2) Zero-pad the data accordingly > > 3) FFT the sero-padded data > > 4) Correct for scaling coefficients > > Something is missing between 3) and 4). As Glen points out in his post > "The FFT is not a good solution". Well the FFT alone isn't.The OP's post made me think this is a person who is taking the first steps into the world of DSP. Some of the phrases indicated to me that he might use terms he have seen somewhere, that he might not quite understand. While I might agree with Glen and you that the FFT might not be a very good tool and some care would be required of one decides to use it anyway, I think it might be premature to discuss such details with the OP. Sure, after he gets some experience a number of questions will need to be clarified. But all in good time. Rune
Reply by ●July 20, 20092009-07-20
On Jul 20, 1:09 pm, Rune Allnor <all...@tele.ntnu.no> wrote:> On 20 Jul, 21:59, dbd <d...@ieee.org> wrote: > ... > > > Tune: > > > 1) Decide on a target accuracy of the frequency estimates > > > 2) Zero-pad the data accordingly > > > 3) FFT the sero-padded data > > > 4) Correct for scaling coefficients >.> > Something is missing between 3) and 4). As Glen points out in his post .> > "The FFT is not a good solution". Well the FFT alone isn't. .> .> The OP's post made me think this is a person who is .> taking the first steps into the world of DSP. Some of .> the phrases indicated to me that he might use terms .> he have seen somewhere, that he might not quite understand. All the more reason to avoid sloppy usage that could be misunderstood.. .> .> While I might agree with Glen and you that the FFT might .> not be a very good tool and some care would be required .> of one decides to use it anyway, That's neither my point or my conclusion about the fft when used with appropriate interpolation algorithms. My point is that referring to the fft and accompanying postprocessing algorithms for interpolation as just "fft" is sloppy and misleading. If you are concerned about being confusing, at least get it right. .>I think it might be .> premature to discuss such details with the OP. .> ... It's never too early to make statements accurately. Even beginners can remember what you say and how you say it. Seeing sloppy substitution of "fft" for "fft and essential appropriate postprocessing algorithms" may be where Glen learned the habit. Until DSP users learn that there are postprocessing algorithms required for fft interpolation they cannot accurately consider whether to apply them. Dale B. Dalrymple
Reply by ●July 20, 20092009-07-20
On Jul 17, 3:17�am, Parlous <parlous2...@gmail.com> wrote:> Suppose I have a function that takes frequency (0 Hz < f < 22kHz), > amplitude (0 to 1 inclusive), phase (any radian), sampling rate (Samps/ > Sec) and Length (how many samples to generate). Suppose also that the > function uses the fundamental function cosine to generate this "pure" > wave. Suppose the discrete-time samples generated are of the double > type (8 bytes, typical IEEE) and thus all 0<=y<=1.Including amplitude 0 is going to give you some problems with meaningful values for phase and frequency.> > If the frequency is low enough (say 1Hz) and sampling rate high enough > (say 44.1kHz) and enough samples are generated (say 99999 samples) > then one could apply the inverse cosine function (typically acos) and > see a triangle-wave pattern output where the maximum would be > 3.14159... and the period of the triangle-wave would match that of the > generated cosine wave. > > Now suppose we increase the frequency of the generated cosine wave > (try >= 800 Hz with above example). If you apply the acos function, > you still see a triangle-wave but the peaks are not all the same > values. None of the peaks "reach" 3.14159... and a wave pattern can be > seen in the peaks. The discrete-time generated cosine wave is skipping > the samples that would cause the acos function to generate the maximum > peak.To the extent that you know the sample rate (which effects the other methods discussed here also) you could actually get an estimate of the frequency from every pair of successive samples in this triangle wave from a "pure" sine wave, and not really care if the triangle wave peaks have the same value or not.> > Ok, finally my question (thanks for the patience)! I'd like to > estimate the frequency, amplitude and phase only from the generated > samples of an arbitrary "pure" wave (say 1024 consecutive samples). > Given the outlined issues with directly applying acos, what would the > best way to do this? I'm very concerned about speed. > > In my application, I'm given these "pure" generated waves as a result > from another transform. All the "pure" waves I'm given are actually > all the same frequency (and yes, the amplitudes are still doubles) but > I'd still like to know a generalized solution. > > Typically, FFT or the like is utilized on discrete samples but this > seems somewhat overkill. Not to mention working out the exact > parameters from the FFT result, taper-windows, etc.With the numbers you are thowing around for frequency, sample rate and number of samples, it is not clear that you will have sufficient signal for an FFT approach.> > Any ideas? It seems like there is a simple solution I'm missing and > I'll probably find it but was wondering if anyone might have a good > idea of the top of their head? It actually seems like it would be a > rudimentary problem, although abit atypical. > > Thank you very much...Might want to try using frequency estimate from sample differences of the triangular wave discussed above, along with suggestion from Greg (Jul 20), then from Greg's A & B, compute the amplitude and phase. Dirk Bell DSP Consultant
Reply by ●July 21, 20092009-07-21
On 20 Jul, 23:35, dbd <d...@ieee.org> wrote:> .>I think it might be > .> premature to discuss such details with the OP. > .> ... > It's never too early to make statements accurately. Even beginners can > remember what you say and how you say it. Seeing sloppy substitution > of "fft" for "fft and essential appropriate postprocessing algorithms" > may be where Glen learned the habit. Until DSP users learn that there > are postprocessing �algorithms required for fft interpolation they > cannot accurately consider whether to apply them.What caused me to reply to the OP at all, was his statement "Typically, FFT or the like is utilized on discrete samples but this seems somewhat overkill." The main issue, as I saw it, was to break him out of this state of mind and consider the DFT as a way to solve the problem. Of course, I could have pulled a Vlad and pointed out to him in unequivocal terms that he lacks basic understanding of elementary tools and techniques etc, but I decided not to. On your advice I will give that particular option greater consideration next time. Thanks for your helpful guidance. Rune
Reply by ●July 21, 20092009-07-21
On Jul 21, 3:11 am, Rune Allnor <all...@tele.ntnu.no> wrote:> On 20 Jul, 23:35, dbd <d...@ieee.org> wrote: > > > .>I think it might be > > .> premature to discuss such details with the OP. > > .> ... > > It's never too early to make statements accurately. Even beginners can > > remember what you say and how you say it. Seeing sloppy substitution > > of "fft" for "fft and essential appropriate postprocessing algorithms" > > may be where Glen learned the habit. Until DSP users learn that there > > are postprocessing algorithms required for fft interpolation they > > cannot accurately consider whether to apply them. > > What caused me to reply to the OP at all, was his statement > > "Typically, FFT or the like is utilized on discrete samples > but this seems somewhat overkill." > > The main issue, as I saw it, was to break him out of this > state of mind and consider the DFT as a way to solve the > problem. > > Of course, I could have pulled a Vlad and pointed out to > him in unequivocal terms that he lacks basic understanding > of elementary tools and techniques etc, but I decided not to. > > On your advice I will give that particular option greater > consideration next time. > > Thanks for your helpful guidance. > > RuneI get your point in comparing your helpfulness to Vlad's. If you don't think it's worth doing right you don't see much point in doing it at all.Thanks for the clarification of your intent. Dale B. Dalrymple






