Author Topic: Calculating V/sqrt(hz) from fft  (Read 2888 times)

0 Members and 1 Guest are viewing this topic.

Offline SolbergTopic starter

  • Contributor
  • Posts: 30
  • Country: dk
Calculating V/sqrt(hz) from fft
« on: June 29, 2021, 07:29:31 pm »
Hi

I'm trying to calculate the V/sqrt(hz) of a signal.

Right now I'm using the ADC of an atmega, to sample the signal from my waveform generator.

I have figured out how to calculate Vpeak, but I would like the fft to display in V/sqrt(hz) instead.

I'm using Scipy to calculate the fft. In Python.

I Just can't find any information on it. Or figure out how to do it.

The Picture is of the program, with a 400 milivolt-Peak-to-Peak signal, at 2kHz.
 

Offline SolbergTopic starter

  • Contributor
  • Posts: 30
  • Country: dk
Re: Calculating V/sqrt(hz) from fft
« Reply #1 on: June 29, 2021, 07:35:34 pm »
Here is some of the code:

Calculating the fft, and remove the dc component.
Code: [Select]
    def calcfft(self, volt, deltatid):
        self.N = len(volt)
        self.T = 1 / 20458.6

        dc_removed = scipy.signal.detrend(volt)
        yf = fft(dc_removed)
        xf = fftfreq(self.N, self.T)[:self.N // 2]
        return xf, yf

And this is how i Plot the Data
Code: [Select]
self.graphWidget.plot(self.xdata, 2.0 / len(self.Voltage) * np.abs(self.ydata[0:len(self.Voltage) // 2]))
           
 

Offline bson

  • Supporter
  • ****
  • Posts: 2457
  • Country: us
Re: Calculating V/sqrt(hz) from fft
« Reply #2 on: June 29, 2021, 07:44:17 pm »
Divide the magnitude of each bucket by the square root of its frequency span.
 
The following users thanked this post: Solberg

Offline SolbergTopic starter

  • Contributor
  • Posts: 30
  • Country: dk
Re: Calculating V/sqrt(hz) from fft
« Reply #3 on: June 29, 2021, 07:55:17 pm »
Divide the magnitude of each bucket by the square root of its frequency span.


I think my math skills are too rusty.

Would it be possible for you to show me how, maybe in pseudo code.
 

Offline gf

  • Super Contributor
  • ***
  • Posts: 1334
  • Country: de
Re: Calculating V/sqrt(hz) from fft
« Reply #4 on: June 29, 2021, 09:04:56 pm »
Sampling rate is obviously 20458.6
Then the bin width is 20458.6 / N
So just divide the currently displayed magnitude by sqrt(bin_width)

Btw, here

    2.0 / len(self.Voltage) * np.abs(self.ydata[0:len(self.Voltage) // 2])

you should not double the magnitude of the DC bin ydata[0], because -0Hz and +0Hz already share the same DFT bin, and are already summed-up.
The same applies to the Nyquist bin ydata[N/2] if N is even (-> then the bin ydata[N/2] is shared too, between frequencies +fs/2 and -fs/2).
Doubling the magnitude of all other frequency bins in the range 1:(N-1)//2 is correct, if your aim is to obtain a positive-only spectrum from the fft spectrum (which has positive and negative frequencies).
« Last Edit: June 29, 2021, 09:49:54 pm by gf »
 
The following users thanked this post: Solberg

Offline SolbergTopic starter

  • Contributor
  • Posts: 30
  • Country: dk
Re: Calculating V/sqrt(hz) from fft
« Reply #5 on: June 29, 2021, 09:32:18 pm »
Sampling rate is obviously 20458.6
Then the bin width is 20458.6 / N
So just divide the currently displayed magnitude by sqrt(bin_width)

Like This?

Code: [Select]
bin = 20458.6 / len(self.Voltage)
self.graphWidget.plot(self.xdata, (2.0 / len(self.Voltage) * (np.abs(self.ydata[0:len(self.Voltage) // 2]))) / sqrt(bin))

Then I get this: An amplitude of 0.06 (V/sqrt(hz))? with a 400milivolt peak-to-peak signal at 2kHz
Does that look right?
 

Offline gf

  • Super Contributor
  • ***
  • Posts: 1334
  • Country: de
Re: Calculating V/sqrt(hz) from fft
« Reply #6 on: June 29, 2021, 09:53:28 pm »
IMO it is not really useful to measure the amplitude of a single-frequency/zero-bandwidth signal in unit of V/sqrt(Hz).
This unit is more useful for wideband signals like noise.
« Last Edit: June 29, 2021, 10:09:58 pm by gf »
 

Offline bson

  • Supporter
  • ****
  • Posts: 2457
  • Country: us
Re: Calculating V/sqrt(hz) from fft
« Reply #7 on: June 29, 2021, 10:09:23 pm »
Then I get this: An amplitude of 0.06 (V/sqrt(hz))? with a 400milivolt peak-to-peak signal at 2kHz
Does that look right?
The graph should look exactly the same since you scale each value by a constant.  Only the unit changes.

As was pointed out previously, it's not terribly meaningful.
 

Offline SolbergTopic starter

  • Contributor
  • Posts: 30
  • Country: dk
Re: Calculating V/sqrt(hz) from fft
« Reply #8 on: June 29, 2021, 10:10:29 pm »
IMO it is not really useful to measure the amplitude of a single-frequency/zero-bandwidth signal in unit of V/sqrt(Hz).
This unit is more useful for wideband signals like noise.


The signal is just for testing. What I want to measure is op-amp noise.

Is there a better test signal I can use?
 

Offline SolbergTopic starter

  • Contributor
  • Posts: 30
  • Country: dk
Re: Calculating V/sqrt(hz) from fft
« Reply #9 on: June 29, 2021, 10:15:22 pm »
Then I get this: An amplitude of 0.06 (V/sqrt(hz))? with a 400milivolt peak-to-peak signal at 2kHz
Does that look right?
The graph should look exactly the same since you scale each value by a constant.  Only the unit changes.

As was pointed out previously, it's not terribly meaningful.


Agreed its not meaningful with the test signal. But i want to measure the noise of op-amps. isn't most noise measured in nV/sqrt(Hz)?
 

Offline gf

  • Super Contributor
  • ***
  • Posts: 1334
  • Country: de
Re: Calculating V/sqrt(hz) from fft
« Reply #10 on: June 29, 2021, 10:19:33 pm »
Agreed its not meaningful with the test signal. But i want to measure the noise of op-amps. isn't most noise measured in nV/sqrt(Hz)?

Yes, as said above: "This unit is more useful for wideband signals like noise."
And for noise I also suggest rather Vrms instead of Vpeak, since a sinewave peak value is not representative for noise => i.e. divide additionally by sqrt(2) to get RMS
« Last Edit: June 29, 2021, 10:25:26 pm by gf »
 
The following users thanked this post: Solberg

Offline gf

  • Super Contributor
  • ***
  • Posts: 1334
  • Country: de
Re: Calculating V/sqrt(hz) from fft
« Reply #11 on: June 30, 2021, 04:27:45 pm »
When I think about it more closely, then I come to the conclusion that you do not really want the amplitude spectral density, for the noise measurement use case, but rather the (one-sided) Power Spectral Density (PSD), or the sqrt of the PSD if you want V/sqrt(Hz) instead if V²/Hz.
 
The following users thanked this post: Solberg

Offline bson

  • Supporter
  • ****
  • Posts: 2457
  • Country: us
Re: Calculating V/sqrt(hz) from fft
« Reply #12 on: June 30, 2021, 09:54:36 pm »
I would suggest to characterize an op amp, you would measure both its input and output, then subtract the input spectrum from the output.  Now you're left with the op amp's spectral contribution.

For the sake of argument, say you have 1kHz bins and want to measure the noise in a 1kHz to 10kHz band, then you add up the magnitudes of the bins, and subtract by the square root of the bandwidth (9kHz), or sqrt(9k) = 30*sqrt(10) = 94.86.

And, good point - the values are peak values, not RMS and usually noise density is expressed as an RMS voltage.

If you measure it across the entire bandwidth of the op amp you get something akin to a Noise Figure.

If you want the noise density from DC, don't omit the 0 bin; the noise can very well have a DC component, and often does when dealing with semiconductors.
 
The following users thanked this post: Solberg

Offline SolbergTopic starter

  • Contributor
  • Posts: 30
  • Country: dk
Re: Calculating V/sqrt(hz) from fft
« Reply #13 on: July 01, 2021, 10:18:16 am »
Thank yoy gf and bson. for your great feedback.

I will try what you have both suggested.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf