# Coherence between signals

**URL:** <https://discourse.julialang.org/t/coherence-between-signals/102772>\
**Category:** Signal and Image Processing\
**Tags:** question, dsp\
**Created:** [August 13, 2023, 4:19pm UTC](https://discourse.julialang.org/t/coherence-between-signals/102772 "2023-08-13T16:19:07Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [August 13, 2023, 4:19pm UTC](https://discourse.julialang.org/t/coherence-between-signals/102772/1 "2023-08-13T16:19:07Z")

</div>

I have two signals, lets call them U\_1 and U\_2. Both are time series of wind speeds, measured at different locations. They are more or less coherent. What I would like to know is how does the coherence between these signals depends on the frequency.

How can I calculate such a “coherence spectrum”?

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [August 13, 2023, 6:05pm UTC](https://discourse.julialang.org/t/coherence-between-signals/102772/2 "2023-08-13T18:05:48Z")

</div>

Take a look at DSP.jl [here](https://docs.juliadsp.org/latest/periodograms/#DSP.Periodograms.mt_cross_power_spectra).

---

<div class="post-metadata">

**Author:** ![joa-quim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joa-quim/32/227_2.png) [@joa-quim](https://discourse.julialang.org/u/joa-quim)\
**Post date:** [August 13, 2023, 6:22pm UTC](https://discourse.julialang.org/t/coherence-between-signals/102772/3 "2023-08-13T18:22:08Z")

</div>

GMT [example](https://docs.generic-mapping-tools.org/latest/gallery/ex03.html) not ported to GMT.jl but shouldn’t be difficult.

---

<div class="post-metadata">

**Author:** ![baggepinnen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/baggepinnen/32/693_2.png) [@baggepinnen](https://discourse.julialang.org/u/baggepinnen)\
**Post date:** [August 13, 2023, 7:02pm UTC](https://discourse.julialang.org/t/coherence-between-signals/102772/4 "2023-08-13T19:02:58Z")

</div>

See also the function `coherenceplot` used in this example [Frequency-domain estimation · ControlSystemIdentification Documentation](https://baggepinnen.github.io/ControlSystemIdentification.jl/dev/freq/#Nonparametric-estimation)

---

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [August 13, 2023, 7:13pm UTC](https://discourse.julialang.org/t/coherence-between-signals/102772/5 "2023-08-13T19:13:32Z")

</div>

Thanks!

What is the difference between a periodogram and a spectrum?

---

<div class="post-metadata">

**Author:** ![baggepinnen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/baggepinnen/32/693_2.png) [@baggepinnen](https://discourse.julialang.org/u/baggepinnen)\
**Post date:** [August 13, 2023, 7:17pm UTC](https://discourse.julialang.org/t/coherence-between-signals/102772/6 "2023-08-13T19:17:51Z")

</div>

> In signal processing, a periodogram is an estimate of the spectral density of a signal.

> **[Periodogram](https://en.m.wikipedia.org/wiki/Periodogram)**
>
> In signal processing, a periodogram is an estimate of the spectral density of a signal. The term was coined by Arthur Schuster in 1898. Today, the periodogram is a component of more sophisticated methods (see spectral estimation). It is the most common tool for examining the amplitude vs frequency characteristics of FIR filters and window functions. FFT spectrum analyzers are also implemented as a time-sequence of periodograms.
> There are at least two different definitions in use today. One of...

---

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [August 13, 2023, 7:36pm UTC](https://discourse.julialang.org/t/coherence-between-signals/102772/7 "2023-08-13T19:36:52Z")

</div>

Well, this text does not explain the difference between a spectrum and a periodogram. Perhaps it is the same?

---

<div class="post-metadata">

**Author:** ![baggepinnen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/baggepinnen/32/693_2.png) [@baggepinnen](https://discourse.julialang.org/u/baggepinnen)\
**Post date:** [August 13, 2023, 7:37pm UTC](https://discourse.julialang.org/t/coherence-between-signals/102772/8 "2023-08-13T19:37:43Z")

</div>

A periodigram is an estimate of the spectrum

---

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [August 13, 2023, 7:41pm UTC](https://discourse.julialang.org/t/coherence-between-signals/102772/9 "2023-08-13T19:41:03Z")

</div>

OK. Thank you.

---

<div class="post-metadata">

**Author:** ![Datseris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/datseris/32/13406_2.png) [@Datseris](https://discourse.julialang.org/u/Datseris)\
**Post date:** [August 14, 2023, 7:43am UTC](https://discourse.julialang.org/t/coherence-between-signals/102772/10 "2023-08-14T07:43:54Z")

</div>

they are the same thing @ufechner7 ; the difference is the x-axis. in the power spectrum you plot over frequency, in periodogram you plot over period, which is 1/frequency.

---

<div class="post-metadata">

**Author:** ![hagi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hagi/32/3678_2.png) [@hagi](https://discourse.julialang.org/u/hagi)\
**Post date:** [November 3, 2023, 9:24am UTC](https://discourse.julialang.org/t/coherence-between-signals/102772/11 "2023-11-03T09:24:42Z")

</div>

They are not the same. The periodogram is an estimation of the power spectral density (PSD), i.e. a statistical description of the signal. The spectrum is one specific realization of the PSD. Practically, the periodogram is calculated by averaging over several spectrum measurements.

---

<div class="post-metadata">

**Author:** ![Datseris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/datseris/32/13406_2.png) [@Datseris](https://discourse.julialang.org/u/Datseris)\
**Post date:** [November 3, 2023, 10:01am UTC](https://discourse.julialang.org/t/coherence-between-signals/102772/12 "2023-11-03T10:01:27Z")

</div>

can you define “spectrum” and “power spectral density”? Because in my background the words “power spectrum” and “power spectral density” mean exactly the same thing, yet in your post they mean different things.

---

<div class="post-metadata">

**Author:** ![Jake](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jake/32/46007_2.png) [@Jake](https://discourse.julialang.org/u/Jake)\
**Post date:** [November 3, 2023, 1:24pm UTC](https://discourse.julialang.org/t/coherence-between-signals/102772/13 "2023-11-03T13:24:52Z")

</div>

I have always had this nagging feeling that the terminology is somewhat dependent upon which discipline you come from. I come from the mechanical engineering, vibration testing part of the world. A good summary of the terminology used is given in Appendix A of [https://www.hpmemoryproject.org/an/pdf/an\_243.pdf](https://www.hpmemoryproject.org/an/pdf/an_243.pdf).  
When your excitation is narrow band, such as a rotating component of a machine, you want to display your signal as the sqrt(autopower spectrum). When your excitation is broad band, such as that caused by turbulence you want to use psd or its sqrt, as then the amplitude is independent of the frequency bin width. If your signal is completely contained within the time block that you are processing, such as a gun firing, then you want to display the signal as ESD.  
In my mental model, I think of spectrum as the result of an FFT, or more commonly as the sqrt(auto power spectrum).  
I have always been confused by the term periodogram so thanks for the clarification above.

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [November 3, 2023, 2:08pm UTC](https://discourse.julialang.org/t/coherence-between-signals/102772/14 "2023-11-03T14:08:05Z")

</div>

> [@Datseris](#):
>
> Because in my background the words “power spectrum” and “power spectral density” mean exactly the same thing,

[Wikipedia’s article on this topic](https://en.wikipedia.org/wiki/Spectral_density) seems to agree with you. See the paragraph “Power spectral density”.

---

<div class="post-metadata">

**Author:** ![joa-quim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joa-quim/32/227_2.png) [@joa-quim](https://discourse.julialang.org/u/joa-quim)\
**Post date:** [November 3, 2023, 2:09pm UTC](https://discourse.julialang.org/t/coherence-between-signals/102772/15 "2023-11-03T14:09:17Z")

</div>

GMT uses the Welch method to compute the periodogram. See this [old example](https://www.generic-mapping-tools.org/GMTjl_doc/gallery/ex03/) that is a bit more complicated than it needs but is _domain specific_. See [this in the spectrum1d](https://docs.generic-mapping-tools.org/dev/spectrum1d.html#tutorial) man page (not yet _translated_ to GMT.jl) for explanations
