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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
2 ##
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
3 ## This file is part of Octave.
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
4 ##
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
6 ## under the terms of the GNU General Public License as published by
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6653
diff changeset
7 ## the Free Software Foundation; either version 3 of the License, or (at
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6653
diff changeset
8 ## your option) any later version.
2313
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
9 ##
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
13 ## General Public License for more details.
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
14 ##
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
15 ## You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6653
diff changeset
16 ## along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6653
diff changeset
17 ## <http://www.gnu.org/licenses/>.
2303
5cffc4b8de57 [project @ 1996-06-24 09:15:24 by jwe]
jwe
parents: 1337
diff changeset
18
3367
0748b03c3510 [project @ 1999-11-20 14:52:38 by jwe]
jwe
parents: 2847
diff changeset
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
0748b03c3510 [project @ 1999-11-20 14:52:38 by jwe]
jwe
parents: 2847
diff changeset
28 ## Return the complex frequency response @var{h} of the rational IIR filter
0748b03c3510 [project @ 1999-11-20 14:52:38 by jwe]
jwe
parents: 2847
diff changeset
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
0748b03c3510 [project @ 1999-11-20 14:52:38 by jwe]
jwe
parents: 2847
diff changeset
36 ## @tex
18453
9d59bc3dc12d doc: Update docstrings for freqz, freqz_plot.
Rik <rik@octave.org>
parents: 18450
diff changeset
37 ## $2\pi$.
3367
0748b03c3510 [project @ 1999-11-20 14:52:38 by jwe]
jwe
parents: 2847
diff changeset
38 ## @end tex
3426
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3367
diff changeset
39 ##
3367
0748b03c3510 [project @ 1999-11-20 14:52:38 by jwe]
jwe
parents: 2847
diff changeset
40 ## @noindent
0748b03c3510 [project @ 1999-11-20 14:52:38 by jwe]
jwe
parents: 2847
diff changeset
41 ## The output value @var{w} is a vector of the frequencies.
3426
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3367
diff changeset
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
0748b03c3510 [project @ 1999-11-20 14:52:38 by jwe]
jwe
parents: 2847
diff changeset
54 ## @tex
18453
9d59bc3dc12d doc: Update docstrings for freqz, freqz_plot.
Rik <rik@octave.org>
parents: 18450
diff changeset
55 ## $\pi$.
3367
0748b03c3510 [project @ 1999-11-20 14:52:38 by jwe]
jwe
parents: 2847
diff changeset
56 ## @end tex
3426
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3367
diff changeset
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
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3367
diff changeset
59 ##
3893
abd8659eea11 [project @ 2002-04-09 21:36:31 by jwe]
jwe
parents: 3457
diff changeset
60 ## Evaluate the response at the specific frequencies in the vector @var{w}.
abd8659eea11 [project @ 2002-04-09 21:36:31 by jwe]
jwe
parents: 3457
diff changeset
61 ## The values for @var{w} are measured in radians.
abd8659eea11 [project @ 2002-04-09 21:36:31 by jwe]
jwe
parents: 3457
diff changeset
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
abd8659eea11 [project @ 2002-04-09 21:36:31 by jwe]
jwe
parents: 3457
diff changeset
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
abd8659eea11 [project @ 2002-04-09 21:36:31 by jwe]
jwe
parents: 3457
diff changeset
67 ## @var{w}, those frequencies should be requested in Hz rather than radians.
abd8659eea11 [project @ 2002-04-09 21:36:31 by jwe]
jwe
parents: 3457
diff changeset
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
0748b03c3510 [project @ 1999-11-20 14:52:38 by jwe]
jwe
parents: 2847
diff changeset
74 ## @end deftypefn
904
3470f1e25a79 [project @ 1994-11-09 21:22:15 by jwe]
jwe
parents: 566
diff changeset
75
3367
0748b03c3510 [project @ 1999-11-20 14:52:38 by jwe]
jwe
parents: 2847
diff changeset
76 ## Author: jwe ???
2314
949ab8eba8bc [project @ 1996-07-12 03:58:02 by jwe]
jwe
parents: 2313
diff changeset
77
5377
bd4ee620c38a [project @ 2005-06-02 15:42:39 by jwe]
jwe
parents: 5307
diff changeset
78 function [h_r, f_r] = freqz (b, a, n, region, Fs)
566
8529a21443fa [project @ 1994-07-26 02:07:38 by jwe]
jwe
parents:
diff changeset
79
3893
abd8659eea11 [project @ 2002-04-09 21:36:31 by jwe]
jwe
parents: 3457
diff changeset
80 if (nargin < 1 || nargin > 5)
6046
34f96dd5441b [project @ 2006-10-10 16:10:25 by jwe]
jwe
parents: 5986
diff changeset
81 print_usage ();
3893
abd8659eea11 [project @ 2002-04-09 21:36:31 by jwe]
jwe
parents: 3457
diff changeset
82 elseif (nargin == 1)
2303
5cffc4b8de57 [project @ 1996-06-24 09:15:24 by jwe]
jwe
parents: 1337
diff changeset
83 ## Response of an FIR filter.
3893
abd8659eea11 [project @ 2002-04-09 21:36:31 by jwe]
jwe
parents: 3457
diff changeset
84 a = n = region = Fs = [];
566
8529a21443fa [project @ 1994-07-26 02:07:38 by jwe]
jwe
parents:
diff changeset
85 elseif (nargin == 2)
2303
5cffc4b8de57 [project @ 1996-06-24 09:15:24 by jwe]
jwe
parents: 1337
diff changeset
86 ## Response of an IIR filter
3893
abd8659eea11 [project @ 2002-04-09 21:36:31 by jwe]
jwe
parents: 3457
diff changeset
87 n = region = Fs = [];
566
8529a21443fa [project @ 1994-07-26 02:07:38 by jwe]
jwe
parents:
diff changeset
88 elseif (nargin == 3)
3893
abd8659eea11 [project @ 2002-04-09 21:36:31 by jwe]
jwe
parents: 3457
diff changeset
89 region = Fs = [];
566
8529a21443fa [project @ 1994-07-26 02:07:38 by jwe]
jwe
parents:
diff changeset
90 elseif (nargin == 4)
3893
abd8659eea11 [project @ 2002-04-09 21:36:31 by jwe]
jwe
parents: 3457
diff changeset
91 Fs = [];
5443
ec8c33dcd1bf [project @ 2005-09-08 01:40:57 by jwe]
jwe
parents: 5378
diff changeset
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
abd8659eea11 [project @ 2002-04-09 21:36:31 by jwe]
jwe
parents: 3457
diff changeset
94 region = [];
abd8659eea11 [project @ 2002-04-09 21:36:31 by jwe]
jwe
parents: 3457
diff changeset
95 endif
abd8659eea11 [project @ 2002-04-09 21:36:31 by jwe]
jwe
parents: 3457
diff changeset
96 endif
abd8659eea11 [project @ 2002-04-09 21:36:31 by jwe]
jwe
parents: 3457
diff changeset
97
5377
bd4ee620c38a [project @ 2005-06-02 15:42:39 by jwe]
jwe
parents: 5307
diff changeset
98 if (isempty (b))
bd4ee620c38a [project @ 2005-06-02 15:42:39 by jwe]
jwe
parents: 5307
diff changeset
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
bd4ee620c38a [project @ 2005-06-02 15:42:39 by jwe]
jwe
parents: 5307
diff changeset
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
abd8659eea11 [project @ 2002-04-09 21:36:31 by jwe]
jwe
parents: 3457
diff changeset
107 endif
abd8659eea11 [project @ 2002-04-09 21:36:31 by jwe]
jwe
parents: 3457
diff changeset
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
abd8659eea11 [project @ 2002-04-09 21:36:31 by jwe]
jwe
parents: 3457
diff changeset
112 endif
abd8659eea11 [project @ 2002-04-09 21:36:31 by jwe]
jwe
parents: 3457
diff changeset
113 if (isempty (region))
abd8659eea11 [project @ 2002-04-09 21:36:31 by jwe]
jwe
parents: 3457
diff changeset
114 if (isreal (b) && isreal (a))
abd8659eea11 [project @ 2002-04-09 21:36:31 by jwe]
jwe
parents: 3457
diff changeset
115 region = "half";
abd8659eea11 [project @ 2002-04-09 21:36:31 by jwe]
jwe
parents: 3457
diff changeset
116 else
abd8659eea11 [project @ 2002-04-09 21:36:31 by jwe]
jwe
parents: 3457
diff changeset
117 region = "whole";
abd8659eea11 [project @ 2002-04-09 21:36:31 by jwe]
jwe
parents: 3457
diff changeset
118 endif
abd8659eea11 [project @ 2002-04-09 21:36:31 by jwe]
jwe
parents: 3457
diff changeset
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
abd8659eea11 [project @ 2002-04-09 21:36:31 by jwe]
jwe
parents: 3457
diff changeset
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
8529a21443fa [project @ 1994-07-26 02:07:38 by jwe]
jwe
parents:
diff changeset
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
8529a21443fa [project @ 1994-07-26 02:07:38 by jwe]
jwe
parents:
diff changeset
132
5583
8eebdcfde94e [project @ 2005-12-15 01:16:26 by jwe]
jwe
parents: 5443
diff changeset
133 a = a(:);
8eebdcfde94e [project @ 2005-12-15 01:16:26 by jwe]
jwe
parents: 5443
diff changeset
134 b = b(:);
566
8529a21443fa [project @ 1994-07-26 02:07:38 by jwe]
jwe
parents:
diff changeset
135
8506
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 7151
diff changeset
136 if (! isscalar (n))
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 7151
diff changeset
137 ## Explicit frequency vector given
5377
bd4ee620c38a [project @ 2005-06-02 15:42:39 by jwe]
jwe
parents: 5307
diff changeset
138 w = f = n;
8506
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 7151
diff changeset
139 if (nargin == 4)
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 7151
diff changeset
140 ## Sampling rate Fs was specified
5377
bd4ee620c38a [project @ 2005-06-02 15:42:39 by jwe]
jwe
parents: 5307
diff changeset
141 w = 2*pi*f/Fs;
566
8529a21443fa [project @ 1994-07-26 02:07:38 by jwe]
jwe
parents:
diff changeset
142 endif
5986
14078139f941 [project @ 2006-09-12 02:46:33 by jwe]
jwe
parents: 5583
diff changeset
143 k = max (length (b), length (a));
14078139f941 [project @ 2006-09-12 02:46:33 by jwe]
jwe
parents: 5583
diff changeset
144 hb = polyval (postpad (b, k), exp (j*w));
14078139f941 [project @ 2006-09-12 02:46:33 by jwe]
jwe
parents: 5583
diff changeset
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
8eebdcfde94e [project @ 2005-12-15 01:16:26 by jwe]
jwe
parents: 5443
diff changeset
147 ## polyval(fliplr(P),exp(jw)) is O(p n) and fft(x) is O(n log(n)),
6653
673686daec87 [project @ 2007-05-22 15:36:09 by jwe]
jwe
parents: 6046
diff changeset
148 ## where p is the order of the polynomial P. For small p it
5377
bd4ee620c38a [project @ 2005-06-02 15:42:39 by jwe]
jwe
parents: 5307
diff changeset
149 ## would be faster to use polyval but in practice the overhead for
bd4ee620c38a [project @ 2005-06-02 15:42:39 by jwe]
jwe
parents: 5307
diff changeset
150 ## polyval is much higher and the little bit of time saved isn't
bd4ee620c38a [project @ 2005-06-02 15:42:39 by jwe]
jwe
parents: 5307
diff changeset
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
8529a21443fa [project @ 1994-07-26 02:07:38 by jwe]
jwe
parents:
diff changeset
185 endif
8529a21443fa [project @ 1994-07-26 02:07:38 by jwe]
jwe
parents:
diff changeset
186
3893
abd8659eea11 [project @ 2002-04-09 21:36:31 by jwe]
jwe
parents: 3457
diff changeset
187 h = hb ./ ha;
abd8659eea11 [project @ 2002-04-09 21:36:31 by jwe]
jwe
parents: 3457
diff changeset
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
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 7151
diff changeset
196 ## Return values and don't plot.
3907
437884fae441 [project @ 2002-04-24 19:33:08 by jwe]
jwe
parents: 3893
diff changeset
197 h_r = h;
5377
bd4ee620c38a [project @ 2005-06-02 15:42:39 by jwe]
jwe
parents: 5307
diff changeset
198 f_r = f;
7151
aeeb646f6538 [project @ 2007-11-09 19:34:17 by jwe]
jwe
parents: 7017
diff changeset
199 endif
3907
437884fae441 [project @ 2002-04-24 19:33:08 by jwe]
jwe
parents: 3893
diff changeset
200
566
8529a21443fa [project @ 1994-07-26 02:07:38 by jwe]
jwe
parents:
diff changeset
201 endfunction
5377
bd4ee620c38a [project @ 2005-06-02 15:42:39 by jwe]
jwe
parents: 5307
diff changeset
202
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
203
5377
bd4ee620c38a [project @ 2005-06-02 15:42:39 by jwe]
jwe
parents: 5307
diff changeset
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
bd4ee620c38a [project @ 2005-06-02 15:42:39 by jwe]
jwe
parents: 5307
diff changeset
206 %! b = [0.292893218813452 0.585786437626905 0.292893218813452];
bd4ee620c38a [project @ 2005-06-02 15:42:39 by jwe]
jwe
parents: 5307
diff changeset
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
bd4ee620c38a [project @ 2005-06-02 15:42:39 by jwe]
jwe
parents: 5307
diff changeset
212
bd4ee620c38a [project @ 2005-06-02 15:42:39 by jwe]
jwe
parents: 5307
diff changeset
213 %!test # whole-half consistency
bd4ee620c38a [project @ 2005-06-02 15:42:39 by jwe]
jwe
parents: 5307
diff changeset
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
bd4ee620c38a [project @ 2005-06-02 15:42:39 by jwe]
jwe
parents: 5307
diff changeset
220
bd4ee620c38a [project @ 2005-06-02 15:42:39 by jwe]
jwe
parents: 5307
diff changeset
221 %!test # Sampling frequency properly interpreted
5986
14078139f941 [project @ 2006-09-12 02:46:33 by jwe]
jwe
parents: 5583
diff changeset
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