Power NP

Former Member
Former Member

Hi,

How we can calculate Power NP? I am reading different ways but I tried with no success..

I need help Slight smile

Best regards,

  • Here's some pseudocode. You have to fill in your own implementation of a fixed-size queue.

    class FixedSizeQueue() {
        function initialize(size) {
            // create queue with size elements
            // TODO...
        }
    
        function enqueue(x) {
            // insert x at back of queue
            // TODO...
            // if queue size > size, remove front item from queue
            // TODO...
        }
    
        // ^ This can implemented with a fixed length array and two
        // indexes which point to the first and last items in the 
        // queue
    
        function size() {
            // return the size of queue
            // TODO...
        }
    }
    
    class RollingAverage() {
        var fixedSizeQueue;
        var size;
        function initialize(s) {
            size = s;
            fixedSizeQueue = new FixedSizeQueue(size);
        }
    
        function addData(x) {
            fixedSizeQueue.enqueue(x);
            // fixedSizeQueue only holds up to size elements
            // If more elements are added, the oldest elements drop off
        }
    
        function getAvg() {
            if (fixedSizeQueue.size() < size) {
                return null;
            } else {
                // return average of all elements in fixedSizeQueue
                // TODO...
            }
        }
    }
    
    class NormalizedPower() {
        var numSamples;
        var rolling_power_data;
        var average_rolling_power_4;
        function initialize() {
            rolling_power_data = new RollingAverage(30);
            average_rolling_power_4 = 0;
            numSamples = 0;
        }
    
        // compute() takes the current power as an argument
        // and returns either null or the calculated normalized power 
        // Assumption: this function is called once per second
        function compute(currentPower) {
            rolling_power_data.addData(currentPower);
    
            var rolling_power = rolling_power_data.getAvg();
            if (rolling_power == null) {
                return null;
            }
    
            numSamples++;
            var rolling_power_4 = Math.pow(rolling_power, 4);
    
            average_rolling_power_4 = (average_rolling_power_4 * (numSamples-1) + (rolling_power_4)) / numSamples;
    
            return Math.pow(average_rolling_power_4, 0.25);
        }
    }
    
    
    class NpView extends Ui.SimpleDataField {
        var np;
        // init program
        function initialze() {
            np = new NormalizedPower();
        }
    
        // Assume compute() is called once per-second by the CIQ framework
        function compute(activityInfo) {
            var currentPower = activityInfo.currentPower;
            var currentNP = np.compute(currentPower);
    
            if (currentNP == null) {
                return "--";
            }
    
            return currentNP;
        }
    }

    And here's the original thread where the code was posted, with context: forums.garmin.com/.../normalized-power-fomula-by-garmin