Skip to content

Commit fbbb361

Browse files
committed
fixed tests, fs->r, added w, updated docs, fixed .+ elsewhere
1 parent 3fc2b1d commit fbbb361

File tree

6 files changed

+16
-15
lines changed

6 files changed

+16
-15
lines changed

doc/periodogram.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@
1717

1818
Compute Bartlett periodogram. This is equivalent to welch_pgram(s, n, 0).
1919

20-
.. function:: spectrogram(s; n=8, m=n/2, fs=1)
20+
.. function:: spectrogram(s; n=length(s)/8, m=n/2, r=1, w=(n)->ones(n,1))
2121

22-
Compute Spectrogram based on n segments with overlap m and sampling rate fs.
22+
Compute Spectrogram based on n segments with overlap m, sampling rate r, and window w.

src/DSP.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export
1616
triang, bartlett, gaussian, bartlett_hann, blackman,
1717
kaiser, dpss,
1818
# Periodogram
19-
arraysplit, periodogram, welch_pgram, bartlett_pgram, spectrogram
19+
arraysplit, periodogram, welch_pgram, bartlett_pgram, spectrogram,
2020
# FFTFilt
2121
fftfilt, firfilt,
2222
# FilterDesign

src/filter_design.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -421,8 +421,8 @@ analogfilter(ftype::FilterType, proto::Filter) = transform_prototype(ftype, prot
421421
# Do bilinear transform
422422
bilinear(f::Filter, fs::Real) = bilinear(convert(ZPKFilter, f), fs)
423423
bilinear(f::ZPKFilter, fs::Real) =
424-
ZPKFilter(lfill((2 + f.z / fs)./(2 - f.z / fs), length(f.p), -1),
425-
(2 + f.p / fs)./(2 - f.p / fs), real(f.k * prod(2 * fs - f.z) ./ prod(2 * fs - f.p)))
424+
ZPKFilter(lfill((2 .+ f.z / fs)./(2 .- f.z / fs), length(f.p), -1),
425+
(2 .+ f.p / fs)./(2 .- f.p / fs), real(f.k * prod(2 * fs .- f.z) ./ prod(2 * fs .- f.p)))
426426

427427
# Pre-warp filter frequencies for digital filtering
428428
prewarp(ftype::Union(Lowpass, Highpass)) = (typeof(ftype))(4*tan(pi*ftype.w/2))

src/periodogram.jl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,12 @@ function bartlett_pgram(s, n)
5050
welch_pgram(s, n, 0)
5151
end
5252

53-
function spectrogram(s; n=int(length(s)/8), m=int(n/2), fs=1)
54-
p=[periodogram(s) for s in arraysplit(s, n, m)]
53+
function spectrogram(s; n=int(length(s)/8), m=int(n/2), r=1, w=(n)->ones(n,1))
54+
w=w(n)
55+
p=[periodogram(s.*w) for s in arraysplit(s, n, m)]
5556
p=hcat(p...)
56-
t=(0:size(p,2)-1)*(n-m)/fs + n/2
57-
f=(0:size(p,1)-1)/size(p,1)*fs
57+
t=(0:size(p,2)-1)*(n-m)/r + n/2
58+
f=(0:size(p,1)-1)/size(p,1)*r
5859
p, t, f
5960
end
6061

test/fftfilt.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using DSP, Base.Test
22

3-
for xlen in 2.^(7:18)-1, blen in 2.^(1:6)-1
3+
for xlen in 2.^(7:18).-1, blen in 2.^(1:6).-1
44
b = randn(blen)
55
x = rand(xlen)
66
filtres = filt(b, [1.0], x)

test/periodogram.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616

1717
using DSP, Base.Test
1818

19-
x0 = readdlm("spectrogram_x.txt",'\t')
20-
f0 = readdlm("spectrogram_f.txt",'\t')
21-
t0 = readdlm("spectrogram_t.txt",'\t')
22-
p0 = readdlm("spectrogram_p.txt",'\t')
23-
p, t, f = spectrogram(x0, nfft=256, fs=1, noverlap=128)
19+
x0 = readdlm(joinpath(dirname(@__FILE__), "data", "spectrogram_x.txt"),'\t')
20+
f0 = readdlm(joinpath(dirname(@__FILE__), "data", "spectrogram_f.txt"),'\t')
21+
t0 = readdlm(joinpath(dirname(@__FILE__), "data", "spectrogram_t.txt"),'\t')
22+
p0 = readdlm(joinpath(dirname(@__FILE__), "data", "spectrogram_p.txt"),'\t')
23+
p, t, f = spectrogram(x0, n=256, r=1, m=128)
2424

2525
# with real input matlab outputs a 1-sided PSD
2626
@test_approx_eq p0[[1,129],:] p[[1,129],:]

0 commit comments

Comments
 (0)