【问题标题】:Julia DSP: Convolution of discrete signalsJulia DSP:离散信号的卷积
【发布时间】:2021-02-24 18:17:04
【问题描述】:

这里是problem。我想为 n 的某些值编写两个简单信号 x[n]=0.2^n*u[n] 和 h[n]=u[n+2] 的卷积。这就是我的实现方式:

using Plots, DSP

x(n) = if n<0 0 else 0.2^n end
h(n) = if n<-2 0 else 1 end

n = -10:10
conv(h.(n),x.(n))

它不起作用。这是错误:

`float` not defined on abstractly-typed arrays; please convert to a more specific type

知道如何解决吗?

【问题讨论】:

    标签: julia signal-processing convolution


    【解决方案1】:

    我使用新的 REPL 会话运行良好:

    julia> using Plots, DSP
    [ Info: Precompiling Plots [91a5bcdd-55d7-5caf-9e0b-520d859cae80]
    [ Info: Precompiling DSP [717857b8-e6f2-59f4-9121-6e50c889abd2]
            
    julia> x(n) = if n<0 0 else 2^n end
    x (generic function with 1 method)
    
    julia> h(n) = if n<-2 0 else 1 end
    h (generic function with 1 method)
    
    julia> n = -10:10
    -10:10
    
    julia> conv(h.(n),x.(n))
    41-element Array{Int64,1}:
        0
        0
      
     (etc)
     
     1984
     1920
     1792
     1536
     1024
    
    julia> plot(conv(h.(n),x.(n)))
    (plots ok)
    

    如果将 2 in 2^n 更改为浮点数,则需要指定 Float64:

    julia>  x(n) = if n<0 0 else  0.2^n end
    x (generic function with 1 method)
    
    julia> conv(h.(n),Float64.(x.(n)))
    41-element Array{Float64,1}:
      0.0
      8.458842092382145e-17
      2.5376526277146434e-16
      4.229421046191072e-17
      2.1147105230955362e-16
           
       (etc)
       
      7.997440000004915e-5
      1.597440000003685e-5
      3.1744000002024485e-6
      6.144000000924524e-7
      1.0240000015600833e-7
    

    【讨论】:

    • 是的,它是这样工作的,但是如果你把 2 改成 0.2 就不行了!知道为什么吗?更多详情:github.com/JuliaDSP/DSP.jl/issues/404
    • 啊哈,投射到 Float64 作品:conv(h.(n),Float64.(x.(n)))
    猜你喜欢
    • 2017-05-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-30
    • 2013-07-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多