Power spectral density function

Link to program folder

Project description

The initial goal was to represent several data sets in the power spectral density format. I discover early that the data collected would already be in this form. Since I had already started to structure my program and thoughts, and was short on alternative ideas, I continued with the program with an alternative goal: make the transition from power spectral density to an accumulating power function and back to power spectral density, to see what this does to the data and to have the option to compare collected data to others that might use accumulating data.


The power spectral density function is the measure of a signals power content across a frequency spectrum. It is defined as:

Where W is an accumulating power function over different frequencies.

Since I have no function to work with, only datapoints, I will be using a discrete derivative.

As one can see from this function, there is no way of describing the first and last x. This means that we should see some differences in the processed data compared to the initial data.

Program description

Analyzing some data

image 1: test data

These images show some random data being processed. The first image is the raw data, the second is the accumulated power function and the third is a discrete derivative of the accumulated function. We can clearly see that some of the data has been lost. The last datapoint has become zero, this has also happened to the first, but is not as clear from the low power value. We can also see that sharp changes in the data has been glossed over. The variation in power at 52-55, as an example is simply gone.

image 2: soundwave

Image 2 shows some data from a sensor measuring sound. The differences between the raw data and the processed are not that obvious, but the resolution is also higher. Which is also something important when comparing with other data.

image 3: compare

Image 3 is a comparison of the sound sensor data and the test data. Since the test data had one datapoint per 1kHz and the sound sensor data had one datapoint each 0.42kHz, I had to change the amount of datapoints in the sound sensor data to compare them. I made a method to sum the data for each 1kHz. Since 0.42 do not add up in ones the result in the raw data image is suffering from resolution errors. But after possessing the data, we get back something that is very similar to the data with the correct resolution.

image 4: soundwave with full resolution, limited to 70 kHz

image 5: soundwave with 1kHz resolution after prosessing

The reason that the power needs to be distributed on the same amount of frequencies is clear from the power difference in the full resolution image compared to the 1kHz resolution image. The power is correct in both instances but divided over a different number of “containers”.


Using a discrete derivative gives only an approximation that leaves out sudden changes and the first and last datapoint.

When comparing power in the frequency spectrum, use the same resolution.

Integrating and derivation can smooth out some resolution issues.

Link to program folder


Added an option to show a dataset with error bands.

image 6: menu with a sixth option

image 7: error bands