# HG changeset patch # User jwe # Date 1018388191 0 # Node ID abd8659eea11a59cbb621d4840b79946c7b016e0 # Parent 56db014d89803d4a59c0d6211984d69bd047642b [project @ 2002-04-09 21:36:31 by jwe] diff --git a/doc/interpreter/strings.txi b/doc/interpreter/strings.txi --- a/doc/interpreter/strings.txi +++ b/doc/interpreter/strings.txi @@ -63,6 +63,9 @@ @item \' Represents a literal single-quote character, @samp{'}. +@item \0 +Represents the ``nul'' character, control-@, ASCII code 0. + @item \a Represents the ``alert'' character, control-g, ASCII code 7. diff --git a/scripts/ChangeLog b/scripts/ChangeLog --- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,3 +1,8 @@ +2002-04-09 Paul Kienzle + + * scripts/freqz.m: Evaluate a specific range of frequencies + expressed in radians or Hz relative to a supplied sample rate. + 2002-04-04 Paul Kienzle * signal/fftfilt.m: Filter columns if called with a matrix. diff --git a/scripts/signal/freqz.m b/scripts/signal/freqz.m --- a/scripts/signal/freqz.m +++ b/scripts/signal/freqz.m @@ -53,55 +53,104 @@ ## ## For fastest computation, @var{n} should factor into a small number of ## small primes. +## +## @deftypefnx {Function File} {@var{h} =} freqz (@var{b}, @var{a}, @var{w}) +## Evaluate the response at the specific frequencies in the vector @var{w}. +## The values for @var{w} are measured in radians. +## +## @deftypefnx {Function File} {[@dots{}] =} freqz (@dots{}, @var{Fs}) +## Return frequencies in Hz instead of radians assuming a sampling rate +## @var{Fs}. If you are evaluating the response at specific frequencies +## @var{w}, those frequencies should be requested in Hz rather than radians. +## ## @end deftypefn ## Author: jwe ??? -function [h, w] = freqz(b,...) +function [h, w] = freqz (b, a, n, region, Fs) - if (nargin == 1) + if (nargin < 1 || nargin > 5) + usage ("[h, w] = freqz (b, a, n [, \"whole\"] [, Fs])"); + elseif (nargin == 1) ## Response of an FIR filter. - a = 1; - n = 512; - region = "half"; + a = n = region = Fs = []; elseif (nargin == 2) ## Response of an IIR filter - a = va_arg(); - n = 512; - region = "half"; + n = region = Fs = []; elseif (nargin == 3) - a = va_arg(); - n = va_arg(); - region = "half"; + region = Fs = []; elseif (nargin == 4) - a = va_arg(); - n = va_arg(); - region = va_arg(); + Fs = []; + if (! isstr (region) && ! isempty (region)) + Fs = region; + region = []; + endif + endif + + if (isempty (a)) + a = 1; + endif + if (isempty (n)) + n = 512; + endif + if (isempty (region)) + if (isreal (b) && isreal (a)) + region = "half"; + else + region = "whole"; + endif + endif + if (isempty (Fs)) + if (nargout == 0) + Fs = 2; + else + Fs = 2*pi; + endif endif - la = length(a); - a = reshape(a,1,la); - lb = length(b); - b = reshape(b,1,lb); + la = length (a); + a = reshape (a, 1, la); + lb = length (b); + b = reshape (b, 1, lb); + k = max ([la, lb]); - k = max([la, lb]); - - if (n >= k) - if (strcmp(region,"whole")) - h = fft(postpad(b,n)) ./ fft(postpad(a,n)); - w = 2*pi*[0:(n-1)]/n; + if (! is_scalar (n)) + if (nargin == 4) ## Fs was specified + w = 2*pi*n/Fs; else - h = fft(postpad(b,2*n)) ./ fft(postpad(a,2*n)); - h = h(1:n); - w = pi*[0:(n-1)]/n; + w = n; endif + n = length (n); + extent = 0; + elseif (strcmp (region, "whole")) + w = 2 * pi * (0:n-1) / n; + extent = n; else - if (strcmp(region,"whole")) - w = 2*pi*[0:(n-1)]/n; - else - w = pi*[0:(n-1)]/n; - endif - h = polyval(postpad(b,k),exp(j*w)) ./ polyval(postpad(a,k),exp(j*w)); + w = pi * (0:n-1) / n; + extent = 2 * n; endif + if (length (b) == 1) + if (length (a) == 1) + hb = b * ones (1, n); + else + hb = b; + endif + elseif (extent >= k) + hb = fft (postpad (b, extent)); + hb = hb(1:n); + else + hb = polyval (postpad (b, k), exp (j*w)); + endif + if (length (a) == 1) + ha = a; + elseif (extent >= k) + ha = fft (postpad (a, extent)); + ha = ha(1:n); + else + ha = polyval (postpad (a, k), exp (j*w)); + endif + h = hb ./ ha; + w = Fs * w / (2*pi); + endfunction diff --git a/src/ChangeLog b/src/ChangeLog --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2002-04-09 Paul Kienzle + + * utils.cc (do_string_escapes): Handle \0 too. + (undo_string_escape): Likewise. + 2002-04-04 John W. Eaton * toplev.cc (octave_config_info): Define struct member EXEEXT, not EXE. diff --git a/src/utils.cc b/src/utils.cc --- a/src/utils.cc +++ b/src/utils.cc @@ -382,6 +382,10 @@ { switch (s[++j]) { + case '0': + retval[i] = '\0'; + break; + case 'a': retval[i] = '\a'; break; @@ -474,6 +478,9 @@ switch (c) { + case '\0': + return "\\0"; + case '\a': return "\\a";