Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

- Community Forums
- :
- Forums
- :
- Hardware Development
- :
- AI Engine, DSP IP and Tools
- :
- Frequency estimation of a decaying sinusoidal wave...

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

thedestroyer

Observer

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

08-10-2011 09:25 AM

7,154 Views

Registered:
07-12-2011

Frequency estimation of a decaying sinusoidal wave with exponential background

Hello guys :),

I have a device that produces a signal every 20 ms like the one in the attached file. The data in the file is produced by a simulation of the experiment with pink (1/f) and white noise added to the signal. The frequency is 3.5 kHz, sampling rate is 10^6/s, number of points 20000 (or less after cropping the sides which has non-useful data). My task is to estimate the frequency of the signal, and in the future this has to be implemented in an FPGA (with VHDL). The signal can be written in the following form in General:

S(t) = (A - B Exp[-F t]) + a Exp[-b t] Sin[2 Pi w t + phi],

where A,B,F,a,b,w,phi are fitting parameters.

I could do very accurate fitting with this form get the frequencies very close to the real value (3.5 kHz), and the Allan standard deviation was very good for the signal.

I'm a physicist, that's why I'm not so familiar with signal processing :-)

----------

The problem:

The problem now is that I find fitting a very complicated process for an FPGA. I want to find a simpler way to do the fit.

Using list convolving with a constant kernal (whose length is equal to the a single period in the signal. Is there a better way?) I could subtract the background exponential to a very good level, so I'm left with a sinusoidal wave in an exponential decaying envelope and some pink and white noise with it.

I'm not sure what I could do to estimate the frequency of this wave. Applying Fourier transforms directly is not helping, because the period in which the signal was recorded is 20 ms, which means that the bandwidth resolution is approximately 50 Hz depending on the number of points I crop from the front and end of the signal. I could improve the result using Fourier transform to plus/minus 2 Hz of the real value by making the beginning and end of the signal in-phase by cropping some more points from the beginning and end of the signal.

I still need more accuracy!

For this I thought of many things. Could you guys tell me how good you see them as professionals, and how possible it's to apply them to an FPGA?

1- The signal can be resampled, in a way that makes the first and last point exactly match in phase, which will give a even higer accuracy in the peak produced by the Forier transform.

2- A linear fit can be done at every intersection to the y=0 axis, in a way that calculates the point that hits the axis and by counting the points in a period we can estimate the frequency.

Any other ideas are very highly appreciated :-)

Thanks a lot!

12 Replies

austin

Scholar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

08-10-2011 09:31 AM

7,152 Views

Registered:
02-27-2008

t.d.

What about remainung in the time-domain? One can find the time between zer-crossings to a better degree of accuracy, perhaps sampling at 400 MHz (+/- 2.5 ns).

A signature of zero-crossings could be recognized.

Austin Lesea

Principal Engineer

Xilinx San Jose

Principal Engineer

Xilinx San Jose

thedestroyer

Observer

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

08-10-2011 09:38 AM - edited 08-10-2011 09:43 AM

7,149 Views

Registered:
07-12-2011

Thank you for your answer! :-)

Sampling with a higher rate is, unfortunately, not possible for technical reasons that have to do with the measurement device we're using. The zero-crossing thing is my second proposal in the solutions I propesed (sorry for not using the right term). Using only 2 points to obtain the zero-crossing is not a good idea since there is noise. So I thought of using a linear fit to obtain the zero-crossings.

Is this practically possible? I think fitting a line is a very expensive process for an FPGA. Isn't it?

austin

Scholar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

08-10-2011 11:02 AM

7,142 Views

Registered:
02-27-2008

Hysteresis should be used on the input to reject noise for the zero-crossings.

You would have 20 ms of zero-crossings. If the nominal frequency is 3.5 KHz, that is about 70 cycles, or 140 zero-crossings. That is all you get. But you will know each zero-crossing +/- 10ns for a 100 MHz sample rate.

Austin Lesea

Principal Engineer

Xilinx San Jose

Principal Engineer

Xilinx San Jose

gszakacs

Professor

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

08-10-2011 12:27 PM

7,135 Views

Registered:
08-14-2007

It's not clear how much noise you have. The data you attached to your first post did not have

any clearly visible noise in it. This could affect how you need to proceed. Obviously enough

noise can add zero-crossings not related to the sinusoidal signal. It is not very expensive

in terms of FPGA resources to filter the data (low pass or band pass) before applying the

zero crossing measurement. This is mathematically similar to using more points to interpolate

the point of zero crossing. Filtering is commonly applied for things like video data before

doing data interpolation for up or downsampling.

-- Gabor

-- Gabor

thedestroyer

Observer

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

08-10-2011 11:42 PM

7,126 Views

Registered:
07-12-2011

Thank you for your answer.

It's not possible to sample in a higher rate because there are other processes involved and it's more complicated than it seems. The physics of the experiment doesn't allow that.

Could you please answer my question about whether it's possible to make a linear fit (regression) in an FPGA? I'm gonna make a simulation for linear fitting today to see how accurate it's to use a linear fit at every zero crossing to get the frequency.

And are there any other methods to estimate the frequency?

thedestroyer

Observer

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

08-10-2011 11:46 PM

7,125 Views

Registered:
07-12-2011

Thank you for your reply.

I provided a sample of the data in a text file with in the attachment with the picture. If you fit the data to the equation I provided, the residuals will represent the pink and white noise I added.

And why would I want to use filters? please explain!

gszakacs

Professor

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

08-11-2011 06:57 AM

7,114 Views

Registered:
08-14-2007

@thedestroyer wrote:

Thank you for your reply.

I provided a sample of the data in a text file with in the attachment with the picture. If you fit the data to the equation I provided, the residuals will represent the pink and white noise I added.

And why would I want to use filters? please explain!

In that case it looks like the pink and white noise are quite small compared to the signal. It wasn't

clear from looking at the waveform that there was any noise added. The real question then comes

down to whether you are trying to measure the frequency with more accuracy than cam be obtained

from the zero-crossings with the noise included. If not, then you don't really need filtering. If you

do, then a bandpass filter could remove a significant portion of the noise.

Another effect of filters is to remove "shot noise" or more simply put single samples that don't

fit the waveform. If you were to choose a linear interpolation approach to finding the zero-

crossings, then the filtered waveform would be a better choice. The filtered value of the

points just before and after the crossing would already be affected by the surrounding

points, making the zero-crossing computation similar to fitting a line to more data points.

What's not as clear to me is how you define a "zero crossing" when the center of the sinusoid

changes over time. Obviously the fitting approach takes this into account. For a more simplistic

time-domain approach you may need to continually monitor the wave peaks and compute the

"zero" level. Note that a bandpass filter would also remove some of the background offset.

-- Gabor

-- Gabor

thedestroyer

Observer

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

08-11-2011 08:25 AM

7,106 Views

Registered:
07-12-2011

Thank you again for your reply.

About the center of the sine changing, I convolved the signal with a constant kernal whose length is equal to the signal's average frequency (10^6/3500 = 286 samples).

Yes! I need an extremely high accuracy, I'm looking for an error +/- 10^-10 Hz!

I created today the script that does the linear fitting. The script removes background shift, and then detects the points that are different in sign, then creates a linear fit of the 2N points around them (on both sides). The result from this approach weren't very pleasing. The results are the following in a list for 100 decays (100 of the signals like the one I posted in my first post) :

{3500.07,3500.24,3500.02,3500.22,3500.17,3500.27,3500.08,3499.98,3499.89,3500.33,3500.3,3500.07,3500.13,3500.2,3500.09,3500.03,3500.24,3500.,3500.3,3500.19,3499.9,3500.09,3500.17,3500.27,3500.36,3499.87,3500.17,3500.22,3499.97,3499.95,3499.98,3500.06,3499.88,3500.34,3500.1,3500.03,3500.13,3500.14,3500.02,3500.03,3500

You're right, noise has to be removed to make this better, I noticed this when I found some contiguous points having negative and positive values. I'm a physicist and I'm not so familiar with filters, so I'm gonna start learning filters in some more details (I'm only familiar with simple filters like low-pass). But someone told me that using a low-pass filter or a high-pass filter or a band-pass filter may have an effect on the frequency on a phase dependent way, which will complicate things way out of my league! is this true?

could you please tell me how to start with this?

gszakacs

Professor

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

08-12-2011 06:38 AM

7,087 Views

Registered:
08-14-2007

Yes! I need an extremely high accuracy, I'm looking for an error +/- 10^-10 Hz!

Ouch! I don't think it very likely that you'll get that sort of accuracy with a simple

zero-crossing method. Your original curve-fitting approach essentially used

all of the input data points to generate the best fit. Your line fitting approach can

only use a small subset of the data where the trajectory is relatively linear.

You might still want to try using a fairly long digital bandpass filter in front of

the zero-crossing technique. As you mentioned, this does affect the phase

of the signal, but as I understand you're only interested in the frequency,

which would not be affected by the filter. There could be some secondary effects

of the amplitude modulation that affect the frequency measurement after

filtering, but theoretically you can compensate for this if the incoming

wave shape is constant. The important thing is to find a method with the

required precision. Then you can find the correction factors to get the required

accuracy.

-- Gabor

-- Gabor

thedestroyer

Observer

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

08-12-2011 08:27 AM

3,921 Views

Registered:
07-12-2011

Thank you for your reply!

WoW!!!! I used 5 low pass and 5 high pass filters, and could impressively clean the signal from noise and background shifts in a very effective way!!! I fitted the line to a sine with an exponential and the fit was perfect with 10^-12 residuals!!!! I'm impressed, thank you for the idea!

Please find attached a sample of the filtered data. The plot is the fit with connected data points. Blue is the fit.

The filters I used have 2000 Hz to 15000 Hz band-pass.

I could get get with line fittings nice results with up to +/- 0.3 Hz maximum errors! So the question is now, how could I improve this? Let's say I'm looking for precision of +/- 0.001 Hz. Is that ever possible by improving the signal or by any other estimation method?

eteam00

Instructor

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

08-13-2011 11:28 AM

3,908 Views

Registered:
07-21-2009

How realistic is this error margin?

If you are filtering an input signal, what is the error of the sampling or generating timebase (including noise, jitter, etc.) ?

If the FPGA is the signal generator, how accurate is the FPGA's timebase?

-- Bob Elkind

SIGNATURE:

README for newbies is here: http://forums.xilinx.com/t5/New-Users-Forum/README-first-Help-for-new-users/td-p/219369

Summary:

1. Read the manual or user guide. Have you read the manual? Can you find the manual?

2. Search the forums (and search the web) for similar topics.

3. Do not post the same question on multiple forums.

4. Do not post a new topic or question on someone else's thread, start a new thread!

5. Students: Copying code is not the same as learning to design.

6 "It does not work" is not a question which can be answered. Provide useful details (with webpage, datasheet links, please).

7. You are not charged extra fees for comments in your code.

8. I am not paid for forum posts. If I write a good post, then I have been good for nothing.

README for newbies is here: http://forums.xilinx.com/t5/New-Users-Forum/README-first-Help-for-new-users/td-p/219369

Summary:

1. Read the manual or user guide. Have you read the manual? Can you find the manual?

2. Search the forums (and search the web) for similar topics.

3. Do not post the same question on multiple forums.

4. Do not post a new topic or question on someone else's thread, start a new thread!

5. Students: Copying code is not the same as learning to design.

6 "It does not work" is not a question which can be answered. Provide useful details (with webpage, datasheet links, please).

7. You are not charged extra fees for comments in your code.

8. I am not paid for forum posts. If I write a good post, then I have been good for nothing.

thedestroyer

Observer

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

08-13-2011 10:28 PM

3,905 Views

Registered:
07-12-2011

Thank you for your answer!

Using fitting with that complicated function I expressed in the first post, the error was very small, and The Allan Standard Deviation for the frequency of 4.9*10^5 measurements (decays like the ones I attached) was stable from the simulation.

About being not accurate in the FPGA for precission reasons is not the issue right now. I want a theoretical method that I could apply on C++ or Mathematica and gain the best accuracy ever, and then lateron implement this method on an FPGA and gain errors that only have to do with precission in the FPGA.

In the real experiment, the signal isn't generated by an FPGA, but by an ADC that gets its result from a real experiment, and then received by an FPGA for detecting the frequenecy.

Does this make sense? Am I on the right path?