Engee documentation

spectralSkewness

Spectral asymmetry of signals and spectrograms.

Library

EngeeDSP

Syntax

Function call

  • skewness,spread,centroid = spectralSkewness(x,f) — returns the spectral asymmetry of the signal x over time. It also returns the spectral extent and spectral centroid. Interpretation x the function depends on the form f.

  • spectralSkewness(___;out=:plot) — plots spectral asymmetry.

    • If the input signal is in the time domain, the spectral asymmetry graph is plotted as a function of time.

    • If the input signal is in the frequency domain, the spectral asymmetry graph is plotted depending on the frame number.

Arguments

Input arguments

# x — input signal

+ column vector | the matrix

Details

An input signal specified as a vector or matrix. Interpretation x the function depends on the form f.

Типы данных

Float32, Float64

# f is the sampling frequency or frequency vector (Hz)

+ scalar | vector

Details

The sampling frequency or frequency vector in Hz, specified as a scalar or vector, respectively. Interpretation x the function depends on the form f:

  • If f — scalar, x it is interpreted as a signal in the time domain, and f — as a sampling rate. In this case x must be a real vector or a matrix. If x set as a matrix, the columns are interpreted as separate channels.

  • If f — vector, x it is interpreted as a signal in the frequency domain, and f — how are the frequencies in Hz corresponding to the strings x. In this case x must be a real array of size , where — the number of spectral values at the specified frequencies f, — the number of individual spectra, and — the number of channels.

  • Number of lines x, , must be equal to the number of elements f.

Типы данных

Float32, Float64

Name-value input arguments

Specify optional argument pairs as Name,Value, where Name — the name of the argument, and Value — the appropriate value. Name-value arguments should be placed after other arguments, but the order of the pairs does not matter.

Use commas to separate the name and value, and Name put it in quotation marks.

The following name-value arguments apply if x — a signal in the time domain. If x — a signal in the frequency domain, arguments of the "name-value" type are ignored.

# Window — the window used in the time domain

+ rectwin(round(f*0.03)) (default) | vector

Details

The window used in the time domain, defined as a real vector. The number of vector elements must be in the range [1,size(x,1)]. The number of vector elements must also be greater. OverlapLength.

Типы данных

Float32, Float64

# OverlapLength — the number of samples overlapping between adjacent windows

+ round(f*0.02) (by default) | a non-negative scalar

Details

The number of samples overlapping between adjacent windows, set as an integer in the range [0,size(Window,1)).

Типы данных

Float32, Float64

# FFTLength — the number of elements in the DFT

+ numel(Window) (by default) | a positive integer scalar

Details

The number of elements used to calculate the DFT of window input samples, set as a positive integer scalar. If no argument is given, FFTLength by default, it is equal to the number of elements in Window.

Типы данных

Float32, Float64

# Range — frequency range (Hz)

+ [0,f/2] (by default) | A two-element vector is a string

Details

The frequency range in Hz, defined as a two-element vector, is a string of increasing real values in the range [0,f/2].

Типы данных

Float32, Float64

# SpectrumType — spectrum type

+ "power" (by default) | "magnitude"

Details

The type of spectrum specified as "power" or "magnitude":

  • "power" — spectral asymmetry is calculated for a one-sided power spectrum;

  • "magnitude" — spectral asymmetry is calculated for a one-sided amplitude spectrum.

Типы данных

String

# out — type of output data

+ :data (by default) | :plot

Details

Type of output data:

  • :data — the function returns data;

  • :plot — the function returns a graph.

Output arguments

# skewness — spectral asymmetry

+ scalar | vector | the matrix

Details

Spectral asymmetry, returned as a scalar, vector, or matrix. Each line skewness corresponds to the spectral asymmetry of the window x. Each column skewness corresponds to an independent channel.

# spread — spectral length

+ scalar | vector | the matrix

Details

The spectral length returned as a scalar, vector, or matrix. Each line spread corresponds to the spectral extent of the window x. Each column spread corresponds to an independent channel.

# centroid — spectral centroid

+ scalar | vector | the matrix

Details

The spectral centroid returned as a scalar, vector, or matrix. Each line centroid corresponds to the spectral centroid of the window x. Each column centroid corresponds to an independent channel.

Examples

Spectral asymmetry of the signal in the time domain

Details

Let’s create an FM signal with white Gaussian noise and calculate the asymmetry using the default parameters.

import EngeeDSP.Functions: chirp, randn, spectralSkewness

fs = 1000
t = (0:1/fs:10)
f1 = 300
f2 = 400
x = chirp(t, f1, 10, f2) + randn(length(t), 1)

skewness = spectralSkewness(x, fs)

Let’s plot the dependence of spectral asymmetry on time.

spectralSkewness(x, fs, out=:plot)

spectralSkewness 1

([-0.41584882984851185, -0.5170941305241857, -0.564347048766862, -0.20108069594499398, 0.3892427522273517, 0.1463327742296114, -0.0959324772116146, -0.4664806868967973, -0.3923963888464158, 0.01796837401846083  …  -0.853109771702925, -1.0019652539560882, -1.7630883535558604, -1.3928510876449312, -1.4782180105459737, -1.1673132825372987, -1.3108237989573261, -1.2622253537332102, -1.1392100073297082, -0.9096598411870619], [137.66250718402654, 127.45803470472126, 128.62674026296034, 129.186501587399, 127.21238231874466, 135.27228568052246, 114.29332508288279, 113.20360160889103, 129.60154758930983, 137.04900834348766  …  113.02519942099786, 138.35361563650906, 110.54777802801922, 115.82292236038828, 113.2157408305658, 124.01480122917285, 126.18012726969127, 136.32543128218506, 152.2965330188322, 151.53661288017915], [232.54635888820377, 244.52603810295574, 263.6019775735153, 271.04043285763873, 267.14685957025756, 275.70362962545187, 270.28792339138397, 255.93688502474646, 268.74572871366905, 274.7291310293522  …  320.08685981196544, 317.87764929627133, 349.6998379422504, 332.2649969853749, 344.80178074508837, 339.5576123782947, 326.9848093500554, 318.2941806082642, 311.10184808692037, 296.1414058613318], Plot{Plots.PlotlyJSBackend() n=1})

Spectral asymmetry of the signal in the frequency domain

Details

Let’s create an LFM signal with white Gaussian noise, and then calculate the spectrogram using the function stft.

import EngeeDSP.Functions: chirp, randn, stft

fs = 1000
t = (0:1/fs:10)'
f1 = 300
f2 = 400
x = chirp(t, f1, 10, f2) + randn(size(t)...)

s, f = stft(x, fs, "FrequencyRange", "onesided")
s = abs.(s).^2

Calculate the asymmetry of the spectrogram over time.

import EngeeDSP.Functions: spectralSkewness

skewness = spectralSkewness(s, f)

Let’s plot the dependence of the spectral asymmetry on the frame number.

spectralSkewness(s, f, out=:plot)

spectralSkewness 2

([-0.8359982931981216, -0.5281233777476992, -0.19003913028541924, -0.20010790649073676, -0.4518215729934591, -0.609505728606324, -0.35104046557619795, -0.44243240701247855, -0.5058598909702079, -0.24334848229314177  …  -0.7652817638675459, -0.29454858120347277, -1.0382786281369654, -0.9085777404108826, -0.3647202399233729, -0.4806516533252003, -0.025478934806172537, -0.3634101240910118, -0.2187538302761354, -0.34903020983974686], [107.17221169316268, 108.08710344363071, 121.73703765712227, 127.2733133823049, 113.45452035995662, 101.935212957374, 118.00182469240174, 132.80689180278688, 115.59164488540159, 103.25800480469758  …  130.74712793061693, 140.8136649111479, 120.8114483851076, 126.27406132641096, 143.9703528142779, 132.1095322961261, 137.9399485601707, 131.12441824862063, 144.70449053384257, 164.38033907467928], [292.7910624802788, 275.40970236507655, 244.1866329141813, 254.4473178753846, 253.6161996745867, 275.82905121269937, 272.98722964342187, 226.80470629232215, 236.10533279943394, 239.64514680772058  …  321.87682998876653, 278.83384299634093, 314.86016584163775, 305.56640901528647, 280.8820142043897, 288.72754980225983, 261.32008807500637, 273.0967688666202, 243.65572527972142, 256.13120365040834], Plot{Plots.PlotlyJSBackend() n=1})

Specifying parameters other than the standard ones

Details

Let’s create an FM signal with white Gaussian noise.

import EngeeDSP.Functions: chirp, randn

fs = 1000
t = (0:1/fs:10)
f1 = 300
f2 = 400
x = chirp(t, f1, 10, f2) + randn(length(t), 1)

Let’s calculate the asymmetry of the power spectrum over time. Calculate the asymmetry for Hamming windows with a duration of 50 ms with overlap 25 ms. We use the range from 62.5 Hz to fs/2 to calculate the asymmetry.

import EngeeDSP.Functions: spectralSkewness, hamming

skewness = spectralSkewness(x, fs,
                      "Window", hamming(round(Int, 0.05*fs)),
                      "OverlapLength", round(Int, 0.025*fs),
                      "Range", [62.5, fs/2])

Let’s plot the dependence of the asymmetry on time.

spectralSkewness(x, fs,
              "Window", hamming(round(Int, 0.05*fs)),
              "OverlapLength", round(Int, 0.025*fs),
              "Range", [62.5, fs/2],
              out=:plot)

spectralSkewness 3

([-0.15358670202573538, -0.10674901633061454, -1.1800361499235466, -0.004310190890005931, -0.6333699707463635, -0.23684625667693265, -0.43005228049825217, -0.8150523711899812, 0.03350102205262587, -0.41422126904743767  …  -0.005625970564356666, -0.6911434383476336, -1.3456964659853543, -1.710416093386148, -0.7442772354709529, 0.17283689627442853, -1.180419434083617, -1.440520104825559, -1.2583907091166355, -1.2842556849576383], [110.53667066154323, 81.12551758487213, 76.00441845155343, 97.84638979421082, 73.30917024731693, 106.73269627867673, 86.62588932286765, 96.51841858083655, 103.85455951559621, 81.25600340707545  …  130.74893548874454, 125.17411282084814, 105.79471192625837, 82.20506434500429, 112.9987914008663, 118.82027872700775, 91.5641846600464, 86.79996258356996, 97.9073613532983, 97.76881671452485], [288.3573645373158, 301.453120754697, 281.81310005697344, 266.79710402702926, 294.40582264869937, 251.81256307415043, 296.03366939785593, 326.86271852855765, 268.5491461338446, 302.8114318001578  …  265.2072744080883, 317.3863334548424, 333.8375132973837, 354.45727064830913, 338.77406994099954, 266.7769262524174, 342.5369659108678, 348.9119484862638, 341.65454501607263, 342.4239901408415], Plot{Plots.PlotlyJSBackend() n=1})

Algorithms

The spectral asymmetry is calculated as described in [1]:

where

  • — the frequency in Hz corresponding to the bin ;

  • — spectral value in bin ;

  • and — band boundaries in bins, which are used to calculate spectral asymmetry;

  • — spectral centroid;

  • — spectral extent.

Literature

  1. Peeters, G. «A Large Set of Audio Features for Sound Description (Similarity and Classification) in the CUIDADO Project.» Technical Report; IRCAM: Paris, France, 2004.