LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Amplitude Spectrum and 1/3 Octave Analysis

Hi,

 

I am slightly confused by the operation of the Amplitude Spectrum VI.  If you feed in a constant sine wave but with differing numbers of samples (4096, 8192, 16384) you get different peak amplitudes out, with or without windowing. In any case, if I'm putting 1V rms in, how come I don't get 1V rms out?

 

Also, I am trying to make a 1/3 octave filter to measure background noise and I am curious to know how to calculate the in-band power for each 1/3 octave.  Again, the results change with sample size.

 

I know that NI do a Sound and Vibration Measurment suite but I cannot afford it at the moment and in any case am keen to learn more about signal processing.  If anyone can help I'd appreciate it.

 

Many thanks

 

Malcolm

Certified LabVIEW Architect and LabVIEW Champion specialising in Noise, Vibration and Harshness
0 Kudos
Message 1 of 5
(7,076 Views)

Malcolm,

 

Fun with spectral analysis!

 

Several things are happening. Spectral leakage. Non-synchronous sampling. Finite data sets.  Maybe some others.

 

The fundamental mathematics of the Fourier series assumes an infinitely repeating (in time) continuous periodic signal. You violate all of those assumptions and expect the result to be the same as if they are valid? 

 

Look at the image below.  This is from your VI with 1024 samples and the spectrum graph set to show the datapoint on a small segment of the spectrum.

 

Spectrum.png

 

Notice that there are about 6 non-zero points and that they are not symmetrically distributed around the peak.  The total energy in those six points probably comes close to measuring the energy in your signal.

 

1. The Fourier transforms used in the LV spectral analysis VIs calculate the spectrum of a signal which consists of the finite dataset at the input as if it were concatenated onto itself infintely many times.  If you look closely at the data you have generated, you will see that the signal does not start and end at the same voltage and that it does not contain a integer number of complete cycles. The image below shows 2 segments of the data as concatenated from a 128 sample signal.  That signal clearly has some spectral components not at the fundamental frequency.

 

128 samples concatenated.png

 

2. Windowing helps minimize the effect of the finite data set by reducing the values at the end of the dataset to near zero. Thus the effects of the discontinuities at the ends of the original datset are minimized.  The choice of window functions is an art and depends on the nature of your signal, any noise or interference present and what you will be doing with the spectral results. If you look at the first element in the spectral output array (the ~zero-frequency or DC component) you will see that windowing reduces it substantially.

 

3. If the frequency of the signal is not exactly a subharmonic of the sampling rate, some of the energy "spills over" into adjacent frequency bins.  Some of that effect is visible in the first image above.  In general synchronized sampling does not occur. So to get amplitudes of spectral components you need to include the adjacent bins. But you cannot just sum them. Because of phase relations and possible amplitude scaling within the spectrum VIs, the correct way to get the amplitude has to be evaluated carefully.  For example with samples set to 1024 the sum of 7 points centered around the peak is 1.27 compared to Max Vrms = 0.988 without a window and 1.01 compared to 0.498 with the window function. If you look at the windowed signal in the time domain compared to the generated sine you can see that the "average" energy must be much less.  However the ratio of the peak spectral value to the sum of adjacent bins is higher with the windowed version because the windowed signal has less energy outside the "desired" spectral bins.

 

Are you more confused than before I started?

 

Lynn

 

 

Message 2 of 5
(7,065 Views)

Lynn,

 

Thank you for such a comprehensive response.  I understood most of it but the numbers in 3. baffled me a bit, as in, where did you get them from?

 

Interesting that you mention a problem when a signal frequency is not a submulitple of the sampling frequency.  I had always heard the opposite that if you sampled a 1k signal with a 16k sample you might get errors because you were always sampling at the same 'point' on the waveform and that sampling a frequency of say 997 Hz would be better.

 

I can appreciate the need for windowing when searching for a signal in noise.  However, I am looking just to measure the level of broadband noise, so I felt I could get away from that.  Nevertheless, some windowing might be beneficial to stop the edge effects you talk about.  I will do some more work and then post again.

 

Finally do you have an answer about 1/3 octave analysis?  Namely, if I do a 16384 FFT and a 32768 FFT each bin in the 32768 FFT will have twice the number of samples, hence twice the energy, of the smaller FFT.  So the longer the FFT the 'louder' the signal.  Clearly there must be some way to use the sampling frequency to scale the answer for time so that levels do not double with every doubling of FFT size.  I have tried to take the mean but that doesn't seem to work.  Any ideas?

 

Thanks

 

Malcolm

Certified LabVIEW Architect and LabVIEW Champion specialising in Noise, Vibration and Harshness
0 Kudos
Message 3 of 5
(7,057 Views)

Malcolm,

 

I will answer the question about the numbers in 3 now. The question about the 1/3 octave analysis will take a little time to put together some demos and make sure my thinking is clear.

 

Test spectrum.png

 

The indicator named "sum" is the sum of 7 elements of the spectrum array centered on the highest peak.  The Max Vrms is unmodified from your VI. The False case is just wired straight through to allow checking an unwindowed data sample.  I did not need to duplicate the Array Max & Min - just not paying attention to the fact that it was already there. So I ran the VI twice, once with windowing and once without to get the numbers I posted.

 

You are right that synchronous sampling has its own issues.  If you sample exactly two times per cycle (which fails the Nyquist criterion - a strict inequality), you could sample exactly on the zero crossings and every sample would be exactly zero. If you sample exaclty four times per cycle you could get samples of 0, 1, 0, -1 for a unit amplitude sine wave where the first sample was at zero phase. You could also get samples of 0.71, 0.71, -0.71, -0.71 when the first sample was at 45 degrees.  Similarly, 30 degrees to the first sample generates 0.50, 0.87, -0.50, -0.87.  So lots of samples per cycle make it easy to estimate the peak amplitude while fewer cycles require more complicated reconstruction.  If you know that you are sampling at zero crossings and peaks, it is easy to get the amplitude. If you do not know the phase it is more difficult.  When you are not synchronized the sample "phase" changes with each cycle.

 

The same thing is true of the spectrum. If you only have few spectral bins (coarse frequency resolution), it is more difficult to estimate the energy in each signal component. And if the bins do not align with the frequency of the signal, as they generally do not, the process requies some care to get valid results.  The Fourier transform also calculates phase information as well as amplitude information and both need to be accounted for in determining the reults.

 

I will put something together later today or tomorrow to address the 1/3 octave and FFT size issues.

 

Lynn

0 Kudos
Message 4 of 5
(7,043 Views)

Dear Lynn,

 

Again thanks for your response.  I have also had some success today.  Rather than using the Amplitude Spectrum.vi then trying to square and sum I have used the Auto Power Spectrum.vi.  This has allowed me to sum values in bins.  I now get values from my FFT and 1/3 octave that are within 0.1 dB of the original signal, which is pretty good considering I'm not doing anything too fancy with my processing.  I'm sure it was my maths that was wrong.

 

As I said earlier, I am measuring broad spectrum noise so I don't think I have to worry too much about resolution or windowing.  However, I do appreciate that to get low frequency bins you need a long FFT so I am currently using 32768 for a 48k sampling frequency.  I will probably raise this to 51,200 since that appears to be a favourite sampling frequency for the 4474 cards I am using.

 

Regards

 

Malcolm

Certified LabVIEW Architect and LabVIEW Champion specialising in Noise, Vibration and Harshness
0 Kudos
Message 5 of 5
(7,035 Views)