-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Designs FIR filter taps using the least squares method
- Loading branch information
1 parent
bfb78ef
commit 9135afa
Showing
3 changed files
with
97 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
using DSP | ||
|
||
# Lowpass | ||
N = 41 | ||
b = [(0.0, 0.4, 1), (0.6, 1, 0)] | ||
h_lp = firls(N, b) | ||
|
||
# Highpass | ||
N = 41 | ||
b = [(0.0, 0.4, 0), (0.6, 1, 1)] | ||
h_hp = firls(N, b) | ||
|
||
# Bandpass | ||
N = 41 | ||
b = [(0, .25, -50dBa), (.4, .6, 0dBa), (.75, 1, -50dBa)] | ||
h_bp = firls(N, b) | ||
|
||
# Bandstop | ||
N = 41 | ||
b = [(0, .2, 0dBa), (.4, .6, -10dBa), (.8, 1, 0dBa)] | ||
h_bs = firls(N, b) | ||
|
||
using PyPlot | ||
|
||
function Filters.freqz(h::Vector, w = linspace(0, π, 250)) | ||
pr = PolynomialRatio(h, [one(eltype(h))]) | ||
freqz(pr, w) | ||
end | ||
Util.amp2db(x::Complex) = amp2db(abs(x)) | ||
Util.amp2db(x::AbstractVector) = [amp2db(x) for x in x] | ||
|
||
clf() | ||
subplot(2,2,1) | ||
title("Lowpass") | ||
ylabel("dB") | ||
xlabel("Normalized ƒ (π rad/s)") | ||
H = amp2db(freqz(h_lp)) | ||
f = linspace(0,1, length(H)) | ||
plot(f, H) | ||
grid() | ||
|
||
subplot(2,2,2) | ||
title("Highpass") | ||
ylabel("dB") | ||
xlabel("Normalized ƒ (π rad/s)") | ||
H = amp2db(freqz(h_hp)) | ||
f = linspace(0,1, length(H)) | ||
plot(f, H) | ||
grid() | ||
|
||
subplot(2,2,3) | ||
title("Bandpass") | ||
ylabel("dB") | ||
xlabel("Normalized ƒ (π rad/s)") | ||
H = amp2db(freqz(h_bp)) | ||
f = linspace(0,1, length(H)) | ||
plot(f, H) | ||
grid() | ||
|
||
subplot(2,2,4) | ||
title("Bandstop") | ||
ylabel("dB") | ||
xlabel("Normalized ƒ (π rad/s)") | ||
H = amp2db(freqz(h_bs)) | ||
f = linspace(0,1, length(H)) | ||
plot(f, H) | ||
grid() |