DSPRelated.com
Forums

Question about DSP in Matlab (beginner)

Started by JCO_DSP May 23, 2015
PS: The following sentence I wrote is of course incorrect:
>It uses a gaussian window in >the time domain, so in the frequency domain the lobe width is much
reduced
>than in your case
I meant that their frequency response is much more focused / narrow. Of course the lobe is a little wider. --------------------------------------- Posted through http://www.DSPRelated.com
Cedron <103185@DSPRelated> wrote:

>[...snip...]
>>The FT of the window fully describes the peak and the sidelobes. The >>sidelobes are what are called "leakage".
>No it doesn't. Just to be clear, you are talking about the sinc = sin( pi >x ) / ( pi x ) function, right?
>"Sidelobes" are a better word than "leakage", but I still don't really >like it because it is from the continuous, not the discrete, definition of >the FT. All the "lobey- ness" is lost in the translation.
You're both right. "FT of the window" could be: (1) FT of a continuous-time function which is a rectangle, or (2) FT of the above rectangle multiplied by an impulse train, i.e. N impulses where N is the number of points in the discrete transform. When N is large, case (2) approaches case (1). Steve
Hi Julien,

Thanks for this well considered reply.

>Dear Cedron, > >If I understand well you blog post "Exact Frequency Formula for a Pure >Real Tone in a DFT", you are dealing with the overdetermined problem of >estimating the frequency from a real sinuosidal tone: 3 unknows >(frequency, phase and amplitude), and n knowns (for n signal samples). >
That's how I see it, too. Except at the DC and Nyquist bins, where there are really only three values, but still enough.
>First, I think it not quite right to speak about an **exact solution**
for
>such a problem (except of course if you have only 3 samples at hand, or
no
>noise at all).
It is only exact in the no noise case, otherwise it is a good estimator.
> >Second, considering the, umm, naivety, of your method (using only 3 bins >of a non-windowed DFT), and your claim, I quote, "this article should be >considered a watershed event in the discipline" (or maybe this is >self-derision?), I wonder if, before posting your blog notes, you have >ever tried to get ackwoledged of the classical methods used to solve
this
>problem? >
You like the "non-windowed" interpretation as well. Others prefer to say it's a rectangular window. Trying to narrow the leakage spread around the tone of interest will not help to calculate the frequency any better with a formula like mine. If the purpose of applying the window is to try to reduce the impact of nearby tones, my formula does that implicitly. I try to explain that in the "Implicit Windowing" section. Suppose Z is a DFT vector with no window applied and Y is a DFT window with a Von Hann window applied. Then Y(k) = Z(k) - [ Z(k-1) + Z(k+1) ] /2 (I may be off by a factor of two) That this is true is one of the coolest things I learned about the DFT early on. Subtracting the average of the neighbors from a DFT bin greatly improves a FFT display on the computer screen by widening sharp peaks and narrowing broad ones. This can also be rewritten as: Y(k) = ( -1, 2, -1 )( Z(k-1) Z(k) Z(k+1) ) / 2 You can rewrite equation (18) as cos( alpha ) = WBZ / WZ As the number of samples gets large, W approaches ( -1, 2, -1 ) and B approaches cos( beta_n ) times the identity matrix. Since W is in the numerator and the denominator, it can be rescaled arbitrarily. The "watershed" statement is a bit of bluster in order to elicit a "No, it's not" claim from someone who would know. I have searched extensively and not found this equation anywhere in the literature. As you can tell from my exchanges from Eric Jacobsen, I have not been able to find an expert that can point one out either. His pages are the best I've found so far that cover the classical approaches using the DFT. If it is a single tone, there are many time domain approaches, too. None of his estimators are exact in the noiseless case, so to have an equation that is would seem to me to be a big improvement. More so, since my formula is derived directly from the fundamental definitions, on theoretical grounds it is a lot cleaner. He has referred me to an author that has written extensively on the subject. I have read some of it. Candan, the author, is still using approximations. Whether those approaches are superior in the presence of noise, I cannot tell you. I plan to write a blog article about effectively eliminating the impact of other tones, and a different one on a noise mitigation technique I developed.
>For example, did you have a look to the classical gaussian window + >quadratic interpolation method >(https://ccrma.stanford.edu/~jos/sasp/Quadratic_Interpolation_Spectral_Peaks.html)?
Thanks for the link. The guassian window has infinitely long tails, so I think when you truncate it with a finite length sampling window a little bit of inaccuracy is introduced to the parabolic relationship. Don't hold me to that. I also believe that the guassian window will actually increase the impact of distantly space tones.
>I have not done any test myself, but just be intuition we can guess that >this method is much more accurate than yours: It uses a gaussian window
in
>the time domain, so in the frequency domain the lobe width is much
reduced
>than in your case, and then it does a quadratic interpolation with 3 >points in the dB scale, which is also an exact solution (because DFT of >gaussian is also a gaussian, and then after log, it becomes just a >quadratic), and in the end there is much more signal energy in their 3
DFT
>bins (thanks to their windowing) than in your 3, unwindowed, DFT bins. >Anyway, look at the link, it's better explained. >
In the linear algebra form of the frequency equation: cos( alpha ) = WBZ / WZ The size of the vectors can be extended to cover any number of bins. So far, I have not found this to be advantageous. In the noiseless case, there is no need. In noisy cases, empirically tested, there isn't any improvement. The highest SNRs are going to be found in the bins near the peak.
>Regards, > >Julien > >PS: I am not a specialist in this domain, there seems to be a lot of
other
>methods to do that, and maybe there even better methods, or different >methods for different applications, I just cited you an example. > >--------------------------------------- >Posted through http://www.DSPRelated.com
As far as the realm of DSP goes, the DFT is my specialty area, although I would not call myself an expert or a specialist in the field. I got into this from my hobby of taping local bands and the recording program I wrote for that purpose. I made some discoveries in the process. I could not find them in the literature, so I decided to write them up in blog format. Since they concern the fundamentals, and the fundamentals are already "well understood", nobody seems to think an improvement can be made on them. I think having exact equations for bin values of non-integer tones (leakage), an exact frequency formula, and a method for getting the exact amplitude and phase for non-integer frequency tones is an improvement. There may not be any improvement in actual implementation, but from an academic/theoretical point of view I think the improvement is significant. Ced --------------------------------------- Posted through http://www.DSPRelated.com
>PS: The following sentence I wrote is of course incorrect: >>It uses a gaussian window in >>the time domain, so in the frequency domain the lobe width is much >reduced >>than in your case > >I meant that their frequency response is much more focused / narrow. Of >course the lobe is a little wider. > >--------------------------------------- >Posted through http://www.DSPRelated.com
You just confirmed this: "I also believe that the guassian window will actually increase the impact of distantly space tones." from my other reply. From your referenced link, in the "interpolated peak location" equation (6.30), I wondered if you noticed that the (-1,2,-1) coefficients turn up in the denominator (rescaled by -1)? And the coefficients ( -1, 0, 1 ) turn up in the numerator (again rescaled by -1)? Now here is Jacobsen's estimator: delta = Re[( X(k-1)-X(k+1))/((2*X(k))-X(k-1)-X(k+1))] from http://www.ericjacobsen.org/fe2/fe2.htm Now look at my equation: cos( alpha ) = WBZ / WZ Where B is the diagonal matrix of cosine values for k-1, k, and k+1. If you subtract out a cos( beta_n ) multiple of the identity matrix you get: cos( alpha ) = cos( beta_n ) + W(B-cos(beta_n)I)Z / WZ Can you see that the numerator's diagonal matrix will now be ( -something, 0, something )? You can work it out formally to show that Jacobsen's estimator is an approximation of my equation. Ced --------------------------------------- Posted through http://www.DSPRelated.com
On Wed, 27 May 2015 21:15:49 +0000 (UTC), spope33@speedymail.org
(Steve Pope) wrote:

>Cedron <103185@DSPRelated> wrote: > >>[...snip...] > >>>The FT of the window fully describes the peak and the sidelobes. The >>>sidelobes are what are called "leakage". > >>No it doesn't. Just to be clear, you are talking about the sinc = sin( pi >>x ) / ( pi x ) function, right? > >>"Sidelobes" are a better word than "leakage", but I still don't really >>like it because it is from the continuous, not the discrete, definition of >>the FT. All the "lobey- ness" is lost in the translation. > >You're both right. > >"FT of the window" could be: > >(1) FT of a continuous-time function which is a rectangle, or
Actually any window function. The FT of a Hamming window gives the response, etc. I suspect this proposed method is only for rectangular.
>(2) FT of the above rectangle multiplied by an impulse train, i.e. >N impulses where N is the number of points in the discrete transform. > >When N is large, case (2) approaches case (1).
Yup.
> >Steve
Eric Jacobsen Anchor Hill Communications http://www.anchorhill.com
On Wed, 27 May 2015 12:34:43 -0500, "kaz" <37480@DSPRelated> wrote:

  [Snipped by Lyons]
> >I hope "Cedron" is not that nice guy "Vlad" back from the dead. > >Kaz
Hi Kaz, Nope. Cedron is not Vladimir. Cedron's real name is known to some of the people here on comp.dsp. But those people have been "considerate" of Cedron's feelings and have not revealed his secret. [-Rick-]
On Sun, 24 May 2015 02:49:41 -0500, "kaz" <37480@DSPRelated> wrote:

>> >>Kaz, I do believe you have misunderstood my point. Just to be clear, we >>are talking about a fixed time interval, and increasing the sample >>density. >> > >Ced >I never heard of this terminology, I still think you mean DFT (of a time >sequence of samples), no problem. > >>As long as the frequencies are below the Nyquist limit, you do not get >>any better frequency resolution, meaning being able to discern (resolve) >two >>different tones, by increasing the number of samples. >> > >On this one, I have been scratching me head since last night. >Doesn't everybody say fft frequency resolution = Fs/N (= bin width)??? Or >is your concept of resolution something else? > >That is what I meant by accuracy, may be not best wording but should be ok >for a practical DSP beginner. > >Kaz
Hi Kaz, Years ago I used to refer to the value Fs/N as the DFT's "resolution". But over the years I realized that the word resolution means different things to different people. So now I merely refer to the value Fs/N as the DFT's "bin spacing". The word resolution is sometimes used in the wrong way. For example, I have read the words: "Increasing the value of N in an N-point DFT provides greater frequency resolution." By "greater" they meant Fs/N is smaller! Ha ha. What they should have written is: "Increasing the value of N in an N-point DFT provides improved frequency resolution." Better yet, they should have written: "Increasing the value of N in an N-point DFT provides smaller DFT bin spacing." [-Rick-]
Rick Lyons <R.Lyons@_bogus_ieee.org> wrote:

(snip)

> Years ago I used to refer to the value > Fs/N as the DFT's "resolution". But over the > years I realized that the word resolution means > different things to different people. So now > I merely refer to the value Fs/N as the DFT's > "bin spacing".
> The word resolution is sometimes used in the wrong > way. For example, I have read the words:
> "Increasing the value of N in an N-point DFT > provides greater frequency resolution."
> By "greater" they meant Fs/N is smaller! Ha ha.
One that bothers me, is the use of the inverse along with the word resolution. Resolution should be a frequency, or spatial frequency in the case of visual resolution, not a time or distance. That is, something where higher is better. Even more, camera shutter speeds are most often given in terms of time, but a speed should have time in the denominator. Shutter speeds dials most often do it right, but it seems to be hard for people to say. That is, 60/second not 1/60 of a second. -- glen
On Sat, 23 May 2015 12:10:22 -0500, JCO_DSP wrote:

> Hi, > > I'm starting to learn DSP (Matlab )and I have two questions about it, > maybe someone can help me out? > > I'm trying to measure a frequency from an Audio Device and I'm using FFT > to transform it from the time domain to the frequency domain. But I am > doing a downsample before the FFT. But you can also do it after the FFT. > Do you know what would be the most efficient (before or after)? And why? > > Another question, I am using zero padding to increase my system > resolution (up to 50Hz). My frame length is N=256 and sample frequency > fs= 44100 Hz. So 44100/50 = 882, so I need to add 626 zeroes (to 256 > frame length) to get 50 Hz resolution, I hope this is correct? I believe > this is done for FFT. But is this the same for the DFT?
If you're still with us -- did you get your question answered? -- www.wescottdesign.com
>Hi Kaz, > Years ago I used to refer to the value >Fs/N as the DFT's "resolution". But over the >years I realized that the word resolution means >different things to different people. So now >I merely refer to the value Fs/N as the DFT's >"bin spacing". > >The word resolution is sometimes used in the wrong >way. For example, I have read the words: > > "Increasing the value of N in an N-point DFT > provides greater frequency resolution." > >By "greater" they meant Fs/N is smaller! Ha ha. > >What they should have written is: > > "Increasing the value of N in an N-point DFT > provides improved frequency resolution." > >Better yet, they should have written: > > "Increasing the value of N in an N-point DFT > provides smaller DFT bin spacing." > >[-Rick-]
Hi Rick, Thanks for the post but I don't seem to grasp the difference between bin resolution and frequency resolution(when detected by FFT). It reminds me of Welsh sheep joke: A physicist, a mathematician, a DSP engineer, a statistician and a software engineer were on a mental rehab vacation to Wales(UK). They spotted a black sheep, then The DSP engineer looked out of the window and said "Look! Welsh sheep are black!" The physicist said, "No, no. Some Welsh sheep are black." The mathematician looked irritated. "There is at least one field, containing at least one sheep, of which at least one side is black." The statistician said : "It's not significant. We only know there's one black sheep" The software guy said: "Oh, no! A special case!" Kaz --------------------------------------- Posted through http://www.DSPRelated.com