This page is not created by, affiliated with, or supported by Slack Technologies, Inc.

## 2024-05-10

## Channels

- # ai (11)
- # babashka (14)
- # beginners (10)
- # biff (3)
- # clj-kondo (6)
- # clojure (34)
- # clojure-austin (1)
- # clojure-europe (23)
- # clojure-gamedev (16)
- # clojure-korea (2)
- # clojure-norway (13)
- # clojure-romania (1)
- # clojure-uk (4)
- # community-development (26)
- # cursive (11)
- # emacs (19)
- # fulcro (105)
- # gratitude (1)
- # honeysql (16)
- # jobs (1)
- # malli (17)
- # off-topic (5)
- # portal (8)
- # reitit (8)
- # remote-jobs (1)
- # shadow-cljs (30)
- # xtdb (10)
- # yamlscript (14)

Hello friends, I have a strange requirement. I have data coming in from a web server at random time intervals. For illustration lets assume I've configured the data as a vector of maps as follows:
`[{:ts 1709624250435 :data 4} {:ts 1709624270435 :data 7} {:ts 1709624270635 :data 2} ... ]`

The ts elements are the long format time vectors and the real date is given by `(ctc/from-long 1709624250435) => #clj-time/date-time "2024-03-05T07:37:30.435Z"`

I need to perform fourier transform on this set of data. Lets assume I want to sample 256 data points. But for fourier transform the data samples need to be at regular samples.
Has anyone managed to convert data sampled at not regular intervals into regular intervals? In my case say I want to sample the data every second, if the data coming in didn't change in that 1 second cycle then the data stays the same as the last value.
Any help will be much appreciated! Many thanks!
To give you some context the data is coming in from a depth sensor on a moving platform.

the implications of interpolating data to get regular time intervals for a fourier analysis vastly exceed the help that we can be expected to give in *#C053AK3F9*. However, once you know what you want to do, I bet we can help out

So my suggestion is find somewhere where you can ask data science questions to figure out the what, and then this community can help out with the how

Thanks for your reply @U11BV7MTK! When I figure it out I'll post my solution back here.

sounds interesting. and perhaps someone here has experience but it’s not our core area of expertise. Hope you solve your issue

I want to stress very much that the code here is not tested, nor have I thought about where things might go wrong, so please only take this as a suggestion of a starting point. If you want to do some interpolation, and linear interpolation is fine, you can sort of break it down to finding 1 sample just below your time of interest ‘t’ and one just above your time of interest. That’ll be 2 2-dimensional points (x = time, y = your sample value) that straddle your time. You can then get the y-intercept (really the t-intercept at time ‘t’) and you’ll have your interpolated sample value. If you’re able to get a bunch of samples in memory first, you can construct a range of regular t values, get the nearest 2 points for each t, do the intercept calculation, and you’ll have your estimated regular values. You would have to be careful with your first and last estimated points, and make sure that the ‘nearest-2’ function is actually working correctly. Plus you might have to consider a situation where an interval may have 0 samples on either its left or its right (in fact, this situation would break my nearest-2 function below). I hope that’s not too confusing… might be just enough to spark your own thought process further.

```
;; Assuming linear interpolation is good enough, you can consider your samples as 2D points
;; where time is the X axis and Y is your sample's value.
;; If you're doing linear interpolation, and you know that point 1 is
;; to the left of x and point 2 is to the right of x, we can write a fn
;; that gives the intercept at that x position:
;; This is just super basic stuff, y = mx + b, m is slope, rearrange to calculate 'b'
;; and subtract t to 'move the y-axis' that you care about
(defn intercept-at-time-t
[[t1 y1] [t2 y2] t]
(let [slope (/ (- y2 y1) (- t2 t1))]
[t (- y1 (* slope (- t1 t)))]))
;; Then, if you're able to aggregate some of your sample points, you could
;; construct a range of regular timestep intervals and use each of those points to get the nearest
;; 2 samples below/above that time
;; NOTE: please check that this actually works... it's a quick hack!!
(defn nearest-2
[samples t]
(take 2 (sort-by (fn [[t' _]]
(abs (- t' t)))
samples)))
(let [your-samples [[0.234 543] [1.4 703]]
start-time 0
step-size 1
n-samples 2
regular-sample-points (range start-time (+ start-time (* n-samples step-size)) step-size)]
(for [t regular-sample-points]
(apply #(intercept-at-time-t %1 %2 t) (nearest-2 your-samples t))))
```

thanks for spending so much time and effort in your answer @U01LR7M2B7A!! Unfortunately I can't interpolate. As I explained earlier, as I am getting data from a depth sensor, if there is no sample... that means the depth didn't change... but your answer gave me an idea to try out. I have been playing with clojure.lang.PersistentQueue for now and I am just trying to check the data time stamp and if it is before the regular time sample trigger, then I take the last value. It is not done yet... but thanks for your help!

Haha, oops. Should’ve read a little more carefully. Still, I’m happy I provided a little idea, at least 🙂 Good luck with your work!

I’m confused about the difference between `reify`

`specify`

and `specify!`

I came across this in the great clerk library. https://github.com/nextjournal/clerk/blob/ee0248bbc1054476e781e25b11414fa9899050b9/src/nextjournal/clerk/render/hooks.cljs#L60
Here is the `specify!`

source
https://github.com/clojure/clojurescript/blob/e74d48d5b0fd8d08c154672349cfa4d8a4166d2d/src/main/clojure/cljs/core.cljc#L1387
Is this like reify without rules? I don’t have the best handle on OO code, so what exactly am I mutating in specify!? And why can’t I mutate it in reify?

Interesting... I'm only familiar with `reify`

because those other two don't exist in Clojure: they are ClojureScript-specific.