Skip to content

Commit d4d6a00

Browse files
committed
Cover more tests
Signed-off-by: ErikQQY <[email protected]>
1 parent 763be54 commit d4d6a00

File tree

4 files changed

+24
-10
lines changed

4 files changed

+24
-10
lines changed

docs/src/frft.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@ Pages = ["frft.md"]
66

77
## Definition
88

9-
While we are already familiar with the ordinary Fourier transform, which is defined by the integral of the product of the original function and a kernel function ``e^{-2\pi ix\xi}​``:
9+
While we are already familiar with the Fourier transform, which is defined by the integral of the product of the original function and a kernel function ``e^{-2\pi ix\xi}​``:
1010

1111
```math
1212
\hat{f}(\xi)=\mathcal{F}[f(x)]=\int_{-\infty}^\infty f(x)e^{-2\pi ix\xi}dx
1313
```
1414

1515
The Fractional Fourier transform has the similar definition:
16+
1617
```math
1718
\hat{f}(\xi)=\mathcal{F}^{\alpha}[f(x)]=\int_{-\infty}^\infty K(\xi,x)f(x)dx
1819
```

docs/src/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@ I would like to express gratitude to
3434
**FractionalTransforms.jl** is built upon the hard work of many scientific researchers, I sincerely appreciate what they have done to help the development of science and technology.
3535

3636
!!! info "WIP"
37-
FractionalTransforms.jl is under heavy construction, some API or docs might change a lot.
37+
FractionalTransforms.jl is under heavy construction, some API or docs might change a lot.

src/frft.jl

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using DSP, LinearAlgebra, ToeplitzMatrices, FFTW
1+
using DSP: conv
2+
using LinearAlgebra, ToeplitzMatrices, FFTW
23

34
"""
45
frft(signal, α)
@@ -78,13 +79,13 @@ function frft(signal, α)::Vector{ComplexF64}
7879

7980
y = y[2*M+1:end-2*M]
8081
y = y[1:3:end]
81-
y= @. exp(-im*(pi*sign(sin(ϕ))/4-ϕ/2))*y
82+
y = @. exp(-im*(pi*sign(sin(ϕ))/4-ϕ/2))*y
8283

8384
return y
8485
end
8586

8687
function freq_shear(x, c)
87-
x=x[:]
88+
x = x[:]
8889
N = length(x)
8990
if rem(N, 2) == 0
9091
error("Signal must be odd")
@@ -121,17 +122,17 @@ end
121122
122123
```Sinc interpolation``` of **signal** at rate **rate**.
123124
124-
For more details, please refer to [Whittaker-Shannon interpolation](https://en.wikipedia.org/wiki/Whittaker%E2%80%93Shannon_interpolation_formula)
125+
For more details, please refer to [Whittaker-Shannon interpolation](https://en.wikipedia.org/wiki/Whittaker%E2%80%93Shannon_interpolation_formula).
125126
"""
126127
function sinc_interp(x, rate)
127-
x=x[:]
128-
N=length(x)
129-
M=rate*N-rate+1
128+
x = x[:]
129+
N = length(x)
130+
M = rate*N - rate + 1
130131

131132
y = zeros(ComplexF64, M)
132133
@views y[1:rate:M] = x
133134

134135
h = sinc.(collect(-(N-1-1/rate):1/rate:(N-1-1/rate)))
135136
out = conv(y, h)
136-
out=out[(rate*N-rate):(end-rate*N+rate+1)]
137+
out = out[(rate*N-rate):(end-rate*N+rate+1)]
137138
end

test/frft.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,16 @@ using Test
44
@testset "Test FRFT" begin
55
@test isapprox(real(frft([1,2,3], 0.5)), [0.100464613588213, 3.07460010423315, 1.31566432887283], atol=1e-5)
66
@test isapprox(imag(frft([1,2,3], 0.5)), [-0.259409480977277, 0.199349381540632, -0.93645356561191], atol=1e-5)
7+
end
8+
9+
@testset "Test FRFT auxillary functions" begin
10+
@testset "Test Sinc Interpolation" begin
11+
@test isapprox(real(sinc_interp([1, 2, 3], 3)), [1.0, 1.1577906803857638, 1.4472383504822042, 2.0, 2.6877283651812367, 3.1425747039042147, 3.0]; atol=1e-5)
12+
@test isapprox(imag(sinc_interp([1, 2, 3], 3)), [-4.0696311822644287e-17, -2.4671622769447922e-17, -2.522336560207922e-16, -3.331855648569948e-17, 0.0, 1.9624582529744518e-17, 3.331855648569948e-17]; atol=1e-5)
13+
end
14+
15+
@testset "Test Frequency Shear" begin
16+
@test isapprox(real(freq_shear([1, 2, 3], 3)), [0.0707372016677029, 2.0, 0.2122116050031087]; atol=1e-5)
17+
@test isapprox(imag(freq_shear([1, 2, 3], 3)), [0.9974949866040544, 0.0, 2.9924849598121632]; atol=1e-5)
18+
end
719
end

0 commit comments

Comments
 (0)