# Obtain Power Spectrum from Voltage Timeseries

**URL:** <https://discourse.julialang.org/t/obtain-power-spectrum-from-voltage-timeseries/97064>\
**Category:** Numerics\
**Tags:** fftw\
**Created:** [April 4, 2023, 2:18pm UTC](https://discourse.julialang.org/t/obtain-power-spectrum-from-voltage-timeseries/97064 "2023-04-04T14:18:31Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![raman\_kumar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raman_kumar/32/26782_2.png) [@raman\_kumar](https://discourse.julialang.org/u/raman_kumar)\
**Post date:** [April 4, 2023, 2:18pm UTC](https://discourse.julialang.org/t/obtain-power-spectrum-from-voltage-timeseries/97064/1 "2023-04-04T14:18:31Z")

</div>

I want to obtain Power spectrum of the Voltage Timeseries of Vela Pulsar data given in picture below 🤔

 ![image](https://global.discourse-cdn.com/julialang/original/3X/7/d/7df8de9df059a5ea9a8bf317e36d9f9b15a04c43.png)

How should i implement FFTW ?

---

<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:** [April 4, 2023, 2:33pm UTC](https://discourse.julialang.org/t/obtain-power-spectrum-from-voltage-timeseries/97064/2 "2023-04-04T14:33:46Z")

</div>

Does `DSP.welch_pgram` or `DSP.periodogram` help you?

---

<div class="post-metadata">

**Author:** ![raman\_kumar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raman_kumar/32/26782_2.png) [@raman\_kumar](https://discourse.julialang.org/u/raman_kumar)\
**Post date:** [April 4, 2023, 3:46pm UTC](https://discourse.julialang.org/t/obtain-power-spectrum-from-voltage-timeseries/97064/3 "2023-04-04T15:46:08Z")

</div>

No , i want to do it using FFTW but its documentation is not having examples. What should i do ?

---

<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:** [April 5, 2023, 3:43pm UTC](https://discourse.julialang.org/t/obtain-power-spectrum-from-voltage-timeseries/97064/4 "2023-04-05T15:43:36Z")

</div>

> [@raman\_kumar](#):
>
> What should i do ?

> **[GitHub - KronosTheLate/EasyFFTs.jl: An opinionated layer on top of FFTW.jl to...](https://github.com/KronosTheLate/EasyFFTs.jl)**
>
> An opinionated layer on top of FFTW.jl to provide simpler FFTs for everyone. - GitHub - KronosTheLate/EasyFFTs.jl: An opinionated layer on top of FFTW.jl to provide simpler FFTs for everyone.

---

<div class="post-metadata">

**Author:** ![raman\_kumar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raman_kumar/32/26782_2.png) [@raman\_kumar](https://discourse.julialang.org/u/raman_kumar)\
**Post date:** [April 7, 2023, 1:38pm UTC](https://discourse.julialang.org/t/obtain-power-spectrum-from-voltage-timeseries/97064/5 "2023-04-07T13:38:56Z")

</div>

I think FFTW.jl should have more elaborate documentation with example because fft is very useful . 😉

---

<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:** [April 7, 2023, 1:55pm UTC](https://discourse.julialang.org/t/obtain-power-spectrum-from-voltage-timeseries/97064/6 "2023-04-07T13:55:51Z")

</div>

How to find the DFT of a time series using FFTW:

```julia
using FFTW: fft, fftshift, fftfreq

data = ... # your data here
fs = ... # specify sampling frequency here

# frequencies where the DFT is evaluated:
f_range = fftshift(fftfreq(data, fs))

# DFT of data
data_f = fftshift(fft(data))

```

Using `fftshift` is optional, but it will sort `f_range` in ascending order, which is nice.

---

<div class="post-metadata">

**Author:** ![raman\_kumar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raman_kumar/32/26782_2.png) [@raman\_kumar](https://discourse.julialang.org/u/raman_kumar)\
**Post date:** [April 8, 2023, 5:14pm UTC](https://discourse.julialang.org/t/obtain-power-spectrum-from-voltage-timeseries/97064/7 "2023-04-08T17:14:40Z")

</div>

```julia
using DelimitedFiles,Plots ,PlutoUI,HypothesisTests,Statistics,FFTW
f=raw"/home/raman/Documents/VELA_Data.txt"
M = readdlm(f);
@bind data Slider(1000:1000:50000, default=10000)
M[1:data:end, 1]
g=fftshift(fft(M[1:data:end, 1]),125000)

```

 ![image](https://global.discourse-cdn.com/julialang/original/3X/a/e/aebb55cfc42607398fd3def9a531c157582450e6.png)

```julia
g=fftshift(fft(M[1:data:end, 1]),125000)

```

🤔 is it correct ? Where 125000 is sampling frequency.

---

<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:** [April 8, 2023, 5:20pm UTC](https://discourse.julialang.org/t/obtain-power-spectrum-from-voltage-timeseries/97064/8 "2023-04-08T17:20:38Z")

</div>

You’ve been pointed to this before, but as a reminder please read [your older posts](https://discourse.julialang.org/t/percentages-in-pie-plot/82366/2).
