Calculating V/sqrt(hz) from fft - Page 1
Forum section: electronics / projects

author: Solberg
author_rank: Contributor
timestamp: June 29, 2021, 07:29:31 pm
content: HiI'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.

author: Solberg
author_rank: Contributor
timestamp: June 29, 2021, 07:35:34 pm
content: Here is some of the code:Calculating the fft, and remove the dc component.Code:def calcfft(self, volt, deltatid):self.N = len(volt)self.T = 1 / 20458.6dc_removed = scipy.signal.detrend(volt)yf = fft(dc_removed)xf = fftfreq(self.N, self.T)[:self.N // 2]return xf, yfAnd this is how i Plot the DataCode:self.graphWidget.plot(self.xdata, 2.0 / len(self.Voltage) * np.abs(self.ydata[0:len(self.Voltage) // 2]))

author: bson
author_rank: Unknown
timestamp: June 29, 2021, 07:44:17 pm
content: Divide the magnitude of each bucket by the square root of its frequency span.

author: Solberg
author_rank: Contributor
timestamp: June 29, 2021, 07:55:17 pm
content: Quote from: bson on June 29, 2021, 07:44:17 pmI think my math skills are too rusty.Would it be possible for you to show me how, maybe in pseudo code.

author: gf
author_rank: Super Contributor
timestamp: June 29, 2021, 09:04:56 pm
content: Sampling rate is obviously 20458.6Then the bin width is 20458.6 / NSo just divide the currently displayed magnitude by sqrt(bin_width)Btw, here2.0/ len(self.Voltage) * np.abs(self.ydata[0:len(self.Voltage) // 2])you should not double the magnitude of the DC bin ydata, 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).

author: Solberg
author_rank: Contributor
timestamp: June 29, 2021, 09:32:18 pm
content: Quote from: gf on June 29, 2021, 09:04:56 pmLike This?Code: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 2kHzDoes that look right?

author: gf
author_rank: Super Contributor
timestamp: June 29, 2021, 09:53:28 pm
content: 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.

author: bson
author_rank: Unknown
timestamp: June 29, 2021, 10:09:23 pm
content: Quote from: Solberg on June 29, 2021, 09:32:18 pmThe 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.

author: Solberg
author_rank: Contributor
timestamp: June 29, 2021, 10:10:29 pm
content: Quote from: gf on June 29, 2021, 09:53:28 pmThe signal is just for testing. What I want to measure is op-amp noise.Is there a better test signal I can use?

author: Solberg
author_rank: Contributor
timestamp: June 29, 2021, 10:15:22 pm
content: Quote from: bson on June 29, 2021, 10:09:23 pmAgreed 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)?

author: gf
author_rank: Super Contributor
timestamp: June 29, 2021, 10:19:33 pm
content: Quote from: Solberg on June 29, 2021, 10:15:22 pmYes, as said above: "This unit is more useful for wideband signals like noise."And for noise I also suggest rather Vrmsinstead of Vpeak, since a sinewave peak value is not representative for noise => i.e. divide additionally by sqrt(2) to get RMS

author: gf
author_rank: Super Contributor
timestamp: June 30, 2021, 04:27:45 pm
content: When I think about it more closely, then I come to the conclusion that you do not really want theamplitudespectral density, for the noise measurement use case, but rather the (one-sided)PowerSpectral Density (PSD), or the sqrt of the PSD if you want V/sqrt(Hz) instead if V²/Hz.

author: bson
author_rank: Unknown
timestamp: June 30, 2021, 09:54:36 pm
content: 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.

author: Solberg
author_rank: Contributor
timestamp: July 01, 2021, 10:18:16 am
content: Thank yoy gf and bson. for your great feedback.I will try what you have both suggested.