From: <pki...@us...> - 2008-10-27 10:01:15
|
Revision: 5386 http://octave.svn.sourceforge.net/octave/?rev=5386&view=rev Author: pkienzle Date: 2008-10-27 09:56:54 +0000 (Mon, 27 Oct 2008) Log Message: ----------- signal: undoing change from T->Fs in iir filters Modified Paths: -------------- trunk/octave-forge/main/signal/inst/bilinear.m trunk/octave-forge/main/signal/inst/butter.m trunk/octave-forge/main/signal/inst/buttord.m trunk/octave-forge/main/signal/inst/cheb1ord.m trunk/octave-forge/main/signal/inst/cheb2ord.m trunk/octave-forge/main/signal/inst/cheby1.m trunk/octave-forge/main/signal/inst/cheby2.m trunk/octave-forge/main/signal/inst/ellip.m trunk/octave-forge/main/signal/inst/ellipord.m Modified: trunk/octave-forge/main/signal/inst/bilinear.m =================================================================== --- trunk/octave-forge/main/signal/inst/bilinear.m 2008-10-25 09:09:50 UTC (rev 5385) +++ trunk/octave-forge/main/signal/inst/bilinear.m 2008-10-27 09:56:54 UTC (rev 5386) @@ -13,20 +13,20 @@ ## You should have received a copy of the GNU General Public License ## along with this program; If not, see <http://www.gnu.org/licenses/>. -## usage: [Zz, Zp, Zg] = bilinear(Sz, Sp, Sg, Fs) -## [Zb, Za] = bilinear(Sb, Sa, Fs) +## usage: [Zz, Zp, Zg] = bilinear(Sz, Sp, Sg, T) +## [Zb, Za] = bilinear(Sb, Sa, T) ## ## Transform a s-plane filter specification into a z-plane ## specification. Filters can be specified in either zero-pole-gain or ## transfer function form. The input form does not have to match the -## output form. Fs is the sampling frequency represented in the z plane. +## output form. T is the sampling frequency represented in the z plane. ## ## Theory: Given a piecewise flat filter design, you can transform it ## from the s-plane to the z-plane while maintaining the band edges by ## means of the bilinear transform. This maps the left hand side of the ## s-plane into the interior of the unit circle. The mapping is highly ## non-linear, so you must design your filter with band edges in the -## s-plane positioned at 2/Fs tan(w*Fs/2) so that they will be positioned +## s-plane positioned at 2/T tan(w*T/2) so that they will be positioned ## at w after the bilinear transform is complete. ## ## The following table summarizes the transformation: @@ -35,9 +35,9 @@ ## | Transform | Zero at x | Pole at x | ## | H(S) | H(S) = S-x | H(S)=1/(S-x) | ## +---------------+-----------------------+----------------------+ -## | 2 z-1 | zero: (2+xFs)/(2-xFs) | zero: -1 | -## | S -> -- --- | pole: -1 | pole: (2+xFs)/(2-xFs)| -## | Fs z+1 | gain: (2-xFs)/Fs | gain: (2-xFs)/Fs | +## | 2 z-1 | zero: (2+xT)/(2-xT) | zero: -1 | +## | S -> - --- | pole: -1 | pole: (2+xT)/(2-xT) | +## | T z+1 | gain: (2-xT)/T | gain: (2-xT)/T | ## +---------------+-----------------------+----------------------+ ## ## With tedious algebra, you can derive the above formulae yourself by @@ -69,13 +69,13 @@ ## Author: Paul Kienzle <pki...@us...> -function [Zz, Zp, Zg] = bilinear(Sz, Sp, Sg, Fs) +function [Zz, Zp, Zg] = bilinear(Sz, Sp, Sg, T) if nargin==3 - Fs = Sg; + T = Sg; [Sz, Sp, Sg] = tf2zp(Sz, Sp); elseif nargin!=4 - usage("[Zz, Zp, Zg]=bilinear(Sz,Sp,Sg,Fs) or [Zb, Za]=blinear(Sb,Sa,Fs)"); + usage("[Zz, Zp, Zg]=bilinear(Sz,Sp,Sg,T) or [Zb, Za]=blinear(Sb,Sa,T)"); end; p = length(Sp); @@ -85,17 +85,17 @@ end ## ---------------- ------------------------- ------------------------ -## Bilinear zero: (2+xFs)/(2-xFs) pole: (2+xFs)/(2-xFs) -## 2 z-1 pole: -1 zero: -1 -## S -> -- --- gain: (2-xFs)/Fs gain: (2-xFs)/Fs -## Fs z+1 +## Bilinear zero: (2+xT)/(2-xT) pole: (2+xT)/(2-xT) +## 2 z-1 pole: -1 zero: -1 +## S -> - --- gain: (2-xT)/T gain: (2-xT)/T +## T z+1 ## ---------------- ------------------------- ------------------------ - Zg = real(Sg * prod((2-Sz*Fs)/Fs) / prod((2-Sp*Fs)/Fs)); - Zp = (2+Sp*Fs)./(2-Sp*Fs); + Zg = real(Sg * prod((2-Sz*T)/T) / prod((2-Sp*T)/T)); + Zp = (2+Sp*T)./(2-Sp*T); if isempty(Sz) Zz = -ones(size(Zp)); else - Zz = [(2+Sz*Fs)./(2-Sz*Fs)]; + Zz = [(2+Sz*T)./(2-Sz*T)]; Zz = postpad(Zz, p, -1); end Modified: trunk/octave-forge/main/signal/inst/butter.m =================================================================== --- trunk/octave-forge/main/signal/inst/butter.m 2008-10-25 09:09:50 UTC (rev 5385) +++ trunk/octave-forge/main/signal/inst/butter.m 2008-10-27 09:56:54 UTC (rev 5386) @@ -87,8 +87,8 @@ ## Prewarp to the band edges to s plane if digital - Fs = 2; # sampling frequency of 2 Hz - W = 2/Fs*tan(pi*W/Fs); + T = 2; # sampling frequency of 2 Hz + W = 2/T*tan(pi*W/T); endif ## Generate splane poles for the prototype butterworth filter @@ -104,7 +104,7 @@ ## Use bilinear transform to convert poles to the z plane if digital - [zero, pole, gain] = bilinear(zero, pole, gain, Fs); + [zero, pole, gain] = bilinear(zero, pole, gain, T); endif ## convert to the correct output form Modified: trunk/octave-forge/main/signal/inst/buttord.m =================================================================== --- trunk/octave-forge/main/signal/inst/buttord.m 2008-10-25 09:09:50 UTC (rev 5385) +++ trunk/octave-forge/main/signal/inst/buttord.m 2008-10-27 09:56:54 UTC (rev 5386) @@ -55,7 +55,7 @@ warning("buttord: seems to overdesign bandpass and bandreject filters"); end - Fs = 2; + T = 2; ## if high pass, reverse the sense of the test stop = find(Wp > Ws); @@ -63,8 +63,8 @@ Ws(stop) = 1-Ws(stop); # subtract from ones(1,length(stop)) ## warp the target frequencies according to the bilinear transform - Ws = (2/Fs)*tan(pi*Ws./Fs); - Wp = (2/Fs)*tan(pi*Wp./Fs); + Ws = (2/T)*tan(pi*Ws./T); + Wp = (2/T)*tan(pi*Wp./T); ## compute minimum n which satisfies all band edge conditions ## the factor 1/length(Wp) is an artificial correction for the @@ -77,7 +77,7 @@ Wc = exp(log(Wp) - qp/2/n); ## unwarp the returned frequency - Wc = atan(Fs/2*Wc)*Fs/pi; + Wc = atan(T/2*Wc)*T/pi; ## if high pass, reverse the sense of the test Wc(stop) = 1-Wc(stop); Modified: trunk/octave-forge/main/signal/inst/cheb1ord.m =================================================================== --- trunk/octave-forge/main/signal/inst/cheb1ord.m 2008-10-25 09:09:50 UTC (rev 5385) +++ trunk/octave-forge/main/signal/inst/cheb1ord.m 2008-10-27 09:56:54 UTC (rev 5386) @@ -44,14 +44,14 @@ error("cheb1ord: Wp(1)<Ws(1)<Ws(2)<Wp(2) or Ws(1)<Wp(1)<Wp(2)<Ws(2)"); end - Fs = 2; + T = 2; ## returned frequency is the same as the input frequency Wc = Wp; ## warp the target frequencies according to the bilinear transform - Ws = (2/Fs)*tan(pi*Ws./Fs); - Wp = (2/Fs)*tan(pi*Wp./Fs); + Ws = (2/T)*tan(pi*Ws./T); + Wp = (2/T)*tan(pi*Wp./T); if (Wp(1) < Ws(1)) ## low pass Modified: trunk/octave-forge/main/signal/inst/cheb2ord.m =================================================================== --- trunk/octave-forge/main/signal/inst/cheb2ord.m 2008-10-25 09:09:50 UTC (rev 5385) +++ trunk/octave-forge/main/signal/inst/cheb2ord.m 2008-10-27 09:56:54 UTC (rev 5386) @@ -44,14 +44,14 @@ error("cheb2ord: Wp(1)<Ws(1)<Ws(2)<Wp(2) or Ws(1)<Wp(1)<Wp(2)<Ws(2)"); end - Fs = 2; + T = 2; ## returned frequency is the same as the input frequency Wc = Ws; ## warp the target frequencies according to the bilinear transform - Ws = (2/Fs)*tan(pi*Ws./Fs); - Wp = (2/Fs)*tan(pi*Wp./Fs); + Ws = (2/T)*tan(pi*Ws./T); + Wp = (2/T)*tan(pi*Wp./T); if (Wp(1) < Ws(1)) ## low pass Modified: trunk/octave-forge/main/signal/inst/cheby1.m =================================================================== --- trunk/octave-forge/main/signal/inst/cheby1.m 2008-10-25 09:09:50 UTC (rev 5385) +++ trunk/octave-forge/main/signal/inst/cheby1.m 2008-10-27 09:56:54 UTC (rev 5386) @@ -89,8 +89,8 @@ ## Prewarp to the band edges to s plane if digital - Fs = 2; # sampling frequency of 2 Hz - W = 2/Fs*tan(pi*W/Fs); + T = 2; # sampling frequency of 2 Hz + W = 2/T*tan(pi*W/T); endif ## Generate splane poles and zeros for the chebyshev type 1 filter @@ -114,7 +114,7 @@ ## Use bilinear transform to convert poles to the z plane if digital - [zero, pole, gain] = bilinear(zero, pole, gain, Fs); + [zero, pole, gain] = bilinear(zero, pole, gain, T); endif ## convert to the correct output form Modified: trunk/octave-forge/main/signal/inst/cheby2.m =================================================================== --- trunk/octave-forge/main/signal/inst/cheby2.m 2008-10-25 09:09:50 UTC (rev 5385) +++ trunk/octave-forge/main/signal/inst/cheby2.m 2008-10-27 09:56:54 UTC (rev 5386) @@ -13,7 +13,7 @@ ## You should have received a copy of the GNU General Public License ## along with this program; If not, see <http://www.gnu.org/licenses/>. -## Generate an Chebyshev type II filter with Rs dB of stop band ripple. +## Generate an Chebyshev type II filter with Rs dB of stop band attenuation. ## ## [b, a] = cheby2(n, Rs, Wc) ## low pass filter with cutoff pi*Wc radians @@ -90,8 +90,8 @@ ## Prewarp to the band edges to s plane if digital - Fs = 2; # sampling frequency of 2 Hz - W = 2/Fs*tan(pi*W/Fs); + T = 2; # sampling frequency of 2 Hz + W = 2/T*tan(pi*W/T); endif ## Generate splane poles and zeros for the chebyshev type 2 filter @@ -123,7 +123,7 @@ ## Use bilinear transform to convert poles to the z plane if digital - [zero, pole, gain] = bilinear(zero, pole, gain, Fs); + [zero, pole, gain] = bilinear(zero, pole, gain, T); endif ## convert to the correct output form Modified: trunk/octave-forge/main/signal/inst/ellip.m =================================================================== --- trunk/octave-forge/main/signal/inst/ellip.m 2008-10-25 09:09:50 UTC (rev 5385) +++ trunk/octave-forge/main/signal/inst/ellip.m 2008-10-27 09:56:54 UTC (rev 5386) @@ -102,8 +102,8 @@ ##Prewarp the digital frequencies if digital - Fs = 2; # sampling frequency of 2 Hz - W = tan(pi*W/Fs); + T = 2; # sampling frequency of 2 Hz + W = tan(pi*W/T); endif ##Generate s-plane poles, zeros and gain @@ -114,7 +114,7 @@ ## Use bilinear transform to convert poles to the z plane if digital - [zero, pole, gain] = bilinear(zero, pole, gain, Fs); + [zero, pole, gain] = bilinear(zero, pole, gain, T); endif Modified: trunk/octave-forge/main/signal/inst/ellipord.m =================================================================== --- trunk/octave-forge/main/signal/inst/ellipord.m 2008-10-25 09:09:50 UTC (rev 5385) +++ trunk/octave-forge/main/signal/inst/ellipord.m 2008-10-27 09:56:54 UTC (rev 5386) @@ -55,10 +55,10 @@ # sampling frequency of 2 Hz -Fs = 2; +T = 2; -Wpw = tan(pi.*Wp./Fs); # prewarp -Wsw = tan(pi.*Ws./Fs); # prewarp +Wpw = tan(pi.*Wp./T); # prewarp +Wsw = tan(pi.*Ws./T); # prewarp ##pass/stop band to low pass filter transform: if (length(Wpw)==2 && length(Wsw)==2) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |