Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6128939
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:41:04+00:00 2026-05-23T16:41:04+00:00

I am creating a tuning fork app, where you pat the iPhone into the

  • 0

I am creating a tuning fork app, where you pat the iPhone into the palm of your other hand, or against a soft surface in order to set the fork zinging.

So I would like to detect the energy contained in each ‘bump’

(EDIT: Removed a ton of gumpf)

Can anyone help me crack this one?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T16:41:04+00:00Added an answer on May 23, 2026 at 4:41 pm

    Thanks to one of the wizards on freenode’s #math channel (thanks Igor), I have a really good working solution.

    You use the standard method to fire a callback at the maximum frequency possible (100Hz), which will contain the instantaneous acceleration x,y,z values.

    I will let the code speak for itself, good code should always speak for itself.

    typedef 
    struct {
        double x,y,z;
    }
    vec_d3;
    
    #define RECENT_COUNT 10
    
    #define SMOOTH_IP( x, x_new, fac )  x  =  fac * x  +  ( 1. - fac ) * x_new
    
    - (void) accelerometer: (UIAccelerometer *) accelerometer 
              didAccelerate: (UIAcceleration *) acceleration 
    {
        // smooth incoming acceleration values
        static vec_d3 smooth = { DOUBLE_EMPTY, 0, 0 };
    
        {
            if ( smooth.x == DOUBLE_EMPTY )
            {
                smooth.x = acceleration.x;
                smooth.y = acceleration.y;
                smooth.z = acceleration.z;
    
                return;
            }
    
            SMOOTH_IP( smooth.x, acceleration.x, 0.9 );
            SMOOTH_IP( smooth.y, acceleration.y, 0.9 );
            SMOOTH_IP( smooth.z, acceleration.z, 0.9 );
        }
    
        // keep track of last k smoothed acceleration values
        static vec_d3 recent[ RECENT_COUNT ];
        {
            static int ptr = 0;
            static BOOL gotEnoughData = NO;
    
            recent[ ptr ] = smooth;
    
            ptr++;
            if ( ptr == RECENT_COUNT )
            {
                ptr = 0;
                gotEnoughData = YES;
            }
    
            // return if array not filled yet
            if ( ! gotEnoughData )
                return;
        }
    
        // get the resultant variation in acceleration over the whole array
        double variation;
        {
            vec_d3 min = smooth, max = smooth;
    
            for ( int i=0; i < RECENT_COUNT; i++ )
            {
                min.x = MIN( min.x, recent[ i ].x );
                min.y = MIN( min.y, recent[ i ].y );
                min.z = MIN( min.z, recent[ i ].z );
    
                max.x = MAX( max.x, recent[ i ].x );
                max.y = MAX( max.y, recent[ i ].y );
                max.z = MAX( max.z, recent[ i ].z );
            }
    
            vec_d3 V = (vec_d3) 
            {
                .x = max.x - min.x,
                .y = max.y - min.y,
                .z = max.z - min.z
            };
    
            variation = sqrt(
                             V.x * V.x  +
                             V.y * V.y  +
                             V.z * V.z
                             );
        }
    
        // smooth it
        static double var_smoothed = DOUBLE_EMPTY;
        {
            if ( var_smoothed == DOUBLE_EMPTY )
            {
                var_smoothed = variation;
                return;
            }
            SMOOTH_IP( var_smoothed, variation, 0.9 );
        }
    
    
        // see if it's just passed a peak
        {
            static double varSmoothed_last = DOUBLE_EMPTY;
            if ( varSmoothed_last == DOUBLE_EMPTY )
            {
                varSmoothed_last = var_smoothed;
                return;
            }
    
            static double varSmoothed_preLast = DOUBLE_EMPTY;
            if ( varSmoothed_preLast == DOUBLE_EMPTY )
            {
                varSmoothed_preLast = varSmoothed_last;
                varSmoothed_last = var_smoothed;
                return;
            }
    
    #define THRESHOLD_IMPULSE .15
    
            if ( varSmoothed_last > varSmoothed_preLast  
                &&  varSmoothed_last > var_smoothed  
                &&  varSmoothed_last > THRESHOLD_IMPULSE )
            {
                LOG ( @"PotPeak @ %f", varSmoothed_last );
    
                // hit a peak at imp_last
                [self peakedWithImpulse: varSmoothed_last ];
            }
    
            varSmoothed_preLast = varSmoothed_last;
            varSmoothed_last = var_smoothed;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When creating iPhone apps in simulator, I sometimes see messages like Springboard failed to
I am creating an iOS app using Flex 4.5 (Flash Builder 5.5) and I
I'm creating an app, that is in some point turning photo library on. The
Creating liquid layouts is an immense pain. Now, I totally understand that tables should
Creating a google map with store locations within 50 miles of user entered address.
(creating a separate question after comments on this: Javascript redeclared global variable overrides old
Creating a server-side socket will fail if I'm trying to use the same port
Creating a JApplet I have 2 Text Fields, a button and a Text Area.
Creating a simple RPG game, first time using XNA. Trying to get my character
When creating a new service in a WCF service project, Visual Studio will automatically

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.