FFT, PSD and Windowing functions

564 vues
Accéder directement au premier message non lu

Yared Melese

non lue,
20 juil. 2016, 10:15:4020/07/2016
à julia-users
Hello

Would you please let me know the package available to do windowing, FFT and PSD?

Currently, I have bin file that I have processed in Julia and need to window it and take preferably PSD but FFT work as well

Thanks
Yared

 

Islam Badreldin

non lue,
20 juil. 2016, 19:52:3720/07/2016
à julia-users
Hello Yared,

Take a look at the DSP package

  -Islam

_____________________________
From: Yared Melese <yam0...@gmail.com>
Sent: Wednesday, July 20, 2016 10:15 AM
Subject: [julia-users] FFT, PSD and Windowing functions
To: julia-users <julia...@googlegroups.com>

Yared Melese

non lue,
21 juil. 2016, 11:19:4421/07/2016
à julia-users
Hi Islam,

Thanks for your input

 I was able to find all windowing functions; however, there is nothing about PSD ( power spectral density). In python and matlab, there is function pwelch which does both windowing and FFT and wondering if there is the same function in Julia.

Here is simple trial I had but it is complaining about type mismatch

fb= fb[:]*hamming(length(fb))
fb = fft(fb)         # take FFT of signal

LoadError: MethodError: `*` has no method matching *(::Array{Complex{Float64},1}, ::Array{Float64,1})
Closest candidates are:
  *(::Any, ::Any, !Matched::Any, !Matched::Any...)
  *{T<:Union{Complex{Float32},Complex{Float64},Float32,Float64},S}(!Matched::Union{DenseArray{T<:Union{Complex{Float32},Complex{Float64},Float32,Float64},2},SubArray{T<:Union{Complex{Float32},Complex{Float64},Float32,Float64},2,A<:DenseArray{T,N},I<:Tuple{Vararg{Union{Colon,Int64,Range{Int64}}}},LD}}, ::Union{DenseArray{S,1},SubArray{S,1,A<:DenseArray{T,N},I<:Tuple{Vararg{Union{Colon,Int64,Range{Int64}}}},LD}})
  *{TA,TB}(!Matched::Base.LinAlg.AbstractTriangular{TA,S<:AbstractArray{T,2}}, ::Union{DenseArray{TB,1},DenseArray{TB,2},SubArray{TB,1,A<:DenseArray{T,N},I<:Tuple{Vararg{Union{Colon,Int64,Range{Int64}}}},LD},SubArray{TB,2,A<:DenseArray{T,N},I<:Tuple{Vararg{Union{Colon,Int64,Range{Int64}}}},LD}})
  ...
in include_string at loading.jl:282
in include_string at C:\Users\melese\.julia\v0.4\CodeTools\src\eval.jl:32
in anonymous at C:\Users\melese\.julia\v0.4\Atom\src\eval.jl:84
in withpath at C:\Users\melese\.julia\v0.4\Requires\src\require.jl:37
in withpath at C:\Users\melese\.julia\v0.4\Atom\src\eval.jl:53
[inlined code] from C:\Users\melese\.julia\v0.4\Atom\src\eval.jl:83
in anonymous at task.jl:58
while loading D:\userdata\melese\Desktop\fft.jl, in expression starting on line 23

Islam Badreldin

non lue,
22 juil. 2016, 11:33:3622/07/2016
à julia-users
Hi Yared,

Please see below,,


On Thursday, July 21, 2016 at 11:19:44 AM UTC-4, Yared Melese wrote:
Hi Islam,

Thanks for your input

 I was able to find all windowing functions; however, there is nothing about PSD ( power spectral density). In python and matlab, there is function pwelch which does both windowing and FFT and wondering if there is the same function in Julia.

Did you take a look at `welch_pgram` function?


Here is simple trial I had but it is complaining about type mismatch

fb= fb[:]*hamming(length(fb))
fb = fft(fb)         # take FFT of signal

LoadError: MethodError: `*` has no method matching *(::Array{Complex{Float64},1}, ::Array{Float64,1})
Closest candidates are:
  *(::Any, ::Any, !Matched::Any, !Matched::Any...)
  *{T<:Union{Complex{Float32},Complex{Float64},Float32,Float64},S}(!Matched::Union{DenseArray{T<:Union{Complex{Float32},Complex{Float64},Float32,Float64},2},SubArray{T<:Union{Complex{Float32},Complex{Float64},Float32,Float64},2,A<:DenseArray{T,N},I<:Tuple{Vararg{Union{Colon,Int64,Range{Int64}}}},LD}}, ::Union{DenseArray{S,1},SubArray{S,1,A<:DenseArray{T,N},I<:Tuple{Vararg{Union{Colon,Int64,Range{Int64}}}},LD}})
  *{TA,TB}(!Matched::Base.LinAlg.AbstractTriangular{TA,S<:AbstractArray{T,2}}, ::Union{DenseArray{TB,1},DenseArray{TB,2},SubArray{TB,1,A<:DenseArray{T,N},I<:Tuple{Vararg{Union{Colon,Int64,Range{Int64}}}},LD},SubArray{TB,2,A<:DenseArray{T,N},I<:Tuple{Vararg{Union{Colon,Int64,Range{Int64}}}},LD}})
  ...
in include_string at loading.jl:282
in include_string at C:\Users\melese\.julia\v0.4\CodeTools\src\eval.jl:32
in anonymous at C:\Users\melese\.julia\v0.4\Atom\src\eval.jl:84
in withpath at C:\Users\melese\.julia\v0.4\Requires\src\require.jl:37
in withpath at C:\Users\melese\.julia\v0.4\Atom\src\eval.jl:53
[inlined code] from C:\Users\melese\.julia\v0.4\Atom\src\eval.jl:83
in anonymous at task.jl:58
while loading D:\userdata\melese\Desktop\fft.jl, in expression starting on line 23


This particular error seems to be occurring at the `fb= fb[:]*hamming(length(fb))` line. It looks like you are multiplying an _vector_ of complex doubles with a _vector_ of doubles, which is not mathematically defined because of the dimension mismatch, since both vectors are of dimension Nx1. Instead, my guess is that you meant element-wise multiplication using `.*`. But again, I think the `welch_pgram` function should meet your needs.

  -Islam

Yared Melese

non lue,
26 juil. 2016, 10:25:4526/07/2016
à julia-users
Hi Islam,

Thanks again for your inputs,

the first method worked, as  you mentioned it was missing dot to do element wise multiplication.

Here is what it looks like
pow_fs = (((2^(adc_bits-1))-1))^2 / 2
fb= fb.*hanning(length(fb))

When I tried the weltch function, it actually has two sets of data as shown below, how do you split data to plot and manipulate the array?
Here is the command I used,      periodogram(fb; onesided=eltype(fb)<:Real, nfft=nextfastfft(length(fb), fs=150, window=hanning)

data collected


 Thanks
Yared
Auto Generated Inline Image 1

Islam Badreldin

non lue,
26 juil. 2016, 19:58:3826/07/2016
à julia-users
Hi Yared,




On Tuesday, July 26, 2016 at 10:25:45 AM UTC-4, Yared Melese wrote:
Hi Islam,

Thanks again for your inputs,

the first method worked, as  you mentioned it was missing dot to do element wise multiplication.

Here is what it looks like
pow_fs = (((2^(adc_bits-1))-1))^2 / 2
fb= fb.*hanning(length(fb))

When I tried the weltch function, it actually has two sets of data as shown below, how do you split data to plot and manipulate the array?
Here is the command I used,      periodogram(fb; onesided=eltype(fb)<:Real, nfft=nextfastfft(length(fb), fs=150, window=hanning)

data collected


First, note that you don't have to supply all the keyword arguments if the default values work for you. For example, you can get the same result as above by using
pdg = periodogram(fb; fs=150, window=hanning)

Second, you can split the data by inspecting the field names of the returned result
> fieldnames(pdg)
2-element Array{Symbol,1}:
 
:power
 
:freq

> fb_power = pdg.power
> fb_freq = pdg.freq

You can then plot this data, using PyPlot for example

using PyPlot
plot
(pdg.freq, pdg.power)



I hope this helps.

  -Islam
 
Répondre à tous
Répondre à l'auteur
Transférer
0 nouveau message