# Is there a way to do "digital phosphor" type of plots for time series data?

**URL:** <https://discourse.julialang.org/t/is-there-a-way-to-do-digital-phosphor-type-of-plots-for-time-series-data/56490>\
**Category:** Visualization\
**Created:** [March 4, 2021, 6:11pm UTC](https://discourse.julialang.org/t/is-there-a-way-to-do-digital-phosphor-type-of-plots-for-time-series-data/56490 "2021-03-04T18:11:44Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![klaff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/klaff/32/7637_2.png) [@klaff](https://discourse.julialang.org/u/klaff)\
**Post date:** [March 4, 2021, 6:11pm UTC](https://discourse.julialang.org/t/is-there-a-way-to-do-digital-phosphor-type-of-plots-for-time-series-data/56490/1 "2021-03-04T18:11:44Z")

</div>

Modern (digital) oscilloscopes usually perform a simulation of a phosphor-based CRT. These are described by various terms like digital phosphor, intensity grading, color temperature display, etc.

These algorithms don’t simply draw a uniform intensity pixel at each point the waveform sweeps through but draw brighter pixels where the signal dwells or repeatedly visits, or use a color map to convey similar information. For waveforms with a lot more points than plot width and particularly for modulated waveforms this can give a much better depiction.

Does anyone know if this has been implemented somewhere in the Julia plotting universe?

---

<div class="post-metadata">

**Author:** ![mbaz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbaz/32/17295_2.png) [@mbaz](https://discourse.julialang.org/u/mbaz)\
**Post date:** [March 4, 2021, 6:29pm UTC](https://discourse.julialang.org/t/is-there-a-way-to-do-digital-phosphor-type-of-plots-for-time-series-data/56490/2 "2021-03-04T18:29:27Z")

</div>

This idea reminded me of [Persistence Spectrum in Signal Analyzer - MATLAB & Simulink](https://www.mathworks.com/help/signal/ug/persistence-spectrum-in-signal-analyzer.html)… it would indeed be awesome to have this capability.

---

<div class="post-metadata">

**Author:** ![yurivish](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yurivish/32/307_2.png) [@yurivish](https://discourse.julialang.org/u/yurivish)\
**Post date:** [March 4, 2021, 6:33pm UTC](https://discourse.julialang.org/t/is-there-a-way-to-do-digital-phosphor-type-of-plots-for-time-series-data/56490/3 "2021-03-04T18:33:23Z")

</div>

I implemented this idea a while ago based on this great post:

> **[Rendering PCM with simulated phosphor persistence](https://www.windytan.com/2013/03/rendering-pcm-with-simulated-phosphor.html)**
>
> A method for plotting nice-looking waveforms.

I’ve put my old notebook here: [windytan.ipynb · GitHub](https://gist.github.com/yurivish/de593a0f1daffd3c73340c9834610d6c)

Here’s a picture:

 ![fancy_resampling](https://global.discourse-cdn.com/julialang/original/3X/9/1/91fd21a949824b29f20ae2370ddfd4990af1856d.jpeg)

---

<div class="post-metadata">

**Author:** ![klaff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/klaff/32/7637_2.png) [@klaff](https://discourse.julialang.org/u/klaff)\
**Post date:** [March 4, 2021, 6:46pm UTC](https://discourse.julialang.org/t/is-there-a-way-to-do-digital-phosphor-type-of-plots-for-time-series-data/56490/4 "2021-03-04T18:46:38Z")

</div>

Very cool!, Thank you for sharing!

---

<div class="post-metadata">

**Author:** ![MA\_Laforge](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ma_laforge/32/385_2.png) [@MA\_Laforge](https://discourse.julialang.org/u/MA_Laforge)\
**Post date:** [March 4, 2021, 8:38pm UTC](https://discourse.julialang.org/t/is-there-a-way-to-do-digital-phosphor-type-of-plots-for-time-series-data/56490/5 "2021-03-04T20:38:30Z")

</div>

I don’t have other solutions regarding “digital phosphor” plots themselves, but I might have other tools you might want - and a possible home for the solution you might find/develop.

### Basic eye diagrams

I have implemented an algorithm to “fold” a time-domain waveform into multiple waveform sections in PhysicalCommunications.jl:  
 → [GitHub - JuliaTelecom/PhysicalCommunications.jl: Tools for development & test of PHY communication layer](https://github.com/JuliaTelecom/PhysicalCommunications.jl)

> There are also PRBS (LFSR) sequence generators in that module.

An eye diagram functionality is also built into the `CMDimData.EasyPlot` module made available through CMDimCircuits.jl:  
 → [GitHub - ma-laforge/CMDimCircuits.jl: Parametric analysis/visualization of model/measurement/simulation results](https://github.com/ma-laforge/CMDimCircuits.jl)

This version is particularly useful if you run parametric sweep simulations. (I should also try to consolidate the two implementations, but I haven’t put in the energy to find an adequate layering)

### A home for “digital phosphor” algorithms

If you eventually do implement this algorithm and wish to find a home for it, I think the JuliaTelecom group would be a good place to start looking:  
 → [GitHub - JuliaTelecom/PhysicalCommunications.jl: Tools for development & test of PHY communication layer](https://github.com/JuliaTelecom/PhysicalCommunications.jl)

If you think it is better housed somewhere else, that’s fine. But I would at least like to add it to our list of available tools found here:  
 → [GitHub - JuliaTelecom/JuliaTelecom: Greetings & telecom-related tools](https://github.com/JuliaTelecom/JuliaTelecom)

---

<div class="post-metadata">

**Author:** ![klaff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/klaff/32/7637_2.png) [@klaff](https://discourse.julialang.org/u/klaff)\
**Post date:** [March 4, 2021, 9:06pm UTC](https://discourse.julialang.org/t/is-there-a-way-to-do-digital-phosphor-type-of-plots-for-time-series-data/56490/6 "2021-03-04T21:06:11Z")

</div>

Thank you! I was poking around JuliaTelecom the other day - I have an RTL-SDR that I’ve played with for a couple of years and an RSP1A on the way just now and want to play with SDR in Julia eventually!

Regarding the phosphor emulation - I am thinking about using FFTResampling to upsample if necessary, forming a image in which each pixel location holds a count or dwell value, then mapping that to a color space. I previously figured out how to plot on an image using Plots.jl (for a chromaticity diagram) which would allow plotting of other things (e.g. results of math performed on the waveform) in the coordinate space of the data.

If I sweep a Gaussian spot, pick the right green, emulate misfocus and astigmatism, I should be able to get quite realistic old school scope effect. That’s taking it a bit farther than necessary but might be fun!

---

<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:** [March 4, 2021, 10:45pm UTC](https://discourse.julialang.org/t/is-there-a-way-to-do-digital-phosphor-type-of-plots-for-time-series-data/56490/7 "2021-03-04T22:45:42Z")

</div>

A simple digital phosphor oscilloscope:

```julia
using Plots; gr(bg=:black, legend=false)
N=1000; Nc=100; # number of points; number of curves
t = LinRange(0, 6, N)
y = [sin.(t .+ rand()/2) for i in 1:Nc]
p = plot() 
for i in 1:Nc
     plot!([t, t], [y[i], -y[i]], lc=:yellow,lw=2,la=2/Nc)
end
display(p)

```

 ![phosphor_oscilloscope](https://global.discourse-cdn.com/julialang/original/3X/d/6/d6f19bc1816ef3bc600bcc4493cd2d498020a483.png)

---

<div class="post-metadata">

**Author:** ![klaff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/klaff/32/7637_2.png) [@klaff](https://discourse.julialang.org/u/klaff)\
**Post date:** [March 4, 2021, 10:57pm UTC](https://discourse.julialang.org/t/is-there-a-way-to-do-digital-phosphor-type-of-plots-for-time-series-data/56490/8 "2021-03-04T22:57:42Z")

</div>

That’s cool and I would say you’re emulating persistence!

Edit: Your trigger is not very stable! 😀

---

<div class="post-metadata">

**Author:** ![klaff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/klaff/32/7637_2.png) [@klaff](https://discourse.julialang.org/u/klaff)\
**Post date:** [March 4, 2021, 11:06pm UTC](https://discourse.julialang.org/t/is-there-a-way-to-do-digital-phosphor-type-of-plots-for-time-series-data/56490/9 "2021-03-04T23:06:10Z")

</div>

Here’s what I did:

```julia
using Colors
using ImageIO
using ImageShow
using Plots

signal(t) = (1.0+0.75*sinpi(2*1000*t))*cospi(2*1.12e6*t)

begin
	xres = 600
	yres = 256
	counts = zeros(yres,xres)
	Nsamples = 1_000_000
	Ts = 2e-9
	tfinal = (Nsamples-1)*Ts
	tpixel = (tfinal+Ts)/xres
	nbits=8
	Vdiv = 0.5
	Vquant = 8*Vdiv/2^nbits
	sampled_signal = Int.(2^(nbits-1) .+ round.(signal.(0.0:Ts:tfinal)/Vquant))
	for i in 1:Nsamples
		t = i*Ts
		x = min(xres,Int(t÷tpixel)+1)
		counts[sampled_signal[i],x] += 1
	end
	counts = Int.(round.(counts./(maximum(counts)/255)).+1)
	cmap = reverse(colormap("Greens",256; logscale=true))
	img = map(c->cmap[c], counts)
end

```

which gives  
 ![image](https://global.discourse-cdn.com/julialang/original/3X/6/5/65f8b492c93a7d137cadc65833a1f9271444d9f8.png)

---

<div class="post-metadata">

**Author:** ![jheinen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jheinen/32/2787_2.png) [@jheinen](https://discourse.julialang.org/u/jheinen)\
**Post date:** [March 5, 2021, 8:47am UTC](https://discourse.julialang.org/t/is-there-a-way-to-do-digital-phosphor-type-of-plots-for-time-series-data/56490/10 "2021-03-05T08:47:16Z")

</div>

You can also use the shading capabilities of GR:

```julia
using WAV
using GR

file = joinpath(dirname(Base.find_package("GR")), "..", "examples", "Monty_Python.wav")
y, fs = WAV.wavread(file)

shade(y, colormap=-GR.COLORMAP_BLUESCALE, ylim=(-1,1))

```

Could also be read with `FileIO`, but seems to be buggy (see [!307](https://github.com/JuliaIO/FileIO.jl/issues/307)).

 ![Screen Shot 2021-03-05 at 09.44.25](https://global.discourse-cdn.com/julialang/original/3X/3/3/33164de44c674111552695e59b348df216d9357b.jpeg)

---

<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:** [March 5, 2021, 11:30am UTC](https://discourse.julialang.org/t/is-there-a-way-to-do-digital-phosphor-type-of-plots-for-time-series-data/56490/11 "2021-03-05T11:30:22Z")

</div>

@jheinen, is it possible to set a black background in `GR.shade`?  
_PS: very nice example with a “cerise sur le gâteau” (Monty Python’s song)_

---

<div class="post-metadata">

**Author:** ![jheinen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jheinen/32/2787_2.png) [@jheinen](https://discourse.julialang.org/u/jheinen)\
**Post date:** [March 5, 2021, 11:49am UTC](https://discourse.julialang.org/t/is-there-a-way-to-do-digital-phosphor-type-of-plots-for-time-series-data/56490/12 "2021-03-05T11:49:23Z")

</div>

> [@jheinen](#):
>
> ```julia
> using WAV
> using GR
> 
> file = joinpath(dirname(Base.find_package("GR")), "..", "examples", "Monty_Python.wav")
> y, fs = WAV.wavread(file)
> 
> shade(y, colormap=-GR.COLORMAP_BLUESCALE, ylim=(-1,1))
> 
> ```

Sure, you simply have to change the color scheme (`usecolorscheme(2)`) and remove the minus sign for the colormap:

 ![Screenshot 2021-03-05 at 12.48.19](https://global.discourse-cdn.com/julialang/original/3X/2/3/23736584092dc75e43e56fc5e43ca8f1af0bd21f.png)

---

<div class="post-metadata">

**Author:** ![jheinen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jheinen/32/2787_2.png) [@jheinen](https://discourse.julialang.org/u/jheinen)\
**Post date:** [March 5, 2021, 11:52am UTC](https://discourse.julialang.org/t/is-there-a-way-to-do-digital-phosphor-type-of-plots-for-time-series-data/56490/13 "2021-03-05T11:52:24Z")

</div>

Looks much better with huge wave files:

 ![Screenshot 2021-03-05 at 12.51.24](https://global.discourse-cdn.com/julialang/original/3X/1/3/13c1dc43f6d815e84bb7e6f6df8a29143d51c8ef.png)

---

<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:** [March 5, 2021, 12:01pm UTC](https://discourse.julialang.org/t/is-there-a-way-to-do-digital-phosphor-type-of-plots-for-time-series-data/56490/14 "2021-03-05T12:01:52Z")

</div>

@jheinen, this is brilliant.

---

<div class="post-metadata">

**Author:** ![jheinen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jheinen/32/2787_2.png) [@jheinen](https://discourse.julialang.org/u/jheinen)\
**Post date:** [March 5, 2021, 12:08pm UTC](https://discourse.julialang.org/t/is-there-a-way-to-do-digital-phosphor-type-of-plots-for-time-series-data/56490/15 "2021-03-05T12:08:23Z")

</div>

But it takes longer to read the file (~5.7s) than to display it (~1.1s) …

```julia
julia> version()
"0.55.0.post17"

julia> versioninfo()
Julia Version 1.5.3
Commit 788b2c77c1 (2020-11-09 13:37 UTC)
Platform Info:
  OS: macOS (x86_64-apple-darwin18.7.0)
  CPU: Intel(R) Core(TM) i9-10910 CPU @ 3.60GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-9.0.1 (ORCJIT, skylake)
Environment:
  JULIA_DEPOT_PATH = /usr/local/lib/julia:
  JULIA_NUM_THREADS = 10
  JULIA_HISTORY = /Users/jheinen/.julia/logs/repl_history.jl

  5.702187 seconds (138.76 M allocations: 3.156 GiB, 7.05% gc time)
  1.137098 seconds (344 allocations: 893.807 MiB, 1.43% gc time)

julia> 

```

---

<div class="post-metadata">

**Author:** ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)\
**Post date:** [March 5, 2021, 2:41pm UTC](https://discourse.julialang.org/t/is-there-a-way-to-do-digital-phosphor-type-of-plots-for-time-series-data/56490/16 "2021-03-05T14:41:53Z")

</div>

I’m late to the party, but these excellent visualizations make me want to recreate the “oscilloscope music” from [Jerobeam Fenderson - Blocks - YouTube](https://www.youtube.com/watch?v=0KDekS4YUy4) in a more accurate style. I wrote a very simple wav → video converter here: [Oscilloscope Music ←](http://blog.robindeits.com/2020/06/07/oscilloscope-music/#Code) but my persistence implementation was pretty basic.

---

<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:** [March 6, 2021, 11:50am UTC](https://discourse.julialang.org/t/is-there-a-way-to-do-digital-phosphor-type-of-plots-for-time-series-data/56490/17 "2021-03-06T11:50:04Z")

</div>

@klaff, yes it is a very cheap model and with only one setting: `persistence = +∞`  
😅
