# Reading EDFs in Julia preserving floating point values

**URL:** https://discourse.julialang.org/t/reading-edfs-in-julia-preserving-floating-point-values/112911
**Category:** General Usage
**Tags:** question, package
**Created:** [April 13, 2024, 5:01pm UTC](https://discourse.julialang.org/t/reading-edfs-in-julia-preserving-floating-point-values/112911 "2024-04-13T17:01:05Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Santiago\_Lopez](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/santiago_lopez/32/46298_2.png) [@Santiago\_Lopez](https://discourse.julialang.org/u/Santiago_Lopez)
#### Post date: [April 13, 2024, 5:01pm UTC](https://discourse.julialang.org/t/reading-edfs-in-julia-preserving-floating-point-values/112911/1 "2024-04-13T17:01:05Z")

</div>

The EDF.jl currently has a limitation; namely, that it automatically converts signals into integers. This is exlicitly stated in the [official documentation:] ([API · EDF.jl](https://docs.juliahub.com/EDF/a8X2Z/0.7.4/)) under `EDF.file`.

I’m interested in reading EDF files but preserving floating points. Is there a way this can be done? I have not found other EDF packages.

Thanks in advance.

---

<div class="post-metadata">

### Author: ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)
#### Post date: [April 13, 2024, 5:20pm UTC](https://discourse.julialang.org/t/reading-edfs-in-julia-preserving-floating-point-values/112911/2 "2024-04-13T17:20:03Z")

</div>

Can you provide a sample file somewhere?

---

<div class="post-metadata">

### Author: ![mkoculak](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkoculak/32/28310_2.png) [@mkoculak](https://discourse.julialang.org/u/mkoculak)
#### Post date: [April 13, 2024, 5:38pm UTC](https://discourse.julialang.org/t/reading-edfs-in-julia-preserving-floating-point-values/112911/3 "2024-04-13T17:38:20Z")

</div>

EDF natively encodes values as Integers, so probably that is what `EDF.jl` is giving you. To get floats, you have to correct the values of each signal with respect to the physical/digital dimensions of that signal encoded in the header.  
In general, it will be enough to do

```julia
scalling = (physical_maximum - physical_minimum) / (digital_maximum - digital_minimum)
samples .*= scaling

```

Note that each signal can have different values for those.  
Some people also perform offset correction to make the span of possible values centred around zero.

---

<div class="post-metadata">

### Author: ![ericphanson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ericphanson/32/215186_2.png) [@ericphanson](https://discourse.julialang.org/u/ericphanson)
#### Post date: [April 13, 2024, 5:39pm UTC](https://discourse.julialang.org/t/reading-edfs-in-julia-preserving-floating-point-values/112911/4 "2024-04-13T17:39:30Z")

</div>

FYI, [`EDF.decode`](https://beacon-biosignals.github.io/EDF.jl/stable/#EDF.decode) will do that decoding for you.

---

<div class="post-metadata">

### Author: ![mkoculak](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkoculak/32/28310_2.png) [@mkoculak](https://discourse.julialang.org/u/mkoculak)
#### Post date: [April 13, 2024, 5:42pm UTC](https://discourse.julialang.org/t/reading-edfs-in-julia-preserving-floating-point-values/112911/5 "2024-04-13T17:42:35Z")

</div>

I was sure it should be there, but scanned the docs and missed that it is at the very bottom of the list.

---

<div class="post-metadata">

### Author: ![Santiago\_Lopez](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/santiago_lopez/32/46298_2.png) [@Santiago\_Lopez](https://discourse.julialang.org/u/Santiago_Lopez)
#### Post date: [April 13, 2024, 5:49pm UTC](https://discourse.julialang.org/t/reading-edfs-in-julia-preserving-floating-point-values/112911/6 "2024-04-13T17:49:17Z")

</div>

Thank you, your answer hits the nail. However, the one by @ericphanson is more straightforward so I marked it as the solution for future readers. Thank you both!
