rm unused tests

pull/324/head
Shuhei Kadowaki 2020-05-10 14:37:50 +09:00
parent de2a6657ea
commit 423146f981
14 changed files with 1 additions and 676 deletions

View File

@ -1,80 +0,0 @@
#' % FIR filter design with Julia
#' % Matti Pastell
#' % 21th April 2016
#' # Introduction
#' This an example of a julia script that can be published using
#' [Weave](http://mpastell.github.io/Weave.jl/latest/usage/).
#' The script can be executed normally using Julia
#' or published to HTML or pdf with Weave.
#' Text is written in markdown in lines starting with "`#'` " and code
#' is executed and results are included in the published document.
#' Notice that you don't need to define chunk options, but you can using
#' `#+`. just before code e.g. `#+ term=True, caption='Fancy plots.'`.
#' If you're viewing the published version have a look at the
#' [source](FIR_design.jl) to see the markup.
#' # FIR Filter Design
#' We'll implement lowpass, highpass and ' bandpass FIR filters. If
#' you want to read more about DSP I highly recommend [The Scientist
#' and Engineer's Guide to Digital Signal
#' Processing](http://www.dspguide.com/) which is freely available
#' online.
#' ## Calculating frequency response
#' DSP.jl package doesn't (yet) have a method to calculate the
#' the frequency response of a FIR filter so we define it:
using Gadfly, DSP
function FIRfreqz(b::Array, w = range(0, stop=π, length=1024))
n = length(w)
h = Array{ComplexF32}(n)
sw = 0
for i = 1:n
for j = 1:length(b)
sw += b[j]*exp(-im*w[i])^-j
end
h[i] = sw
sw = 0
end
return h
end
#' ## Design Lowpass FIR filter
#' Designing a lowpass FIR filter is very simple to do with DSP.jl, all you
#' need to do is to define the window length, cut off frequency and the
#' window. We will define a lowpass filter with cut off frequency at 5Hz for a signal
#' sampled at 20 Hz.
#' We will use the Hamming window, which is defined as:
#' $w(n) = \alpha - \beta\cos\frac{2\pi n}{N-1}$, where $\alpha=0.54$ and $\beta=0.46$
fs = 20
f = digitalfilter(Lowpass(5, fs = fs), FIRWindow(hamming(61)))
w = range(0, stop=pi, length=1024)
h = FIRfreqz(f, w)
#' ## Plot the frequency and impulse response
h_db = log10(abs(h))
ws = w/pi*(fs/2)
#' The next code chunk is executed in term mode, see the [script](FIR_design.jl) for syntax.
#+ term=true
plot(y = h_db, x = ws, Geom.line,
Guide.xlabel("Frequency (Hz)"), Guide.ylabel("Magnitude (db)"))
#' And again with default options
h_phase = unwrap(-atan(imag(h),real(h)))
plot(y = h_phase, x = ws, Geom.line,
Guide.xlabel("Frequency (Hz)"), Guide.ylabel("Phase (radians)"))

View File

@ -1,112 +0,0 @@
% FIR filter design with Julia
% Matti Pastell
% 21th April 2016
# Introduction
This an example of a julia script that can be published using
[Weave](http://mpastell.github.io/Weave.jl/latest/usage/).
The script can be executed normally using Julia
or published to HTML or pdf with Weave.
Text is written in markdown in lines starting with "`#'` " and code
is executed and results are included in the published document.
Notice that you don't need to define chunk options, but you can using
`#+`. just before code e.g. `#+ term=True, caption='Fancy plots.'`.
If you're viewing the published version have a look at the
[source](FIR_design.jl) to see the markup.
# FIR Filter Design
We'll implement lowpass, highpass and ' bandpass FIR filters. If
you want to read more about DSP I highly recommend [The Scientist
and Engineer's Guide to Digital Signal
Processing](http://www.dspguide.com/) which is freely available
online.
## Calculating frequency response
DSP.jl package doesn't (yet) have a method to calculate the
the frequency response of a FIR filter so we define it:
~~~~{.julia}
using Gadfly, DSP
function FIRfreqz(b::Array, w = linspace(0, π, 1024))
n = length(w)
h = Array{Complex64}(n)
sw = 0
for i = 1:n
for j = 1:length(b)
sw += b[j]*exp(-im*w[i])^-j
end
h[i] = sw
sw = 0
end
return h
end
~~~~~~~~~~~~~
## Design Lowpass FIR filter
Designing a lowpass FIR filter is very simple to do with DSP.jl, all you
need to do is to define the window length, cut off frequency and the
window. We will define a lowpass filter with cut off frequency at 5Hz for a signal
sampled at 20 Hz.
We will use the Hamming window, which is defined as:
$w(n) = \alpha - \beta\cos\frac{2\pi n}{N-1}$, where $\alpha=0.54$ and $\beta=0.46$
~~~~{.julia}
fs = 20
f = digitalfilter(Lowpass(5, fs = fs), FIRWindow(hamming(61)))
w = linspace(0, pi, 1024)
h = FIRfreqz(f, w)
~~~~~~~~~~~~~
## Plot the frequency and impulse response
~~~~{.julia}
h_db = log10(abs(h))
ws = w/pi*(fs/2)
~~~~~~~~~~~~~
The next code chunk is executed in term mode, see the [script](FIR_design.jl) for syntax.
~~~~{.julia}
julia> plot(y = h_db, x = ws, Geom.line,
Guide.xlabel("Frequency (Hz)"), Guide.ylabel("Magnitude (db)"))
Plot(...)
~~~~~~~~~~~~~
![](figures/FIR_design_4_1.png)\
And again with default options
~~~~{.julia}
h_phase = unwrap(-atan2(imag(h),real(h)))
plot(y = h_phase, x = ws, Geom.line,
Guide.xlabel("Frequency (Hz)"), Guide.ylabel("Phase (radians)"))
~~~~~~~~~~~~~
![](figures/FIR_design_5_1.png)\

View File

@ -1,56 +0,0 @@
[source,julia]
--------------------------------------
using Gadfly
x = linspace(0, 2π, 200)
plot(x=x, y = sin(x), Geom.line)
--------------------------------------
image::figures/gadfly_formats_test_sin_fun_1.png[width=600,title="sin(x) function."]
image::figures/gadfly_formats_test_2_1.png[width=600,title="cos(x) function."]
image::figures/gadfly_formats_test_cos2_fun_1.png[width=600]
[source,julia]
--------------------------------------
julia> x = linspace(0, 2π, 200)
200-element LinSpace{Float64}:
0.0,0.0315738,0.0631476,0.0947214,0.126295,…,6.18846,6.22004,6.25161,6.28319
julia> plot(x=x, y = sin(x), Geom.line)
Plot(...)
--------------------------------------
image::figures/gadfly_formats_test_4_1.png[width=600]
[source,julia]
--------------------------------------
julia> y = 20
20
julia> plot(x=x, y = cos(x), Geom.line)
Plot(...)
--------------------------------------
image::figures/gadfly_formats_test_4_2.png[width=600]
[source,julia]
--------------------------------------
x = linspace(0, 2π, 200)
plot(x=x, y = sin(x), Geom.line)
--------------------------------------
image::figures/gadfly_formats_test_5_1.png[width=15cm]
[source,julia]
--------------------------------------
y = 20
plot(x=x, y = cos(x), Geom.line)
--------------------------------------
image::figures/gadfly_formats_test_5_2.png[width=15cm]

File diff suppressed because one or more lines are too long

View File

@ -1,26 +0,0 @@
\section{Header}
\begin{minted}[mathescape, fontsize=\small, xleftmargin=0.5em]{julia}
using Plots
gr()
scatter(1:10)
\end{minted}
\includegraphics[width=\linewidth]{figures/publish_test_1_1.pdf}
\begin{minted}[mathescape, fontsize=\small, xleftmargin=0.5em]{julia}
plot(1:10)
\end{minted}
\begin{figure}[!h]
\center
\includegraphics[width=\linewidth]{figures/publish_test_somefig_1.pdf}
\caption{Hello}
\label{fig:somefig}
\end{figure}

View File

@ -1,17 +0,0 @@
---
title : Test
author: Matti Pastell
date : today
---
# Header
```julia
using Plots
gr()
scatter(1:10)
```
```julia; fig_cap = "Hello"; label = "somefig"
plot(1:10)
```

View File

@ -1,29 +0,0 @@
<<fig_cap="sin(x) function."; label="sin_fun"; fig_pos="ht">>=
using PyPlot
x = linspace(0, 2π, 200)
plot(x, sin(x))
@
<<echo=false; fig_cap="cos(x) function.">>=
plot(x, cos(x))
@
<<echo=false; label="cos2_fun">>=
plot(x, cos(2x))
@
<<term=true;fig_width=5>>=
x = linspace(0, 2π, 200)
plot(x, sin(x))
y = 20
plot(x, cos(x))
@
<<out_width="15cm">>=
x = randn(100, 100)
contourf(x)
@

View File

@ -1,74 +0,0 @@
````julia
using PyPlot
x = linspace(0, 2π, 200)
plot(x, sin(x))
````
````
1-element Array{Any,1}:
PyObject <matplotlib.lines.Line2D object at 0x7f5326a4a290>
````
![sin(x) function.](figures/pyplot_formats_sin_fun_1.png)
````
1-element Array{Any,1}:
PyObject <matplotlib.lines.Line2D object at 0x7f5326a56c10>
````
![cos(x) function.](figures/pyplot_formats_2_1.png)
````
1-element Array{Any,1}:
PyObject <matplotlib.lines.Line2D object at 0x7f5326d76350>
````
![](figures/pyplot_formats_cos2_fun_1.png)
````julia
julia> x = linspace(0, 2π, 200)
linspace(0.0,6.283185307179586,200)
julia> plot(x, sin(x))
1-element Array{Any,1}:
PyObject <matplotlib.lines.Line2D object at 0x7f5326de8c10>
julia> y = 20
20
julia> plot(x, cos(x))
1-element Array{Any,1}:
PyObject <matplotlib.lines.Line2D object at 0x7f5326de8e50>
````
![](figures/pyplot_formats_4_1.png)
````julia
x = randn(100, 100)
contourf(x)
````
````
PyObject <matplotlib.contour.QuadContourSet object at 0x7f53346d2910>
````
![](figures/pyplot_formats_5_1.png)

View File

@ -1,64 +0,0 @@
````julia
using PyPlot
x = range(0, stop=2π, length=200)
plot(x, sin(x))
````
````
1-element Array{Any,1}:
PyObject <matplotlib.lines.Line2D object at 0x7fbd590d7860>
````
![sin(x) function.](figures/pyplot_formats_sin_fun_1.png)
````
1-element Array{Any,1}:
PyObject <matplotlib.lines.Line2D object at 0x7fbd60094160>
````
![cos(x) function.](figures/pyplot_formats_2_1.png)
````
1-element Array{Any,1}:
PyObject <matplotlib.lines.Line2D object at 0x7fbd5905c7b8>
````
![](figures/pyplot_formats_cos2_fun_1.png)
````julia
julia> x = range(0, stop=2π, length=200)
200-element LinSpace{Float64}:
0.0,0.0315738,0.0631476,0.0947214,0.126295,…,6.18846,6.22004,6.25161,6.28319
julia> plot(x, sin(x))
1-element Array{Any,1}:
PyObject <matplotlib.lines.Line2D object at 0x7fbd60047fd0>
julia> y = 20
20
julia> plot(x, cos(x))
1-element Array{Any,1}:
PyObject <matplotlib.lines.Line2D object at 0x7fbd6004eeb8>
````
![](figures/pyplot_formats_4_1.png)
````julia
x = randn(100, 100)
contourf(x)
````
````
PyObject <matplotlib.contour.QuadContourSet object at 0x7fbd5a506128>
````
![](figures/pyplot_formats_5_1.png)

View File

@ -1,85 +0,0 @@
.. code-block:: julia
using PyPlot
x = linspace(0, 2π, 200)
plot(x, sin(x))
::
1-element Array{Any,1}:
PyObject <matplotlib.lines.Line2D object at 0x7fbd50edb0b8>
.. figure:: figures/pyplot_formats_sin_fun_1.svg
:width: 15 cm
sin(x) function.
::
1-element Array{Any,1}:
PyObject <matplotlib.lines.Line2D object at 0x7fbd514a7780>
.. figure:: figures/pyplot_formats_2_1.svg
:width: 15 cm
cos(x) function.
::
1-element Array{Any,1}:
PyObject <matplotlib.lines.Line2D object at 0x7fbd580c6080>
.. image:: figures/pyplot_formats_cos2_fun_1.svg
:width: 15 cm
.. code-block:: julia
julia> x = linspace(0, 2π, 200)
200-element LinSpace{Float64}:
0.0,0.0315738,0.0631476,0.0947214,0.126295,…,6.18846,6.22004,6.25161,6.28319
julia> plot(x, sin(x))
1-element Array{Any,1}:
PyObject <matplotlib.lines.Line2D object at 0x7fbd585a7320>
julia> y = 20
20
julia> plot(x, cos(x))
1-element Array{Any,1}:
PyObject <matplotlib.lines.Line2D object at 0x7fbd58612128>
.. image:: figures/pyplot_formats_4_1.svg
:width: 15 cm
.. code-block:: julia
x = randn(100, 100)
contourf(x)
::
PyObject <matplotlib.contour.QuadContourSet object at 0x7fbd5a2d8e48>
.. image:: figures/pyplot_formats_5_1.svg
:width: 15cm

View File

@ -1,59 +0,0 @@
\begin{juliacode}
using PyPlot
x = linspace(0, 2π, 200)
plot(x, sin(x))
\end{juliacode}
\begin{juliaout}
1-element Array{Any,1}:
PyObject <matplotlib.lines.Line2D object at 0x7fbd66371c50>
\end{juliaout}
\begin{figure}[ht]
\center
\includegraphics[width=\linewidth]{figures/pyplot_formats_sin_fun_1.pdf}
\caption{sin(x) function.}
\label{fig:sin_fun}
\end{figure}
\begin{juliaout}
1-element Array{Any,1}:
PyObject <matplotlib.lines.Line2D object at 0x7fbd66325a20>
\end{juliaout}
\begin{figure}[htpb]
\center
\includegraphics[width=\linewidth]{figures/pyplot_formats_2_1.pdf}
\caption{cos(x) function.}
\end{figure}
\begin{juliaout}
1-element Array{Any,1}:
PyObject <matplotlib.lines.Line2D object at 0x7fbd6629cf28>
\end{juliaout}
\includegraphics[width=\linewidth]{figures/pyplot_formats_cos2_fun_1.pdf}
\begin{juliaterm}
julia> x = linspace(0, 2π, 200)
200-element LinSpace{Float64}:
0.0,0.0315738,0.0631476,0.0947214,0.126295,…,6.18846,6.22004,6.25161,6.28319
julia> plot(x, sin(x))
1-element Array{Any,1}:
PyObject <matplotlib.lines.Line2D object at 0x7fbd600ca588>
julia> y = 20
20
julia> plot(x, cos(x))
1-element Array{Any,1}:
PyObject <matplotlib.lines.Line2D object at 0x7fbd600f4c18>
\end{juliaterm}
\includegraphics[width=\linewidth]{figures/pyplot_formats_4_1.pdf}
\begin{juliacode}
x = randn(100, 100)
contourf(x)
\end{juliacode}
\begin{juliaout}
PyObject <matplotlib.contour.QuadContourSet object at 0x7fbd600ba9b0>
\end{juliaout}
\includegraphics[width=15cm]{figures/pyplot_formats_5_1.pdf}

View File

@ -1,6 +1,6 @@
# Test for Gadfly with different chunk options and figure formatsusing Weave
using Gadfly
using Gadfly, Cairo
function test_gadfly(doctype, fig_ext)

View File

@ -1,17 +0,0 @@
using Weave
using Test
import Plots
function publish_test(outfile, format)
outfile = joinpath("documents/publish", outfile)
infile = "documents/publish_test.jmd"
weave(infile, doctype = format, out_path = outfile, template = "templates/mini.tpl")
result = read(outfile, String)
ref = read(outfile * ".ref", String)
@test result == ref
rm(outfile)
end
#Test formatters
publish_test("publish_tex.tex", "md2tex")
#!is_windows() && publish_test("publish_test.html", "md2html")

View File

@ -1,33 +0,0 @@
using Weave
using Test
cleanup = true
weave("documents/pyplot_formats.txt", plotlib="pyplot", doctype="tex")
result = read("documents/pyplot_formats.tex", String)
ref = read("documents/pyplot_formats_ref.tex", String)
result = replace(result, r"\s*PyObject.*\n", "\n") #Remove PyObjects, because they change
ref = replace(ref, r"\s*PyObject.*\n", "\n")
@test result == ref
weave("documents/pyplot_formats.txt", plotlib="pyplot", doctype="github")
result = read("documents/pyplot_formats.md", String)
ref = read("documents/pyplot_formats_ref.md", String)
result = replace(result, r"\s*PyObject.*\n", "")
ref = replace(ref, r"\s*PyObject.*\n", "")
@test result == ref
weave("documents/pyplot_formats.txt", plotlib="pyplot", doctype="rst", fig_ext=".svg")
result = read("documents/pyplot_formats.rst", String)
ref = read("documents/pyplot_formats_ref.rst", String)
result = replace(result, r"\s*PyObject.*\n", "")
ref = replace(ref, r"\s*PyObject.*\n", "")
@test result == ref
if cleanup
rm("documents/pyplot_formats.tex")
rm("documents/pyplot_formats.rst")
rm("documents/pyplot_formats.md")
rm("documents/figures", recursive = true)
end