cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Did you get an answer that solved your problem? Please mark it as an Accepted Solution so others with the same problem can find the answer easily. X

Spectrum analyser

Luc_Meekes-disa
1-Newbie

Spectrum analyser

Collabs,

I need a spectrum analyser to examine simulated output of a sytem that does digital signal processing.

I build my simulations in Mathcad, so I want the spectrum analyser to work in Mathcad as well. And of course I'll use one of the DFT functions available: the one that best fits the world of electronic engineers is (C)FFT.

After a lot of digging around I've come up with a machine that (almost) does the trick in a way that is suitable for me.

The attached sheet contains the machine (yellow), as well as a lot of dressing to check it.

It reports the input signal components well, both in magnitude and phase. So I should be happy... I'm not, because it doesn't satisfy Parseval's relation, so that I cannot take power measurements in the frequency domain.

Does anybody know:
- how to make this work?
- an explanation why it is impossible?

Thanks,
Luc
31 REPLIES 31

On 5/19/2009 8:30:49 AM, Luc_Meekes wrote:
>Collabs,
>
>I need a spectrum analyser to
>examine simulated output of a
>system that does digital signal
>processing.
>
>I build my simulations in
>Mathcad, so I want the
>spectrum analyser to work in
>Mathcad as well. And of course
>I'll use one of the DFT
>functions available: the one
>that best fits the world of
>electronic engineers is
>(C)FFT.
>
>After a lot of digging around
>I've come up with a machine
>that (almost) does the trick
>in a way that is suitable for
>me.
>
>The attached sheet contains
>the machine (yellow), as well
>as a lot of dressing to check
>it.
>
>It reports the input signal
>components well, both in
>magnitude and phase. So I
>should be happy... I'm not,
>because it doesn't satisfy
>Parseval's relation, so that I
>cannot take power measurements
>in the frequency domain.
>
>Does anybody know:
>- how to make this work?
>- an explanation why it is
>impossible?
>
>Thanks,
>Luc
_____________________________

Luc,

I understand nothing or not completely.
An instrument is calibrated for a measured range of the experiment. It is then converted (most commonly into a 4... 20mA loaded by an accurate 250 Ohms at the input card for an analog range of 1... 5V. That is the analog seen by the A/D converter, which after the conversion is scaled 0...1V for so many bits + sign. A 10 bits + sign gives a resolution of 1000/1024 = 0.98 mV.

That is not enough in Process control & Instrumentation, we use 12 bits + sign for a resolution of 1000/4096 = 0.244 mV. There are input cards 18 bits + sign and in my time 24 bits + sign. What that means is that your 12 bits if it comes out of a standard measuring chain, it will have 0.244 mV. The number of bits is very critical if the input signal is "sosolikethis". It is not so much critical to get control of simple loops but the minimum standard is 12 bits + sign, taking into account lot of inertia and hysteresis in the loop.

In the attached, here is a typical uncalibrated waveform quantized by N (global definition cyan). Something not correct in your setup ... changing the number of bit should not change the amplitude of the waveform, you should see only finer and finer meshing of the waveform itself. All what you have is very complicated business ! Your model does not like 2 Pi ? But there is a curious two peaks ? What's not correct either is the absence of first discretizing the model function. It might be imputable to the programs ?
What is "Sample length" ? is it the number of accumulated values at the time of the loop scan "read" ? I have no recollection about Bruel & Kajer or Bentley Nevada vibration software. There are input cards of various capacity for the accumulated values, that's what you (C)FFT for a spectral of so many minutes/seconds accumulation.

I seem to understand you are balancing a dB reference in the system.

jmG


... sorry Luc,

There is a gross mistake in the previous attachment.

Jean

Jean,

My sampler uses a number of bits to characterise the A/D converter. Then with more bits I get a higher number of output counts. It also means that with more bits, the value of each output count decreases is something that is not reflected in the plot.
Hence you see a larger output (in counts) with more bits in the A/D converter, which is a completely correct modelling of the digital domain, the domain where Volts, Ampere's and Ohms of the analog domain do not exist. (But of course, there is a relation.)

Luc

Don't know if this helps or not, but power is not magnitude.

Fred Kohlhepp
fkohlhepp@sikorsky.com

On 5/19/2009 8:30:49 AM, Luc_Meekes wrote:
>Collabs,
>
>I need a spectrum analyser to
>examine simulated output of a
>sytem that does digital signal
>processing.
>
>.... it doesn't satisfy
>Parseval's relation, so that I
>cannot take power measurements
>in the frequency domain.

The frequencies used in CFFT are 0, �fo, �2fo, ...

The power is given by the DC component squared, plus all the other components squared divided by two.

When properly normalized, Parseval's relationship is maintained.

- Guy

In your SpectrumAnalyzer function you delete approximately half the vector after the CFFT. The second (approximately) half contains the complex conjugate of the first half. That's not needed for some things, such as viewing the spectrum, but you can't delete it and expect all operations on that vector to work the same. The simplest example is to just do the ICFFT. Without the complex conjugate part the result of the ICFFT will not be your original data, and will in fact be complex. Another example is that Parseval's relation will not work.

You also need to be careful deciding which points to delete, because it's not quite as simple as you think. If the number of points is even, then point 0 is unique (i.e. it does not have a corresponding point that is it's complex conjugate). If the number of points is odd, then both points 0 and ceil(last(R)/2) are unique. So n should be ceil(last(R)/2).

Richard

Your spectrum analyzer function has not allocated power correctly. For real signals, the positive and negative freq. terms each contribute equal power, not equal signal amplitudes (the point Guy makes). When computing an equivalent positive-only spectral component in the analyzer function, just use a scale factor of sqrt(2) instead of 2. This gives the correct power for the real freq. term, and is the RMS amplitude of the corresponding real sinusoid - what a real instrument gives. The Parseval relation at the end of your original sheet is then satisfied.

I don't understand why you use the imag. unit factor in the analyzer function. If the sampled signal is cos(w*t) (or sin with +90deg phase inyour model), then I expect the spectrum to have a positive real coef at the + and - freq terms. This is what you get without the 'i' factor. Did you have a particular reason for using it?

Lou



I don't see the philosophy behind getting a large number of data samples and interpreting a Fourier analysis of the whole range all together.
The Fourier analysis just repeats over and over again the fundamental cycles to the end and the data is corrupted in each new cycle.

On 5/20/2009 12:24:11 AM, bones7xx wrote:
>I don't see the philosophy
>behind getting a large number
>of data samples and
>interpreting a Fourier
>analysis of the whole range
>all together.
>The Fourier analysis just
>repeats over and over again
>the fundamental cycles to the
>end and the data is corrupted
>in each new cycle.
______________________________

That is totally true Theodore,
Fourier analysis is complete with only "one (1) period".

Jean




>
>That is totally true Theodore,
>Fourier analysis is complete with only
>"one (1) period".

Jean, Theodore,

You are completely right: one period suffices to characterise the complete signal.
Would you care to indicate what the period of my example signal is? Don't forget to take the noise part of the signal into acount....

Thanks,
Luc


On 5/22/2009 6:15:37 PM, Luc_Meekes wrote:
>
>>
>>That is totally true Theodore,
>>Fourier analysis is complete with only
>>"one (1) period".
>
>Jean, Theodore,
>
>You are completely right: one
>period suffices to
>characterize the complete
>signal.
>Would you care to indicate
>what the period of my example
>signal is? Don't forget to
>take the noise part of the
>signal into acount....
>
>Thanks,
____________________________

Luc,

The period is very close to 0.1 s, if not ?
0.1000005 s


Here is the rough work, that you can refine by getting a more exact by solving in some way aroud these two points. You might then want to size sig(t) in that exact range. Then you could use the Quantization sheet from before
Can't root accurately ! ?
Here is a spectral + a two periods plot.

You specified "white noise", i.e: on the amplitude only. Then we can't take the noise into account for a neat determination of the period. If we would use Theodore Budapest, the noise on the Cartesian X would have no influence, because the point would still be basically equally spaced like in the real life of experiments.

Jean

Luc,

What I have done here quick is damned wise (in my opinion). Toke the function sig(t) , discretized the 1rst period starting @ 0. Then applied the magnificent TA Budapest {Theodore] for a reconstruct of the needed scalar F(t). Then applied a thumb digitize, then as you would increase/decrease N [cyan] near the plot, you can read the digitized level. Finally, for a 1mV resolution, you need > 40096 levels of digitization, that means you need > 12 bits + sign. But that means nothing yet, why ? because the signal is not scaled 0 ... 1V like usual for A/D converters. What that means in real project is that you need a XTR (transmitter) that you can calibrate so that if the input card includes the A/D converter and is 12 bits + sign, you will then have your resolution .

Quite an interesting conclusion.
But all that we knew in advance.
More interesting is the spectral deviation between the sampled and the quantized 0.001 spectral in this example. That is a damned accurate spectral for the remaining of the project. The other meaning is that from a chain of measurements and past the analyzer, you would reconstruct a very accurate "original" signal.

That was a most interesting project, at this point well in hand !

Hope it helps, at least suggest comments.

Jean

PS: In real applications of sound design, we neglect noise. Adding noise in your analysis will do nothing valuable except complicate matters that you can't predict. Mostly T/C [Thermocouples] are prone to noise vis their small emf capability, then they act like antennas. Even then, a good installation is very immune to harsh environment.

Luc,

I will take the overall project, top to bottom, the parts that are scattered in several workshetes, the parts that I did and understand and that work ... will group in a single worksheet. Completely tutored for review, so that interested collabs and yourself can recompose your programmed version. There will be a scaling module and a special noise module, also the Delta rate used in this instance for determining the period.

Once done, will repost.

Today is gardening course 101, a long day ! Therefore it might take few bed time periods for composing this proposal, an expected long work sheet but within reason and as required.

Cheer, Jean.

Is my interpretation of the "Power spectrum correct" & PWR ?

Borrowed from the Treasury

jmG

Guy, Richard, Lou,

I guess you provided the direct answers to my questions. In short:
I can't transform the output of the CFTT to suit one of my output interests, and then expect regular operations that yield the correct answer on the direct CFFT output, to yield the same correct answer when applied to my transformed CFFT output.

Guy: thank you for providing a way to get the right power output.

Richard: I originally had a branch that chose between "if even" and "if uneven", then I saw a way to simplify the machine and not have to branch. I'll check your suggestion.

Lou: I didn't see the correct phase output, using the arg() function. If you look at the right page you can see that I investigated the phase output. Eventually I found that a phase turn of 90degrees was necessary, hence the multiplication with 1i.
Maybe there is an inconsistency in Mathcad between phase indicated by the CFFT output and what the arg() function makes of it?

Thank you.

Luc

You wrote your signal in terms of the sine rather than the cosine. That is the reason for the 90° phase inconsistency.

Arg is the correct way to get the phase. But phase is modulo 360°, so you can adjust by multiples of 2π to meet additional conditions.
__________________
� � � � Tom Gutman

Tom and Lou,

Lesson learned: I should define my sines using the cosine function.

Thanks!
Luc

Collabs,

Here is SpectrumAnalyser with two additional functions:
SignalPower to compute the power of a time-discrete signal
SpectralPower to compute the power of the output of the spectrum analyser over a given band width.

Luc

On 6/8/2009 4:00:11 AM, Luc_Meekes wrote:
>Collabs,
>
>Here is SpectrumAnalyser with
>two additional functions:
>SignalPower to compute the
>power of a time-discrete
>signal
>SpectralPower to compute the
>power of the output of the
>spectrum analyser over a given
>band width.
>
>Luc

Luc,
Are the green "OK" regions at the end meant to be actively calculated? or are they just personal notes?
[how did you calculate the cross check values?]

Philip Oakley

Philip,

It's merely noting that the spectrum analyser actually outputs what I put in. So I guess they are personal notes.

Somewhere along the line you see that with the choice of AD converter I get 1 mV / bit. So when the first (nonzero) frequency component that I put in with an amplitude of 1 V comes out with a magnitude of 1000 in the spectrum, I'm happy and mark it as OK. There's no magic.

Regards,
Luc

On 6/8/2009 4:00:11 AM, Luc_Meekes wrote:
>Collabs,
>
>Here is SpectrumAnalyser with
>two additional functions:
>SignalPower to compute the
>power of a time-discrete
>signal
>SpectralPower to compute the
>power of the output of the
>spectrum analyser over a given
>band width.
>
>Luc
_______________________________

Luc,

I don't have time to look at it but this work sheet is incorrect on sevral points resumed here:

1. Treat the problem on 1 (one) period, which has been calculated before with some difficulty as 0.1 exact.
2. The front end attached supposes a data set from which we extract the underlying function as if you would start at this point.
3. follows a typical digitization procedure generously sampled that is subject to user
3. taking it as is, "as is" means w/o A/D conditioning (typical 0... 1 V, then 14 bits are needed to achieve the 1 mV.
4 that may not be all , you must check the cfft(Sampled-Quantized).
5. for sure something is wrong in your setup, there is no 2 sparse peaks.
6.going back to 3/. if the signal was calibrated A/D 0... 1 V (like in standard Process Control & Instrumentation, a 10 bits + sign would be enough for a 1 mV resolution.
7. the power spectrum may not be all correct , ignore that part.
8. maybe you can compact the attached procedure in a real working program, except for the front end, i.e: the reconstruct from a data set and this part is necessary as data set are discrete. The proposal is a bit incorrect whereas there would be 2^n accumulated values instead of 1000 as illustrated, here for instance the closet would be 1024.

Your "Spectrum Analyzer" is incorrect at 1/. & 5/. & 8/.

Saved as Mathcad 2000.

Jean

PS: I can see your Vsf = 2.048/4096 = 0.5 mV resolution.
The difficulty to establish the period was caused by the small amount of rnd noise. The other point here is that the period does not exist in true life, only "pseudo-period", the length of the vector of accumulated values to be digitized, "pseudo-period = Fourier period = spectrum period".


PhilipOakley
5-Regular Member
(To:ptc-1368288)

I thought it was reasonable. Perhaps the task is at cross purposes. Each to his own, nothing wrong with either.

As they say here 'different strokes for different folks'

Philip Oakley

On 6/9/2009 5:43:01 PM, philipoakley wrote:
>I thought it was reasonable.
>Perhaps the task is at cross
>purposes. Each to his own,
>nothing wrong with either.
>
>As they say here 'different
>strokes for different folks'
>
>Philip Oakley
____________________________

Yes Philip,

something wrong in the work sheet showing the two peaks.

Jean



PhilipOakley
5-Regular Member
(To:ptc-1368288)

On 6/9/2009 7:54:46 PM, jmG wrote:
>On 6/9/2009 5:43:01 PM, philipoakley
>wrote:
>>I thought it was reasonable.
>>Perhaps the task is at cross
>>purposes. Each to his own,
>>nothing wrong with either.
>>
>>As they say here 'different
>>strokes for different folks'
>>
>>Philip Oakley
>____________________________
>
>Yes Philip,
>
>something wrong in the work sheet
>showing the two peaks.
>
>Jean
>
>
>
Jean,

I didn't see 'two peaks' - which sheet are we looking at.
I was looking at SpectrumAnalyser(2).mcd

Philip Oakley

We are looking at the same sheet, as there are 3 unexplainable peaks. Why did I say one peak ? No matter how you look at it, with or w/o noise (within reason), the digitized signal can't produce much different spectrum than a pure signal. Play with the noise level and get more confused. My model is correct but it should be calibrated vs the A/D converter installed as there are several kind of technologies for these gadgets and too many different kind of signals they take.

Maybe there are 3 peaks after all, but surely not so near equal. And in real life, nothing works that way and that simple, here is a typical A/D specification:

Resolution: 12 bits
A/D conversion accuracy: �0.025% of span (5 V DC)

jmG
PhilipOakley
5-Regular Member
(To:ptc-1368288)

Correct, there are three sine waves in the signal. The sampling is 'deliberately' not exact, as would happen with a real spectrum analyser (i.e. you can't always sample wher you want)

If yiou have a look at the start and end of the signal you should be able to see that (unfortunately) the sampling ends with both signals being positive, so the hoped for repetative continuity doesn't happen. The mean of the signal is hence positive and is the large lump of dBs at the left end of the frequency plot (it is on a log scale)

All the round off errors in the A/D sampling end up as all the remaining noise signals, again, being in dBs they 'show up' but are at least negative relative to the baseline of 1mV = 0 dB = 1 digital count.

You are right that in an ideal world the signals would be clean and pure, but Luc's sheet shows what happens when it isn't, which I think was the purpose.

Philip Oakley

You have too many good points Philip,

I don't understand the idea of not getting first the spectrum and deal with db after. The portion that you plug in Fourier is the "Fourier period", the spectrum comes out indexed, what is the purpose of plotting the spectrum indexes on log scale ? Further, the signal is a pure function with some degree of noise (user). But in reality there is little noise or negligible noise because all the converting devices between the very primary sensitive (capturing) device that converts the physics into signal ... the transmission, the readout before the A/D.

jmG
PhilipOakley
5-Regular Member
(To:ptc-1368288)

On 6/17/2009 12:37:31 PM, jmG wrote:
>You have too many good points
>Philip,
>
>I don't understand the idea of
>not getting first the spectrum
>and deal with db after. The
>portion that you plug in
>Fourier is the "Fourier
>period", the spectrum comes
>out indexed, what is the
>purpose of plotting the
>spectrum indexes on log scale
>? Further, the signal is a
>pure function with some degree
>of noise (user). But in
>reality there is little noise
>or negligible noise because
>all the converting devices
>between the very primary
>sensitive (capturing) device
>that converts the physics into
>signal ... the transmission,
>the readout before the A/D.
>
>jmG

Hi Jean,

You have picked up on a couple of the right points, but are possibley looking from the wrong side of the 'solution'. As you rightly say, it would be great if we could get the sample period to be an exact multiple of the signal periods, and if the analog to digital conversion had negligible noise. Unfortunately, Luc and others (and me sometimes) are stuck at the other end without the option of the exact period or 'perfect' (infinite precision) A/D converter.

So Luc's sheet shows what happens when we don't get our sample right. The main effects are actually the 'bad sampling' - I have just had to do one for an internal report showing that Fourier has the same 'problems' as Wavelets in respect of imperfect sampling.

The A/D noise will be low unless we change the number of bits to a low number e.g. 3, 5, 6, 7 etc. Even then the Fourier transform will still be pretty good (which is amazing really(*). The base noise can't get above +/-1/2 lsb peak so as an rms it is low.

The use of dB and a log scale are just because they are so common in electrical engineering. I'm sure part of the point of the simulation is to flag up a warning to other users of spectrum analysers as to the 'funny effects' that can be seen. [I tend to stick with lin-lin plots in mcd, so I can see what mcd sees]

Philip Oakley

(*) that ability to 'pull' the signal out of the very bad noise is similar to watching a snowy TV! [the things that digital USA will miss...]
Random noise of amplitude rms = 1/2lsb will average out to linear to better than a further 8 bits (i.e the mean level, after digitisation, will average to the true value to better than 1/256th of the digitisation bit)

Philip,

The large chunk at the left side of the (log scaled) plot is the DC component. It is moved to 1/10th of the lowest frequency, just for the purpose of being able to plot it along with the other frequencies on a log scale (Mathcad doesn't like 0 on a log scale, for good reasons).

Regards,
Luc
Top Tags