Engee documentation

EngeeDSP.spectrumAnalyzer

Creates a spectrum analyzer object.

Library

EngeeDSP

Description

An object EngeeDSP.spectrumAnalyzer displays the frequency spectrum of the signals in the time domain. The spectrum analyzer represents the frequency spectrum in the form of a spectrum or a spectrogram. The object performs the spectrum calculation using the filter bank method and the method of averaged modified Welch periodograms. For more information, see Algorithms. The spectrum analyzer can display the signal power spectrum in three units: W, dBm and dBW. For more information about power conversion between these three units, see Transfer of power from one unit of measurement to another.

To create a spectrum analyzer object, follow these steps:

  1. Create an object EngeeDSP.spectrumAnalyzer and set its properties.

  2. Call the object with arguments as if it were a function.

To learn more about how to work with system objects, see Engee System Objects.

Syntax

Creation

scope = EngeeDSP.spectrumAnalyzer(name = value) — creates a system object EngeeDSP.spectrumAnalyzer with the specified properties as a pair Name=Value, where Name — the name of the property, and Value — the appropriate value. You can specify multiple pairs «name-value» the order of the pairs does not matter. Unspecified properties retain their default values.

Using

  • scope(signal) — displays the frequency spectrum of the input signal signal in the time domain in the spectrum analyzer.

    scope(signal)
  • scope(signal1,signal2,…​,signalN) — displays the frequency spectrum of multiple input signals signal1,signal2,…​,signalN in the time domain in the spectrum analyzer. Each signal is interpreted as a separate channel.

    scope(signal1,signal2,signal3)

Arguments

Input arguments

signal — input signal

+ scalar | vector | the matrix

Details

An input signal or visualization signals specified as a scalar, vector, or matrix. The number of channels in each signal can be different, but the frame size of each signal must be the same.

Типы данных

Float64, Float32, Int8, Int16, Int32, Int64, UInt8, UInt16, UInt32, UInt64

Support for complex numbers

Yes

Features

None.

Methods

Common to all system objects

step!

The calculation step. Returns an object CairoMakie.Figure. You can call it in two ways:

  • direct challenge: step!(scope, args…​);

  • calling via a functor: scope(args…​).

release!

Allow changing the value of a system object property.

Specific to EngeeDSP.spectrumAnalyzer

setup!

Called at the first step, can be called directly: step!(scope, args…​).

display

Re-draw the graph.

getSpectrumData

Return the dictionary with the last displayed data. Possible keys:

  • "spectrum";

  • "spectrogram";

  • "frequencies";

  • "times".

Examples

A spectrum analyzer for a single-sided power spectrum

Details

Creating an object EngeeDSP.spectrumAnalyzer and set its properties.

import EngeeDSP:spectrumAnalyzer

Fs = 100e6

scope = spectrumAnalyzer(SampleRate=Fs,AveragingMethod="exponential",PlotAsTwoSidedSpectrum=false,RBWSource="auto",SpectrumUnits="dBW")
spectrumAnalyzer(
	SpectrumType = "power"
	ViewType = "spectrum"
	Method = "filter-bank"
	SpectrumUnits = "dBW"
	ReferenceLoad = 1
	FullScaleSource = "auto"
	FullScale = 1
	OverlapPercent = 0
	FrequencyResolutionMethod = "rbw"
	WindowLength = 1024
	RBWSource = "auto"
	RBW = 9.76
	FFTLengthSource = "auto"
	FFTLength = 1024
	SampleRate = 1.0e8
	Window = "Hann"
	SidelobeAttenuation = 60
	FrequencyOffset = 0
	FrequencySpan = "full"
	Span = 10000.0
	CenterFrequency = 0
	StartFrequency = -5000.0
	StopFrequency = 5000.0
	PlotAsTwoSidedSpectrum = false
	AveragingMethod = "exponential"
	ForgettingFactor = 0.9
	VBWSource = "auto"
	VBW = 10
	SpectrogramChannel = 1
	TimeResolutionSource = "auto"
	TimeResolution = 0.001
	TimeSpanSource = "auto"
	TimeSpan = 0.1
	Size = (800, 500)
	Title = ""
	YLabel = ""
	YLimits = "auto"
	AxesLayout = "vertical"
	ShowColorbar = true
	ShowGrid = true
	Colormap = "jet"
	ShowLegend = false
	ColorLimits = "auto"
	LineWidth = 1.5
	LineStyle = "-"
	FrequencyScale = "linear"
	ChannelNames = String[]
)

Let’s draw a one-sided power spectrum created from the sum of fixed real sinusoids with different amplitudes and frequencies.

fSz = 5000
t = (0:fSz-1)/Fs

sin1 = sin.(2π * 5e6 * t)
sin2 = 1e-1 * sin.(2π * 15e6 * t)
sin3 = 1e-2 * sin.(2π * 25e6 * t)
sin4 = 1e-3 * sin.(2π * 35e6 * t)
sin5 = 1e-4 * sin.(2π * 45e6 * t)

for idx in 1:250
    y_total = sin1 + sin2 + sin3 + sin4 + sin5 + 0.0001 * randn(fSz)
    scope(y_total)
end

scope |> display

release!(scope)

spectrumanalyzer 1

Additional Info

Transfer of power from one unit of measurement to another

Details

The spectrum analyzer provides three units for measuring spectral power density: W/Hz, dBm/Hz and dBW/Hz. The corresponding units of power measurement are W, dBm, and dBW. In electrical applications, you can also view the RMS value of a signal in V (RMS value), DBMQ, or dBV. The default spectrum type is the power in dBm.

transfer power from Watts to dBW and dBm

The power in dBW is determined by the formula:

The power in dBm is determined by the formula:

For a sinusoidal signal with an amplitude of 1 The power of the one-sided spectrum in Watts is determined by the formula:



The corresponding power in dBm is calculated using the formula:





For a white noise signal, the spectrum is flat for all frequencies. Consider a white noise signal with variance 1e-4. Thus, the power per unit of bandwidth ( ) is equal to 1e-4. For a one-way spectrum in the range the total white noise power in watts is determined by the formula:



where

  • — this is the sampling frequency of the input signal;

  • is the ratio of total bandwidth to bandwidth resolution ( ).

For a one-way spectrum, the total bandwidth is half the sampling frequency. Consider the sampling rate 44100 Hz and bandwidth resolution 21.53 Hz. At these values, the total white noise power in Watts is 0.1024 Tue.

The white noise power in dBm can be calculated using the formula:



transfer power from W to dB of full scale

If you set the spectral units to dBFS and the full scale ([Property:FullScaleSource]) to the mode "auto", then the power in dBFS it will be calculated as follows:

where

  • — power in watts;

  • for double precision and floating point signals — this is the maximum value of the input signal;

  • for fixed-point or integer signals — this is the maximum value that can be represented.

If you set the full scale ([Property:FullScaleSource]) to the mode "property", then the power in dBFS it will be calculated as follows:

where — property value [Property:FullScale].

For a sinusoidal signal with an amplitude of 1 The power of the one-way spectrum in Watts is determined by the formula:



The corresponding power in dB of full scale is calculated using the formula:



transfer power from dBm to RMS value in

The power in dBm is determined by the formula:

The voltage (RMS value) is calculated using the formula:

In the previous example equal to 26.9897 dBm. Meaning calculated as:

Algorithms

Spectrum Calculation — filter bank

Details

If for [Property:Method] set the value "filter-bank" then the spectrum analyzer will use a filter bank to calculate the power spectrum.

The filter bank separates the broadband input signal with sampling rate for multiple narrowband signals with sampling rate .

Variable represents the number of frequency bands in the filter bank. In the spectrum analyzer is equal to the number of data points required to achieve the specified resolution band value (RBW) or 1024, depending on which value is greater.

After the spectrum analyzer divides the broadband input signal into several narrow bands, it calculates the power in each narrow frequency band using the following equation:

where is each value it is a calculation of power in a narrow frequency band, and — the length of the narrowband signal for .

Power values in all narrow frequency bands (denoted by ) form a vector :

The spectrum analyzer averages the current vector with previous vectors using one of the sliding averaging methods: over the video band or exponential weighting. The result of the averaging operation forms a vector for calculating the spectrum. For more information about averaging methods, see The averaging method.

spectrumanalyzer 2

The spectrum analyzer uses the RBW value (Hz) or the number of frequency bands to determine the length of the input frame.

If specified [Property:FrequencyResolutionMethod] = "rbw", and for [Property:RBWSource] the value is set:

  • "auto" — The spectrum analyzer determines the appropriate resolution band to ensure the presence of 1024 bandwidth resolution intervals in a given frequency range. In this case, the spectrum analyzer calculates RBW using the formula:

  • "property" — the spectrum analyzer calculates the number of samples using the formula:

    where

    • — the sampling frequency of the input signal, set by the property [Property:SampleRate] in Hz;

    • — specified in [Property:RBW] The value of the resolution band must be such that there are at least two RBW intervals in the specified frequency range. The ratio of the total range to RBW must be greater than two:

      ;

    • — the range in which the spectrum analyzer calculates and plots the spectrum.

If specified [Property:FrequencyResolutionMethod] = "num-frequency-bands", then the resulting resolution bandwidth will be:

Spectrum calculation — the Welch method

Details

If for [Property:Method] set the value "welch", then the calculation of the power spectrum is an averaged modified periodogram.

The algorithm of the spectrum analyzer consists of the following steps:

  1. Buffers the input data into data segments consisting of points. Each data segment is divided into overlapping data segments, each with a length of , overlapping on points. The data segments can be represented as follows:

    • If , then the overlap is 50%.

    • If , then the overlap is 0%.

  2. Applies a window to each of the overlapping data segments in the time domain.

    If as a resolution method [Property:FrequencyResolutionMethod] value selected "window-length", then you can specify the length of the data window using the property [Property:WindowLength].

    If as a resolution method [Property:FrequencyResolutionMethod] value selected "rbw", then the algorithm determines the length of the data window using the following equation: .

    It then splits the input signal into several data segments processed using the window.

    Most window functions have a greater impact on the data in the center of the segment than on the data at the edges, resulting in information loss. To reduce this loss, individual data segments are usually overlapped in time. For each segment processed using the window, a periodogram is calculated by calculating the discrete Fourier transform. Then the square of the modulus of the result is calculated and divided by :

    where is the normalization factor for the power in the window function and is defined as:

    The window can be set in the property [Property:Window].

  3. The spectrum analyzer calculates and plots the power spectrum, power spectral density, and RMS value using a modified periodogram calculation method.

    To determine the calculation of the power spectrum for the Welch method, the spectrum analyzer averages the results of the periodograms for the latter data segments. Averaging reduces the variance compared to the original one -a point segment of data. For more information about averaging methods, see The averaging method.

    • The spectrum analyzer calculates the spectral power density using:

    • The power spectrum is the product of the spectral power density and the resolution band:

    • The spectrum analyzer displays the power in the form of a spectrogram in the mode "spectrogram". Each line of the spectrogram represents a periodogram. The time resolution of each line is , which is the minimum achievable resolution. To achieve the required resolution, it may be necessary to combine several periodograms. Then, using interpolation, non-integer values are calculated. . On the spectrogram screen, time scrolls from top to bottom, so the most recent data is displayed at the top of the screen. The offset shows the time at which the center of the most recent line of the spectrogram was located.

The spectrum analyzer uses a certain number of samples to calculate the spectrum. This value is directly related to the resolution band ( ) using the following equation:

or with the length of the window ( ) using the equation:

where

If as a resolution method [Property:FrequencyResolutionMethod] value selected "rbw", then the window length is determined by the formula:

If as a resolution method [Property:FrequencyResolutionMethod] value selected "window-length" the algorithm uses the window length value specified in the property [Property:WindowLength].

Percentage of overlap (Op)

Details

Percentage of overlap — this is the value specified in the property [Property:OverlapPercent].

As the percentage of overlap increases, the spectrum analyzer requires fewer new input samples to calculate a new spectral update.

0%

100

50%

50

80%

20

Normalized Effective Noise Bandwidth (NENBW)

Details

Normalized Effective Noise Bandwidth, ) is a window parameter that measures the noise characteristics of the window. Meaning It is determined using the window length and its coefficients and is given by the following equation:

where denotes the vector of window coefficients, and — the length of the window. For more information about how the algorithm determines the window length, see Spectrum calculation — the Welch method.

The lowest value has a rectangular window equal to 1. All other windows are more important. . For example, the Hanna window has a value approximately 1.5.

Resolution Band (RBW)

Details

Resolution Band controls the spectral resolution of the displayed signal. Meaning defines the interval between the frequencies that the spectrum analyzer can resolve. A lower value provides higher spectral resolution and reduces noise levels, meaning the spectrum analyzer can resolve frequencies located closer to each other. However, this leads to an increase in the scan time.

The resolution band can be set using the property [Property:RBW] in Hz.

If specified [Property:FrequencyResolutionMethod] = "rbw", and for [Property:RBWSource] the value is set:

  • "auto" — the spectrum analyzer determines the appropriate resolution band to ensure the presence of 1024 bandwidth resolution intervals in a given frequency range. In this case, the spectrum analyzer calculates RBW using the formula:

  • "property" — the spectrum analyzer calculates the number of samples using the formula:

    where

    • — the sampling frequency of the input signal, set by the property [Property:SampleRate] in Hz;

    • — specified in [Property:RBW] The value of the resolution band must be such that there are at least two RBW intervals in the specified frequency range. The ratio of the total range to RBW should be more than two:

      ;

    • — the range in which the spectrum analyzer calculates and plots the spectrum.

If specified [Property:FrequencyResolutionMethod] = "num-frequency-bands", then the resulting resolution bandwidth will be:

Nyquist frequency range

Details

When constructing a two-way spectrum, when [Property:PlotAsTwoSidedSpectrum] = true, the Nyquist frequency range is in Hz.

When [Property:PlotAsTwoSidedSpectrum] = false Nyquist frequency range in Hz.

The averaging method

Details

The spectrum analyzer calculates a moving average using one of the following methods:

  • The video band spectrum analyzer uses a low—pass filter in the time domain to smooth out noise in the signal. Video Band Filter ( ) smooths the curve and reduces noise, and the spectrum analyzer applies this filter to the data before displaying it.

    The video band is the bandwidth of a low—pass filter that a spectrum analyzer uses to average or smooth out noise in a signal before displaying it. The spectrum analyzer calculates the video band using the following formula:

    where

    • — the coefficient of forgetting;

    • — resolution band, for more information, see Resolution Band (RBW);

    • — normalized effective noise bandwidth, for more information, see Normalized Effective Noise Bandwidth (NENBW).

      The video band does not affect the noise level (noise threshold), but only increases the signal-to-noise ratio and smoothes the noise curve. When decreasing the value The signal-to-noise ratio is improving.

      The cutoff frequency of the video band filter is determined by the formula:

      where

    • — sampling rate of the input signal;

    • — the number of FFT points.

  • Exponential — The moving average algorithm uses exponential weighting to update the weights and recursively calculate the moving average for each incoming vector. using the following recursive equations:



    where

    • — the coefficient of forgetting;

    • — the weight factor applied to the current vector ;

    • — current vector ;

    • — the moving average up to the previous vector ;

    • — the influence of previous vectors on average;

    • — a moving average that includes the current vector .