Turn on suggestions

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

Showing results for

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

sharon1991

Member

11-03-2016 07:29 AM

Options

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

I have evenly sampled data, where each data point corresponds to a point on a sine wave. I need to detect the peak of the sine wave during a particular time window, and so I need to fit a sine wave to my data points.

For now, I have used a polynomial fit (attached LabVIEW 2013 code and screenshots), but this isn't good enough. Each data point I have should be on the sine-fit line.

Is there any way of doing this in LabVIEW?

- Tags:
- Sine-fit

Norbert_B

Proven Zealot

11-03-2016 08:00 AM

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

Instead of looking into curve fitting functions, i recommend using a higher sample rate for acquisition. This results for more data to work on and there is a higher chance to have the maximum (peak as you call it)as a direkt sample.

Also note that measurement inaccuracies and rounding errors add up during analysis. Depending on the oversampling rate (sine frequency vs. sampling frequency), simply picking the maximum value could already be equally accurate.

Norbert

Norbert

----------------------------------------------------------------------------------------------------

CEO: What exactly is stopping us from doing this?

Expert: Geometry

Marketing Manager: Just ignore it.

----------------------------------------------------------------------------------------------------

CEO: What exactly is stopping us from doing this?

Expert: Geometry

Marketing Manager: Just ignore it.

11-03-2016 08:37 AM

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

Norbert_B

Proven Zealot

11-03-2016 08:45 AM

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

Then i recommend to discuss the maximum excepted error. Depending on the result, the recommended "just pick the maxmimum value" might still be valid.

If the basic signal is known to be a sine waveform, i'd rather use resample than interpolation...

Norbert

Norbert

----------------------------------------------------------------------------------------------------

CEO: What exactly is stopping us from doing this?

Expert: Geometry

Marketing Manager: Just ignore it.

----------------------------------------------------------------------------------------------------

CEO: What exactly is stopping us from doing this?

Expert: Geometry

Marketing Manager: Just ignore it.

CtheR

Member

11-03-2016 09:12 AM - edited 11-03-2016 09:18 AM

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

Does your Sine change its frequency over time?

If not you just need two data points (x1,t1) and (x2,t2). Then you can calculate A and w from 2 equations with 2 variables

x1=A*sin(w*t1) and x2=A*sin(w*t2) with simple math. Your sine_max is A.

Bob_Schor

Knight of NI

11-03-2016 09:15 AM

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

Do you know the frequency of the sinusoid, and the sampling frequency? In that case, you can easily fit a sinusoid to the data, and use the phase information to tell you when the peak of each single sine wave occurs.

Can you attach an example data file (let us know the format so we can read it), tell us the sampling frequency, and one of us (such as I, unless someone beats me to it) will look at and suggest how to "find the peaks".

Bob Schor

11-03-2016 09:37 AM

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

johnsold

Knight of NI

11-03-2016 09:37 AM

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

The data you posted is not very sinusoidal. The image below shows a "manual" fit of a sine to your data. I adjusted the offset to match the zero crossing and then a multiplier to match the slope near the zero crossing. The plotted fit is sin(m*(x-b)) where be is the x value at the zero crossing and m is the multiplier.

Peak Detector.vi seems to work OK with your data. It finds the peak as x = 0.8096, which appears reasonable.

Lynn

11-03-2016 09:38 AM

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

Bob_Schor

Knight of NI

11-03-2016 09:49 AM

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

Sorry, I didn't look at the pictures (pictures are almost __never__ data, they are at best "pictures of data"). However, now that I have, I "see the problem" -- you may only have a fraction of a sinusoid represented by your data, which makes the problem "problematic". A sinusoid is characterized by four numbers -- offset (DC value), amplitude, phase, and frequency. If you have multiple cycles, you can estimate frequency, and if you know frequency, you can estimate the other three parameters easily. If you have less than a cycle, the estimation problem becomes much more difficult.

I will repeat my request. Can you attach a (complete) set of data? I can't do any computations from a __picture__ -- I need __numbers__ (or a file whose format you describe to me so I can extract the numbers).

Bob Schor