Mercurial > octave-nkf
annotate scripts/signal/freqz.m @ 20266:83792dd9bcc1
Use in-place operators in m-files where possible.
* scripts/audio/@audioplayer/set.m, scripts/audio/@audiorecorder/set.m,
scripts/audio/mu2lin.m, scripts/elfun/cosd.m, scripts/general/del2.m,
scripts/general/profexplore.m, scripts/general/quadl.m, scripts/general/rat.m,
scripts/general/rotdim.m, scripts/help/get_first_help_sentence.m,
scripts/help/private/__strip_html_tags__.m, scripts/image/cubehelix.m,
scripts/io/textread.m, scripts/linear-algebra/duplication_matrix.m,
scripts/linear-algebra/housh.m, scripts/linear-algebra/krylov.m,
scripts/linear-algebra/logm.m, scripts/linear-algebra/normest.m,
scripts/linear-algebra/onenormest.m, scripts/optimization/fminsearch.m,
scripts/optimization/lsqnonneg.m, scripts/optimization/qp.m,
scripts/plot/appearance/annotation.m, scripts/plot/appearance/axis.m,
scripts/plot/appearance/legend.m, scripts/plot/appearance/specular.m,
scripts/plot/draw/colorbar.m, scripts/plot/draw/hist.m,
scripts/plot/draw/plotmatrix.m, scripts/plot/draw/private/__stem__.m,
scripts/plot/util/__actual_axis_position__.m,
scripts/plot/util/__gnuplot_drawnow__.m, scripts/plot/util/findobj.m,
scripts/plot/util/print.m, scripts/plot/util/private/__go_draw_axes__.m,
scripts/plot/util/private/__print_parse_opts__.m, scripts/plot/util/rotate.m,
scripts/polynomial/pchip.m, scripts/polynomial/polyaffine.m,
scripts/polynomial/polyder.m, scripts/polynomial/private/__splinefit__.m,
scripts/polynomial/residue.m, scripts/signal/arch_fit.m,
scripts/signal/arch_rnd.m, scripts/signal/bartlett.m,
scripts/signal/blackman.m, scripts/signal/freqz.m, scripts/signal/hamming.m,
scripts/signal/hanning.m, scripts/signal/spectral_adf.m,
scripts/signal/spectral_xdf.m, scripts/signal/stft.m,
scripts/sparse/bicgstab.m, scripts/sparse/cgs.m,
scripts/sparse/private/__sprand_impl__.m, scripts/sparse/qmr.m,
scripts/sparse/sprandsym.m, scripts/sparse/svds.m, scripts/specfun/legendre.m,
scripts/special-matrix/gallery.m, scripts/statistics/base/gls.m,
scripts/statistics/models/logistic_regression.m,
scripts/statistics/tests/kruskal_wallis_test.m,
scripts/statistics/tests/manova.m, scripts/statistics/tests/wilcoxon_test.m,
scripts/time/datevec.m:
Use in-place operators in m-files where possible.
author | Rik <rik@octave.org> |
---|---|
date | Tue, 26 May 2015 21:07:42 -0700 |
parents | f1d0f506ee78 |
children |
rev | line source |
---|---|
19731
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19723
diff
changeset
|
1 ## Copyright (C) 1994-2015 John W. Eaton |
2313 | 2 ## |
3 ## This file is part of Octave. | |
4 ## | |
5 ## Octave is free software; you can redistribute it and/or modify it | |
6 ## under the terms of the GNU General Public License as published by | |
7016 | 7 ## the Free Software Foundation; either version 3 of the License, or (at |
8 ## your option) any later version. | |
2313 | 9 ## |
10 ## Octave is distributed in the hope that it will be useful, but | |
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 ## General Public License for more details. | |
14 ## | |
15 ## You should have received a copy of the GNU General Public License | |
7016 | 16 ## along with Octave; see the file COPYING. If not, see |
17 ## <http://www.gnu.org/licenses/>. | |
2303 | 18 |
3367 | 19 ## -*- texinfo -*- |
16491
b10a23fe80bb
doc: Tweak docstrings of functions changed for Texinfo 5.0 compatibility.
Rik <rik@octave.org>
parents:
16489
diff
changeset
|
20 ## @deftypefn {Function File} {[@var{h}, @var{w}] =} freqz (@var{b}, @var{a}, @var{n}, "whole") |
18453
9d59bc3dc12d
doc: Update docstrings for freqz, freqz_plot.
Rik <rik@octave.org>
parents:
18450
diff
changeset
|
21 ## @deftypefnx {Function File} {[@var{h}, @var{w}] =} freqz (@var{b}) |
9d59bc3dc12d
doc: Update docstrings for freqz, freqz_plot.
Rik <rik@octave.org>
parents:
18450
diff
changeset
|
22 ## @deftypefnx {Function File} {[@var{h}, @var{w}] =} freqz (@var{b}, @var{a}) |
9d59bc3dc12d
doc: Update docstrings for freqz, freqz_plot.
Rik <rik@octave.org>
parents:
18450
diff
changeset
|
23 ## @deftypefnx {Function File} {[@var{h}, @var{w}] =} freqz (@var{b}, @var{a}, @var{n}) |
16489
36dba9be680b
doc: Make documentation compatible with Texinfo 5.0 (bug #38392)
Amod Mulay <amodmulay1@gmail.com>
parents:
14363
diff
changeset
|
24 ## @deftypefnx {Function File} {@var{h} =} freqz (@var{b}, @var{a}, @var{w}) |
19722
8724af455b11
freqz.m: Add 1 more point to the plot output (bug #438950).
Doug Stewart <doug.dastew@gmail.com
parents:
19627
diff
changeset
|
25 ## @deftypefnx {Function File} {[@var{h}, @var{w}] =} freqz (@dots{}, @var{Fs}) |
16489
36dba9be680b
doc: Make documentation compatible with Texinfo 5.0 (bug #38392)
Amod Mulay <amodmulay1@gmail.com>
parents:
14363
diff
changeset
|
26 ## @deftypefnx {Function File} {} freqz (@dots{}) |
19627
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
18453
diff
changeset
|
27 ## |
3367 | 28 ## Return the complex frequency response @var{h} of the rational IIR filter |
29 ## whose numerator and denominator coefficients are @var{b} and @var{a}, | |
20200
f1d0f506ee78
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19867
diff
changeset
|
30 ## respectively. |
f1d0f506ee78
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19867
diff
changeset
|
31 ## |
f1d0f506ee78
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19867
diff
changeset
|
32 ## The response is evaluated at @var{n} angular frequencies between 0 and |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
8506
diff
changeset
|
33 ## @ifnottex |
18453
9d59bc3dc12d
doc: Update docstrings for freqz, freqz_plot.
Rik <rik@octave.org>
parents:
18450
diff
changeset
|
34 ## 2*pi. |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
8506
diff
changeset
|
35 ## @end ifnottex |
3367 | 36 ## @tex |
18453
9d59bc3dc12d
doc: Update docstrings for freqz, freqz_plot.
Rik <rik@octave.org>
parents:
18450
diff
changeset
|
37 ## $2\pi$. |
3367 | 38 ## @end tex |
3426 | 39 ## |
3367 | 40 ## @noindent |
41 ## The output value @var{w} is a vector of the frequencies. | |
3426 | 42 ## |
16491
b10a23fe80bb
doc: Tweak docstrings of functions changed for Texinfo 5.0 compatibility.
Rik <rik@octave.org>
parents:
16489
diff
changeset
|
43 ## If @var{a} is omitted, the denominator is assumed to be 1 (this |
b10a23fe80bb
doc: Tweak docstrings of functions changed for Texinfo 5.0 compatibility.
Rik <rik@octave.org>
parents:
16489
diff
changeset
|
44 ## corresponds to a simple FIR filter). |
b10a23fe80bb
doc: Tweak docstrings of functions changed for Texinfo 5.0 compatibility.
Rik <rik@octave.org>
parents:
16489
diff
changeset
|
45 ## |
20200
f1d0f506ee78
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19867
diff
changeset
|
46 ## If @var{n} is omitted, a value of 512 is assumed. For fastest computation, |
f1d0f506ee78
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19867
diff
changeset
|
47 ## @var{n} should factor into a small number of small primes. |
16491
b10a23fe80bb
doc: Tweak docstrings of functions changed for Texinfo 5.0 compatibility.
Rik <rik@octave.org>
parents:
16489
diff
changeset
|
48 ## |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16491
diff
changeset
|
49 ## If the fourth argument, @qcode{"whole"}, is omitted the response is |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16491
diff
changeset
|
50 ## evaluated at frequencies between 0 and |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
8506
diff
changeset
|
51 ## @ifnottex |
18453
9d59bc3dc12d
doc: Update docstrings for freqz, freqz_plot.
Rik <rik@octave.org>
parents:
18450
diff
changeset
|
52 ## pi. |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
8506
diff
changeset
|
53 ## @end ifnottex |
3367 | 54 ## @tex |
18453
9d59bc3dc12d
doc: Update docstrings for freqz, freqz_plot.
Rik <rik@octave.org>
parents:
18450
diff
changeset
|
55 ## $\pi$. |
3367 | 56 ## @end tex |
3426 | 57 ## |
16491
b10a23fe80bb
doc: Tweak docstrings of functions changed for Texinfo 5.0 compatibility.
Rik <rik@octave.org>
parents:
16489
diff
changeset
|
58 ## @code{freqz (@var{b}, @var{a}, @var{w})} |
3426 | 59 ## |
3893 | 60 ## Evaluate the response at the specific frequencies in the vector @var{w}. |
61 ## The values for @var{w} are measured in radians. | |
62 ## | |
16489
36dba9be680b
doc: Make documentation compatible with Texinfo 5.0 (bug #38392)
Amod Mulay <amodmulay1@gmail.com>
parents:
14363
diff
changeset
|
63 ## @code{[@dots{}] = freqz (@dots{}, @var{Fs})} |
16491
b10a23fe80bb
doc: Tweak docstrings of functions changed for Texinfo 5.0 compatibility.
Rik <rik@octave.org>
parents:
16489
diff
changeset
|
64 ## |
3893 | 65 ## Return frequencies in Hz instead of radians assuming a sampling rate |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
66 ## @var{Fs}. If you are evaluating the response at specific frequencies |
3893 | 67 ## @var{w}, those frequencies should be requested in Hz rather than radians. |
68 ## | |
16489
36dba9be680b
doc: Make documentation compatible with Texinfo 5.0 (bug #38392)
Amod Mulay <amodmulay1@gmail.com>
parents:
14363
diff
changeset
|
69 ## @code{freqz (@dots{})} |
16491
b10a23fe80bb
doc: Tweak docstrings of functions changed for Texinfo 5.0 compatibility.
Rik <rik@octave.org>
parents:
16489
diff
changeset
|
70 ## |
18453
9d59bc3dc12d
doc: Update docstrings for freqz, freqz_plot.
Rik <rik@octave.org>
parents:
18450
diff
changeset
|
71 ## Plot the magnitude and phase response of @var{h} rather than returning them. |
9d59bc3dc12d
doc: Update docstrings for freqz, freqz_plot.
Rik <rik@octave.org>
parents:
18450
diff
changeset
|
72 ## |
9d59bc3dc12d
doc: Update docstrings for freqz, freqz_plot.
Rik <rik@octave.org>
parents:
18450
diff
changeset
|
73 ## @seealso{freqz_plot} |
3367 | 74 ## @end deftypefn |
904 | 75 |
3367 | 76 ## Author: jwe ??? |
2314 | 77 |
5377 | 78 function [h_r, f_r] = freqz (b, a, n, region, Fs) |
566 | 79 |
3893 | 80 if (nargin < 1 || nargin > 5) |
6046 | 81 print_usage (); |
3893 | 82 elseif (nargin == 1) |
2303 | 83 ## Response of an FIR filter. |
3893 | 84 a = n = region = Fs = []; |
566 | 85 elseif (nargin == 2) |
2303 | 86 ## Response of an IIR filter |
3893 | 87 n = region = Fs = []; |
566 | 88 elseif (nargin == 3) |
3893 | 89 region = Fs = []; |
566 | 90 elseif (nargin == 4) |
3893 | 91 Fs = []; |
5443 | 92 if (! ischar (region) && ! isempty (region)) |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
93 Fs = region; |
3893 | 94 region = []; |
95 endif | |
96 endif | |
97 | |
5377 | 98 if (isempty (b)) |
99 b = 1; | |
19722
8724af455b11
freqz.m: Add 1 more point to the plot output (bug #438950).
Doug Stewart <doug.dastew@gmail.com
parents:
19627
diff
changeset
|
100 elseif (! isvector (b)) |
8724af455b11
freqz.m: Add 1 more point to the plot output (bug #438950).
Doug Stewart <doug.dastew@gmail.com
parents:
19627
diff
changeset
|
101 error ("freqz: B must be a vector"); |
5377 | 102 endif |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
103 if (isempty (a)) |
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
104 a = 1; |
19722
8724af455b11
freqz.m: Add 1 more point to the plot output (bug #438950).
Doug Stewart <doug.dastew@gmail.com
parents:
19627
diff
changeset
|
105 elseif (! isvector (a)) |
8724af455b11
freqz.m: Add 1 more point to the plot output (bug #438950).
Doug Stewart <doug.dastew@gmail.com
parents:
19627
diff
changeset
|
106 error ("freqz: A must be a vector"); |
3893 | 107 endif |
108 if (isempty (n)) | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
109 n = 512; |
19722
8724af455b11
freqz.m: Add 1 more point to the plot output (bug #438950).
Doug Stewart <doug.dastew@gmail.com
parents:
19627
diff
changeset
|
110 elseif (isscalar (n) && n < 1) |
8724af455b11
freqz.m: Add 1 more point to the plot output (bug #438950).
Doug Stewart <doug.dastew@gmail.com
parents:
19627
diff
changeset
|
111 error ("freqz: N must be a positive integer"); |
3893 | 112 endif |
113 if (isempty (region)) | |
114 if (isreal (b) && isreal (a)) | |
115 region = "half"; | |
116 else | |
117 region = "whole"; | |
118 endif | |
119 endif | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
120 if (isempty (Fs)) |
18450
694e8f0b3862
freqz: Make frequency response plot visually compatible with Matlab (bug #41464)
Mike Miller <mtmiller@ieee.org>
parents:
17744
diff
changeset
|
121 freq_norm = true; |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
122 if (nargout == 0) |
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
123 Fs = 2; |
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
124 else |
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
125 Fs = 2*pi; |
3893 | 126 endif |
18450
694e8f0b3862
freqz: Make frequency response plot visually compatible with Matlab (bug #41464)
Mike Miller <mtmiller@ieee.org>
parents:
17744
diff
changeset
|
127 else |
694e8f0b3862
freqz: Make frequency response plot visually compatible with Matlab (bug #41464)
Mike Miller <mtmiller@ieee.org>
parents:
17744
diff
changeset
|
128 freq_norm = false; |
566 | 129 endif |
19722
8724af455b11
freqz.m: Add 1 more point to the plot output (bug #438950).
Doug Stewart <doug.dastew@gmail.com
parents:
19627
diff
changeset
|
130 plot_output = (nargout == 0); |
8724af455b11
freqz.m: Add 1 more point to the plot output (bug #438950).
Doug Stewart <doug.dastew@gmail.com
parents:
19627
diff
changeset
|
131 whole_region = strcmp (region, "whole"); |
566 | 132 |
5583 | 133 a = a(:); |
134 b = b(:); | |
566 | 135 |
8506 | 136 if (! isscalar (n)) |
137 ## Explicit frequency vector given | |
5377 | 138 w = f = n; |
8506 | 139 if (nargin == 4) |
140 ## Sampling rate Fs was specified | |
5377 | 141 w = 2*pi*f/Fs; |
566 | 142 endif |
5986 | 143 k = max (length (b), length (a)); |
144 hb = polyval (postpad (b, k), exp (j*w)); | |
145 ha = polyval (postpad (a, k), exp (j*w)); | |
8667
a89198168175
freqz.m: freqz.m: fix for long input
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
146 else |
5583 | 147 ## polyval(fliplr(P),exp(jw)) is O(p n) and fft(x) is O(n log(n)), |
6653 | 148 ## where p is the order of the polynomial P. For small p it |
5377 | 149 ## would be faster to use polyval but in practice the overhead for |
150 ## polyval is much higher and the little bit of time saved isn't | |
151 ## worth the extra code. | |
8667
a89198168175
freqz.m: freqz.m: fix for long input
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
152 k = max (length (b), length (a)); |
a89198168175
freqz.m: freqz.m: fix for long input
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
153 if (k > n/2 && nargout == 0) |
a89198168175
freqz.m: freqz.m: fix for long input
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
154 ## Ensure a causal phase response. |
20266
83792dd9bcc1
Use in-place operators in m-files where possible.
Rik <rik@octave.org>
parents:
20200
diff
changeset
|
155 n *= 2 .^ ceil (log2 (2*k/n)); |
8667
a89198168175
freqz.m: freqz.m: fix for long input
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
156 endif |
a89198168175
freqz.m: freqz.m: fix for long input
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
157 |
19722
8724af455b11
freqz.m: Add 1 more point to the plot output (bug #438950).
Doug Stewart <doug.dastew@gmail.com
parents:
19627
diff
changeset
|
158 if (whole_region) |
8667
a89198168175
freqz.m: freqz.m: fix for long input
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
159 N = n; |
19722
8724af455b11
freqz.m: Add 1 more point to the plot output (bug #438950).
Doug Stewart <doug.dastew@gmail.com
parents:
19627
diff
changeset
|
160 if (plot_output) |
19723
894b5c5e0b92
Add missing semicolon to cset 8724af455b11.
Rik <rik@octave.org>
parents:
19722
diff
changeset
|
161 f = Fs * (0:n).' / N; # do 1 more for the plot |
19722
8724af455b11
freqz.m: Add 1 more point to the plot output (bug #438950).
Doug Stewart <doug.dastew@gmail.com
parents:
19627
diff
changeset
|
162 else |
8724af455b11
freqz.m: Add 1 more point to the plot output (bug #438950).
Doug Stewart <doug.dastew@gmail.com
parents:
19627
diff
changeset
|
163 f = Fs * (0:n-1).' / N; |
8724af455b11
freqz.m: Add 1 more point to the plot output (bug #438950).
Doug Stewart <doug.dastew@gmail.com
parents:
19627
diff
changeset
|
164 endif |
8667
a89198168175
freqz.m: freqz.m: fix for long input
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
165 else |
a89198168175
freqz.m: freqz.m: fix for long input
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
166 N = 2*n; |
19722
8724af455b11
freqz.m: Add 1 more point to the plot output (bug #438950).
Doug Stewart <doug.dastew@gmail.com
parents:
19627
diff
changeset
|
167 if (plot_output) |
8724af455b11
freqz.m: Add 1 more point to the plot output (bug #438950).
Doug Stewart <doug.dastew@gmail.com
parents:
19627
diff
changeset
|
168 n++; |
8724af455b11
freqz.m: Add 1 more point to the plot output (bug #438950).
Doug Stewart <doug.dastew@gmail.com
parents:
19627
diff
changeset
|
169 endif |
8724af455b11
freqz.m: Add 1 more point to the plot output (bug #438950).
Doug Stewart <doug.dastew@gmail.com
parents:
19627
diff
changeset
|
170 f = Fs * (0:n-1).' / N; |
8667
a89198168175
freqz.m: freqz.m: fix for long input
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
171 endif |
a89198168175
freqz.m: freqz.m: fix for long input
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
172 |
a89198168175
freqz.m: freqz.m: fix for long input
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
173 pad_sz = N*ceil (k/N); |
a89198168175
freqz.m: freqz.m: fix for long input
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
174 b = postpad (b, pad_sz); |
a89198168175
freqz.m: freqz.m: fix for long input
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
175 a = postpad (a, pad_sz); |
a89198168175
freqz.m: freqz.m: fix for long input
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
176 |
a89198168175
freqz.m: freqz.m: fix for long input
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
177 hb = zeros (n, 1); |
a89198168175
freqz.m: freqz.m: fix for long input
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
178 ha = zeros (n, 1); |
a89198168175
freqz.m: freqz.m: fix for long input
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
179 |
a89198168175
freqz.m: freqz.m: fix for long input
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
180 for i = 1:N:pad_sz |
20266
83792dd9bcc1
Use in-place operators in m-files where possible.
Rik <rik@octave.org>
parents:
20200
diff
changeset
|
181 hb += fft (postpad (b(i:i+N-1), N))(1:n); |
83792dd9bcc1
Use in-place operators in m-files where possible.
Rik <rik@octave.org>
parents:
20200
diff
changeset
|
182 ha += fft (postpad (a(i:i+N-1), N))(1:n); |
8667
a89198168175
freqz.m: freqz.m: fix for long input
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
183 endfor |
a89198168175
freqz.m: freqz.m: fix for long input
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
184 |
566 | 185 endif |
186 | |
3893 | 187 h = hb ./ ha; |
188 | |
19722
8724af455b11
freqz.m: Add 1 more point to the plot output (bug #438950).
Doug Stewart <doug.dastew@gmail.com
parents:
19627
diff
changeset
|
189 if (plot_output) |
8724af455b11
freqz.m: Add 1 more point to the plot output (bug #438950).
Doug Stewart <doug.dastew@gmail.com
parents:
19627
diff
changeset
|
190 ## Plot and don't return values. |
8724af455b11
freqz.m: Add 1 more point to the plot output (bug #438950).
Doug Stewart <doug.dastew@gmail.com
parents:
19627
diff
changeset
|
191 if (whole_region) |
8724af455b11
freqz.m: Add 1 more point to the plot output (bug #438950).
Doug Stewart <doug.dastew@gmail.com
parents:
19627
diff
changeset
|
192 h(end+1) = h(1); # Solution is periodic. Copy first value to end. |
8724af455b11
freqz.m: Add 1 more point to the plot output (bug #438950).
Doug Stewart <doug.dastew@gmail.com
parents:
19627
diff
changeset
|
193 endif |
8724af455b11
freqz.m: Add 1 more point to the plot output (bug #438950).
Doug Stewart <doug.dastew@gmail.com
parents:
19627
diff
changeset
|
194 freqz_plot (f, h, freq_norm); |
8724af455b11
freqz.m: Add 1 more point to the plot output (bug #438950).
Doug Stewart <doug.dastew@gmail.com
parents:
19627
diff
changeset
|
195 else |
8506 | 196 ## Return values and don't plot. |
3907 | 197 h_r = h; |
5377 | 198 f_r = f; |
7151 | 199 endif |
3907 | 200 |
566 | 201 endfunction |
5377 | 202 |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
203 |
5377 | 204 %!test # correct values and fft-polyval consistency |
17336
b81b9d079515
Use '##' for comments which stand alone on a line.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
205 %! ## butterworth filter, order 2, cutoff pi/2 radians |
5377 | 206 %! b = [0.292893218813452 0.585786437626905 0.292893218813452]; |
207 %! a = [1 0 0.171572875253810]; | |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
208 %! [h,w] = freqz (b,a,32); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
209 %! assert (h(1),1,10*eps); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
210 %! assert (abs (h(17)).^2,0.5,10*eps); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
211 %! assert (h,freqz (b,a,w),10*eps); # fft should be consistent with polyval |
5377 | 212 |
213 %!test # whole-half consistency | |
214 %! b = [1 1 1]/3; # 3-sample average | |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
215 %! [h,w] = freqz (b,1,32,"whole"); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
216 %! assert (h(2:16),conj (h(32:-1:18)),20*eps); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
217 %! [h2,w2] = freqz (b,1,16,"half"); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
218 %! assert (h(1:16),h2,20*eps); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
219 %! assert (w(1:16),w2,20*eps); |
5377 | 220 |
221 %!test # Sampling frequency properly interpreted | |
5986 | 222 %! b = [1 1 1]/3; a = [1 0.2]; |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
223 %! [h,f] = freqz (b,a,16,320); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
224 %! assert (f,[0:15]'*10,10*eps); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
225 %! [h2,f2] = freqz (b,a,[0:15]*10,320); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
226 %! assert (f2,[0:15]*10,10*eps); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
227 %! assert (h,h2.',20*eps); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
228 %! [h3,f3] = freqz (b,a,32,"whole",320); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
229 %! assert (f3,[0:31]'*10,10*eps); |
17338
1c89599167a6
maint: End m-files with 1 blank line.
Rik <rik@octave.org>
parents:
17336
diff
changeset
|
230 |
19867
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19731
diff
changeset
|
231 ## Test input validation |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19731
diff
changeset
|
232 ## FIXME: Need to put tests here and simplify input validation in the main code. |
19722
8724af455b11
freqz.m: Add 1 more point to the plot output (bug #438950).
Doug Stewart <doug.dastew@gmail.com
parents:
19627
diff
changeset
|
233 |