From fmiyara at fceia.unr.edu.ar Wed Jul 20 22:47:14 2022 From: fmiyara at fceia.unr.edu.ar (Federico Miyara) Date: Wed, 20 Jul 2022 17:47:14 -0300 Subject: [Scilab-users] Unexpected result using horner Message-ID: <42eb40da-529c-3101-77aa-8237ce959bc5@fceia.unr.edu.ar> Dear All, I have problems with this script: Fs = 44100; fo = 500; B = 2^(1/6)-2^(-1/6); // Low-pass Butterworth hLPs = analpf(3,"butt",[],1); // Band-pass Butterworth centered at fo hBPs = horner(hLPs, (2*%pi*fo/%s + %s/(2*%pi*fo))/B) // Apply bilinear transform hBPz = horner(hBPs, 2*Fs*(%z - 1)/(%z + 1)) // Attempt to get the same using iir hBPz1 = iir(3, "bp", "butt", fo/Fs*[2^(1/6),2^(-1/6)], [0 0]) I attempt to design a discrete Butterworth band-pass filter using two equivalent methods: 1) Manually applying a bilinear transform to the analog filter designed with analpf() 2) Applying the function iir() For some resaon I couldn't figure out, the first method yields an unexpected result: --> hBPz ?hBPz? = ?? 0.0000005 +0.0000016z +0.0000016z? +0.0000005z? ?? ----------------------------------------------- ?????? -0.9671578 +2.9195957z -2.9518237z? +z? --> hBPz1 ?hBPz1? = ???????????????? 0.0000006 -0.0000017z? +0.0000017z? -0.0000006z? ----------------------------------------------------------------------------- ?? 1.0335428 -6.1515162z +15.271063z? -20.239437z? +15.104038z? -6.0176897z? +z? The official function iir() is correct. The manual procedure unexpectedly reduces the order of the denominator. Maybe someone can find out what's going on... Thanks, Federico Miyara -- El software de antivirus Avast ha analizado este correo electr?nico en busca de virus. https://www.avast.com/antivirus -------------- next part -------------- An HTML attachment was scrubbed... URL: From sgougeon at free.fr Sun Jul 24 13:34:10 2022 From: sgougeon at free.fr (Samuel Gougeon) Date: Sun, 24 Jul 2022 13:34:10 +0200 Subject: [Scilab-users] Unexpected result using horner In-Reply-To: <42eb40da-529c-3101-77aa-8237ce959bc5@fceia.unr.edu.ar> References: <42eb40da-529c-3101-77aa-8237ce959bc5@fceia.unr.edu.ar> Message-ID: Hello Federico, Le 20/07/2022 ? 22:47, Federico Miyara a ?crit?: > > Dear All, > > I have problems with this script: > Fs = 44100; > fo = 500; > B = 2^(1/6)-2^(-1/6); > // Low-pass Butterworth > hLPs = analpf(3,"butt",[],1); > // Band-pass Butterworth centered at fo > hBPs = horner(hLPs, (2*%pi*fo/%s + %s/(2*%pi*fo))/B) > // Apply bilinear transform > hBPz = horner(hBPs, 2*Fs*(%z - 1)/(%z + 1)) > // Attempt to get the same using iir > hBPz1 = iir(3, "bp", "butt", fo/Fs*[2^(1/6),2^(-1/6)], [0 0]) > I attempt to design a discrete Butterworth band-pass filter using two > equivalent methods: > > 1) Manually applying a bilinear transform to the analog filter > designed with analpf() > 2) Applying the function iir() > > For some resaon I couldn't figure out, the first method yields an > unexpected result: > > --> hBPz > ?hBPz? = > ?? 0.0000005 +0.0000016z +0.0000016z? +0.0000005z? > ?? ----------------------------------------------- > ?????? -0.9671578 +2.9195957z -2.9518237z? +z? > > --> hBPz1 > ?hBPz1? = > ???????????????? 0.0000006 -0.0000017z? +0.0000017z? -0.0000006z? > ----------------------------------------------------------------------------- > > ?? 1.0335428 -6.1515162z +15.271063z? -20.239437z? +15.104038z? > -6.0176897z? +z? > > The official function iir() is correct. The manual procedure > unexpectedly reduces the order of the denominator. > > Maybe someone can find out what's going on... Sorry, but nothing is clear to me about your statements: 1) what shows you that iir() is correct while the analpf + horner way is not? 2) With the analpf + horner method, assuming that it is not correct, what shows you that horner is not correct, while analpf is correct, instead of the opposite or both incorrect? 3) do you have a reference about the equivalence? 4) have you tried after simp_mode(%f)? Samuel -------------- next part -------------- An HTML attachment was scrubbed... URL: From sgougeon at free.fr Sun Jul 24 13:42:08 2022 From: sgougeon at free.fr (Samuel Gougeon) Date: Sun, 24 Jul 2022 13:42:08 +0200 Subject: [Scilab-users] Unexpected result using horner In-Reply-To: References: <42eb40da-529c-3101-77aa-8237ce959bc5@fceia.unr.edu.ar> Message-ID: <2807ed37-cdf5-e144-fc91-678913b2797f@free.fr> Le 24/07/2022 ? 13:34, Samuel Gougeon a ?crit?: > > Sorry, but nothing is clear to me about your statements: > > 1) what shows you that iir() is correct while the analpf + horner way > is not? > > 2) With the analpf + horner method, assuming that it is not correct, > what shows you that horner is not correct, while analpf is correct, > instead of the opposite or both incorrect? > > 3) do you have a reference about the equivalence? > > 4) have you tried after simp_mode(%f)? > By the way, you may edit iir(). You will see that it uses analpf() as well, plus bilt() and trans() instead of (directly) horner. Then editing bilt and trans show a lot of code... From fmiyara at fceia.unr.edu.ar Mon Jul 25 02:44:46 2022 From: fmiyara at fceia.unr.edu.ar (Federico Miyara) Date: Sun, 24 Jul 2022 21:44:46 -0300 Subject: [Scilab-users] Unexpected result using horner In-Reply-To: References: <42eb40da-529c-3101-77aa-8237ce959bc5@fceia.unr.edu.ar> Message-ID: <8384eff2-75e0-ed6b-6bf4-31e02d072c88@fceia.unr.edu.ar> Samuel, > Sorry, but nothing is clear to me about your statements: > > 1) what shows you that iir() is correct while the analpf + horner way > is not? There are several reasons: a) The result of using iir() is consistent with the expected frequency response, since it is equal to the analog filter response except at high frequency, an expected artifact for IIR filters. The other solution is completely different. b) The degree of the denominator should be 6 but when using horner it reduces to 3. My own informal and not very deep analysis suggests that as all the poles are very close to unity, may be horner() performs some simplification and simplifies things incorrectly, which might dramatically change the frequency response. > 2) With the analpf + horner method, assuming that it is not correct, > what shows you that horner is not correct, while analpf is correct, > instead of the opposite or both incorrect? analpf() is a very simple algorithm, at least for Butterworth, since explicit formulas for the poles exist and in all the cases I have tested the result is the expected one, particularly in this case. > 3) do you have a reference about the equivalence? The substitution of the bilinear transformation is the usual method to get an IIR digital filter from an analog prototype. They aren't completely equivalent, but very similar up to about half Nyquist frequency. Any book on digital signal processing includes that transformation. Also https://en.wikipedia.org/wiki/Bilinear_transform > 4) have you tried after simp_mode(%f)? No, but this might be the answer considering my reply to 2). I'll try it later. Thanks. Regerds, Federico Miyara > Samuel > > > _______________________________________________ > users mailing list > users at lists.scilab.org > http://lists.scilab.org/mailman/listinfo/users -- El software de antivirus Avast ha analizado este correo electr?nico en busca de virus. https://www.avast.com/antivirus -------------- next part -------------- An HTML attachment was scrubbed... URL: From sgougeon at free.fr Mon Jul 25 12:21:13 2022 From: sgougeon at free.fr (Samuel Gougeon) Date: Mon, 25 Jul 2022 12:21:13 +0200 Subject: [Scilab-users] Unexpected result using horner In-Reply-To: <8384eff2-75e0-ed6b-6bf4-31e02d072c88@fceia.unr.edu.ar> References: <42eb40da-529c-3101-77aa-8237ce959bc5@fceia.unr.edu.ar> <8384eff2-75e0-ed6b-6bf4-31e02d072c88@fceia.unr.edu.ar> Message-ID: Le 25/07/2022 ? 02:44, Federico Miyara a ?crit?: > > Samuel, > >> Sorry, but nothing is clear to me about your statements: >> >> 1) what shows you that iir() is correct while the analpf + horner way >> is not? > > There are several reasons: > > a) The result of using iir() is consistent with the expected frequency > response, since it is equal to the analog filter response except at > high frequency, an expected artifact for IIR filters. The other > solution is completely different. > > b) The degree of the denominator should be 6 but when using horner it > reduces to 3. > > My own informal and not very deep analysis suggests that as all the > poles are very close to unity, may be horner() performs some > simplification and simplifies things incorrectly, which might > dramatically change the frequency response. > >> 2) With the analpf + horner method, assuming that it is not correct, >> what shows you that horner is not correct, while analpf is correct, >> instead of the opposite or both incorrect? > > analpf() is a very simple algorithm, at least for Butterworth, since > explicit formulas for the poles exist and in all the cases I have > tested the result is the expected one, particularly in this case. > >> 3) do you have a reference about the equivalence? > > The substitution of the bilinear transformation is the usual method to > get an IIR digital filter from an analog prototype. They aren't > completely equivalent, but very similar up to about half Nyquist > frequency. Any book on digital signal processing includes that > transformation. Also https://en.wikipedia.org/wiki/Bilinear_transform > >> 4) have you tried after simp_mode(%f)? > > No, but this might be the answer considering my reply to 2). I'll try > it later. To get equivalent transfer functions, you need a) indeed to turn simp_mode(%f), b) to run hBPz1= iir(3, "bp", "butt", fo/Fs*[2^(-1/6), 2^(1/6)], [0 0]) instead of hBPz1= iir(3, "bp", "butt", fo/Fs*[2^(1/6),2^(-1/6)], [0 0]) Then the curves of both transfer functions are superimposed. clf, plot(linspace(0.5,1.5,100), [hBPsz, hBPz1]) When working with polynomials or rationals, one must keep in mind that every time that their roots or/and poles have close values, then results become very sensitive to numerical round-off errors or uncertainties. The roots of a polynomial of degree N can't be computed from its coefficients with a numerical relative accuracy better than %eps^(1/N). If this uncertainty becomes bigger than the distance between roots values, then things become really bad. Samuel -------------- next part -------------- An HTML attachment was scrubbed... URL: From j.s.strom at hslmg.de Thu Jul 28 23:06:58 2022 From: j.s.strom at hslmg.de (Jens Simon Strom) Date: Thu, 28 Jul 2022 23:06:58 +0200 Subject: [Scilab-users] Problem with ticks Message-ID: <50740198-f0ef-3fff-5f05-73f2c9252d0e@hslmg.de> Hi, The code below works in version 6.1.0. But after replacing the ticks configuration by the commented one it fails. What is wrong there? Regards Jens T=15:200; P=9600../T; xdel() plot(T,P) ca=gca(); ca.grid=[1 1]; xtitle('$P=\frac{9600}{T}$'); t=ca.title; t.font_size=5; ca.x_ticks.locations=[0:20:200]'; ca.x_ticks.labels=string(ca.x_ticks.locations) ca.y_ticks.locations=[0:100:700]'; ca.y_ticks.labels=string(ca.y_ticks.locations) //ca.x_ticks.locations=[0:10:200]'; //ca.x_ticks.labels=string(ca.x_ticks.locations) //ca.y_ticks.locations=[0:50:700]'; //ca.y_ticks.labels=string(ca.y_ticks.locations) -------------- next part -------------- An HTML attachment was scrubbed... URL: