Mercurial > octave
annotate scripts/signal/stft.m @ 17338:1c89599167a6
maint: End m-files with 1 blank line.
Simplifies automated grammarchecking script.
* scripts/@ftp/ascii.m, scripts/@ftp/binary.m, scripts/@ftp/cd.m,
scripts/@ftp/close.m, scripts/@ftp/delete.m, scripts/@ftp/dir.m,
scripts/@ftp/display.m, scripts/@ftp/ftp.m, scripts/@ftp/loadobj.m,
scripts/@ftp/mget.m, scripts/@ftp/mkdir.m, scripts/@ftp/mput.m,
scripts/@ftp/rename.m, scripts/@ftp/rmdir.m, scripts/@ftp/saveobj.m,
scripts/audio/lin2mu.m, scripts/audio/loadaudio.m, scripts/audio/mu2lin.m,
scripts/audio/record.m, scripts/audio/saveaudio.m, scripts/audio/setaudio.m,
scripts/deprecated/__error_text__.m, scripts/deprecated/cut.m,
scripts/deprecated/error_text.m, scripts/deprecated/isstr.m,
scripts/deprecated/polyderiv.m, scripts/deprecated/studentize.m,
scripts/deprecated/sylvester_matrix.m, scripts/general/bicubic.m,
scripts/general/celldisp.m, scripts/general/colon.m,
scripts/general/cplxpair.m, scripts/general/del2.m, scripts/general/display.m,
scripts/general/isdir.m, scripts/general/isequaln.m, scripts/general/loadobj.m,
scripts/general/private/__isequal__.m, scripts/general/private/__splinen__.m,
scripts/general/profexplore.m, scripts/general/quadgk.m,
scripts/general/randi.m, scripts/general/repmat.m, scripts/general/saveobj.m,
scripts/geometry/delaunay.m, scripts/help/__unimplemented__.m,
scripts/help/doc_cache_create.m, scripts/help/get_first_help_sentence.m,
scripts/help/help.m, scripts/help/print_usage.m,
scripts/help/private/__additional_help_message__.m,
scripts/help/private/__strip_html_tags__.m, scripts/help/type.m,
scripts/image/imfinfo.m, scripts/image/imformats.m, scripts/image/imread.m,
scripts/image/imwrite.m, scripts/image/private/__imfinfo__.m,
scripts/image/private/__imread__.m, scripts/image/private/__imwrite__.m,
scripts/image/private/imageIO.m, scripts/image/private/imwrite_filename.m,
scripts/image/private/ind2x.m, scripts/io/beep.m, scripts/io/strread.m,
scripts/io/textread.m, scripts/io/textscan.m, scripts/linear-algebra/krylov.m,
scripts/linear-algebra/subspace.m, scripts/miscellaneous/bug_report.m,
scripts/miscellaneous/bunzip2.m, scripts/miscellaneous/cast.m,
scripts/miscellaneous/copyfile.m, scripts/miscellaneous/debug.m,
scripts/miscellaneous/dir.m, scripts/miscellaneous/dump_prefs.m,
scripts/miscellaneous/error_ids.m, scripts/miscellaneous/fileattrib.m,
scripts/miscellaneous/gunzip.m, scripts/miscellaneous/isdeployed.m,
scripts/miscellaneous/ismac.m, scripts/miscellaneous/mex.m,
scripts/miscellaneous/mexext.m, scripts/miscellaneous/mkoctfile.m,
scripts/miscellaneous/movefile.m, scripts/miscellaneous/namelengthmax.m,
scripts/miscellaneous/news.m, scripts/miscellaneous/pack.m,
scripts/miscellaneous/perl.m,
scripts/miscellaneous/private/display_info_file.m,
scripts/miscellaneous/python.m, scripts/miscellaneous/rmappdata.m,
scripts/miscellaneous/run.m, scripts/miscellaneous/tar.m,
scripts/miscellaneous/tempname.m, scripts/miscellaneous/untar.m,
scripts/miscellaneous/unzip.m, scripts/miscellaneous/what.m,
scripts/miscellaneous/zip.m, scripts/optimization/fminunc.m,
scripts/optimization/fsolve.m, scripts/optimization/fzero.m,
scripts/optimization/glpk.m, scripts/optimization/optimget.m,
scripts/optimization/optimset.m, scripts/optimization/qp.m,
scripts/optimization/sqp.m, scripts/path/pathdef.m, scripts/pkg/pkg.m,
scripts/pkg/private/build.m, scripts/pkg/private/describe.m,
scripts/pkg/private/dirempty.m, scripts/pkg/private/get_forge_download.m,
scripts/pkg/private/get_forge_pkg.m,
scripts/pkg/private/get_unsatisfied_deps.m, scripts/pkg/private/install.m,
scripts/pkg/private/is_architecture_dependent.m,
scripts/pkg/private/list_forge_packages.m, scripts/pkg/private/rebuild.m,
scripts/pkg/private/shell.m, scripts/pkg/private/uninstall.m,
scripts/plot/axes.m, scripts/plot/box.m, scripts/plot/closereq.m,
scripts/plot/diffuse.m, scripts/plot/ezpolar.m, scripts/plot/findfigs.m,
scripts/plot/gco.m, scripts/plot/guidata.m, scripts/plot/guihandles.m,
scripts/plot/hdl2struct.m, scripts/plot/linkprop.m, scripts/plot/peaks.m,
scripts/plot/print.m, scripts/plot/private/__add_datasource__.m,
scripts/plot/private/__axis_label__.m, scripts/plot/private/__clabel__.m,
scripts/plot/private/__color_str_rgb__.m, scripts/plot/private/__contour__.m,
scripts/plot/private/__default_plot_options__.m,
scripts/plot/private/__errcomm__.m, scripts/plot/private/__file_filter__.m,
scripts/plot/private/__fltk_file_filter__.m,
scripts/plot/private/__getlegenddata__.m,
scripts/plot/private/__gnuplot_open_stream__.m,
scripts/plot/private/__gnuplot_print__.m,
scripts/plot/private/__go_draw_axes__.m,
scripts/plot/private/__interp_cube__.m, scripts/plot/private/__is_function__.m,
scripts/plot/private/__line__.m, scripts/plot/private/__marching_cube__.m,
scripts/plot/private/__next_line_style__.m, scripts/plot/private/__patch__.m,
scripts/plot/private/__pie__.m, scripts/plot/private/__pltopt__.m,
scripts/plot/private/__quiver__.m, scripts/plot/private/__scatter__.m,
scripts/plot/private/__stem__.m, scripts/plot/private/__uigetdir_fltk__.m,
scripts/plot/private/__uigetfile_fltk__.m,
scripts/plot/private/__uiobject_split_args__.m,
scripts/plot/private/__uiputfile_fltk__.m, scripts/plot/refresh.m,
scripts/plot/saveas.m, scripts/plot/shg.m, scripts/plot/specular.m,
scripts/plot/sphere.m, scripts/plot/struct2hdl.m, scripts/plot/subplot.m,
scripts/plot/uicontextmenu.m, scripts/plot/uicontrol.m, scripts/plot/uipanel.m,
scripts/plot/uipushtool.m, scripts/plot/uiresume.m,
scripts/plot/uitoggletool.m, scripts/plot/uitoolbar.m, scripts/plot/uiwait.m,
scripts/plot/waitforbuttonpress.m, scripts/polynomial/pchip.m,
scripts/polynomial/polyeig.m, scripts/polynomial/ppval.m,
scripts/prefs/addpref.m, scripts/prefs/getpref.m, scripts/prefs/ispref.m,
scripts/prefs/private/loadprefs.m, scripts/prefs/private/prefsfile.m,
scripts/prefs/private/saveprefs.m, scripts/prefs/setpref.m,
scripts/set/private/validargs.m, scripts/set/unique.m,
scripts/signal/arch_fit.m, scripts/signal/arch_rnd.m,
scripts/signal/arch_test.m, scripts/signal/arma_rnd.m,
scripts/signal/durbinlevinson.m, scripts/signal/fractdiff.m,
scripts/signal/freqz.m, scripts/signal/freqz_plot.m, scripts/signal/hurst.m,
scripts/signal/periodogram.m, scripts/signal/private/rectangle_lw.m,
scripts/signal/private/rectangle_sw.m, scripts/signal/private/triangle_sw.m,
scripts/signal/spectral_adf.m, scripts/signal/spectral_xdf.m,
scripts/signal/stft.m, scripts/signal/synthesis.m, scripts/signal/yulewalker.m,
scripts/sparse/colperm.m, scripts/sparse/eigs.m, scripts/sparse/etreeplot.m,
scripts/sparse/gmres.m, scripts/sparse/private/__sprand_impl__.m,
scripts/sparse/spdiags.m, scripts/sparse/sprandn.m, scripts/specfun/bessel.m,
scripts/specfun/betaln.m, scripts/specfun/expint.m,
scripts/special-matrix/gallery.m, scripts/startup/__finish__.m,
scripts/statistics/base/qqplot.m, scripts/statistics/distributions/tcdf.m,
scripts/statistics/distributions/wienrnd.m,
scripts/statistics/models/logistic_regression.m,
scripts/statistics/models/private/logistic_regression_derivatives.m,
scripts/statistics/models/private/logistic_regression_likelihood.m,
scripts/statistics/tests/anova.m, scripts/statistics/tests/bartlett_test.m,
scripts/statistics/tests/chisquare_test_homogeneity.m,
scripts/statistics/tests/chisquare_test_independence.m,
scripts/statistics/tests/cor_test.m,
scripts/statistics/tests/f_test_regression.m,
scripts/statistics/tests/hotelling_test.m,
scripts/statistics/tests/hotelling_test_2.m,
scripts/statistics/tests/kolmogorov_smirnov_test_2.m,
scripts/statistics/tests/kruskal_wallis_test.m,
scripts/statistics/tests/manova.m, scripts/statistics/tests/mcnemar_test.m,
scripts/statistics/tests/prop_test_2.m, scripts/statistics/tests/run_test.m,
scripts/statistics/tests/sign_test.m, scripts/statistics/tests/t_test.m,
scripts/statistics/tests/t_test_2.m,
scripts/statistics/tests/t_test_regression.m,
scripts/statistics/tests/u_test.m, scripts/statistics/tests/var_test.m,
scripts/statistics/tests/welch_test.m,
scripts/statistics/tests/wilcoxon_test.m, scripts/statistics/tests/z_test.m,
scripts/statistics/tests/z_test_2.m, scripts/strings/strcat.m,
scripts/strings/strjoin.m, scripts/strings/strsplit.m,
scripts/testfun/__have_feature__.m, scripts/testfun/__printf_assert__.m,
scripts/testfun/__prog_output_assert__.m, scripts/testfun/__run_test_suite__.m,
scripts/time/clock.m, scripts/time/datenum.m, scripts/ui/errordlg.m,
scripts/ui/private/message_dialog.m: End m-files with 1 blank line.
author | Rik <rik@octave.org> |
---|---|
date | Wed, 28 Aug 2013 08:33:02 -0700 |
parents | 049e8bbff782 |
children | 6ed0a8532bcf |
rev | line source |
---|---|
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1 ## Copyright (C) 1995-2012 Andreas Weingessel |
3426 | 2 ## |
3922 | 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. | |
3426 | 9 ## |
3922 | 10 ## Octave is distributed in the hope that it will be useful, but |
3191 | 11 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
3426 | 13 ## General Public License for more details. |
14 ## | |
3191 | 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/>. | |
3191 | 18 |
3449 | 19 ## -*- texinfo -*- |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
20 ## @deftypefn {Function File} {[@var{y}, @var{c}] =} stft (@var{x}, @var{win_size}, @var{inc}, @var{num_coef}, @var{win_type}) |
9072
bd8e388043c4
Cleanup documentation for signal.texi, image.texi, audio.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
21 ## Compute the short-time Fourier transform of the vector @var{x} with |
3449 | 22 ## @var{num_coef} coefficients by applying a window of @var{win_size} data |
23 ## points and an increment of @var{inc} points. | |
3191 | 24 ## |
25 ## Before computing the Fourier transform, one of the following windows | |
3449 | 26 ## is applied: |
27 ## | |
28 ## @table @asis | |
10791
3140cb7a05a1
Add spellchecker scripts for Octave and run spellcheck of documentation
Rik <octave@nomad.inbox5.com>
parents:
9072
diff
changeset
|
29 ## @item @nospell{hanning} |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
30 ## win_type = 1 |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
31 ## |
10791
3140cb7a05a1
Add spellchecker scripts for Octave and run spellcheck of documentation
Rik <octave@nomad.inbox5.com>
parents:
9072
diff
changeset
|
32 ## @item @nospell{hamming} |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
33 ## win_type = 2 |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
34 ## |
3449 | 35 ## @item rectangle |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
36 ## win_type = 3 |
3449 | 37 ## @end table |
38 ## | |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
39 ## The window names can be passed as strings or by the @var{win_type} number. |
3191 | 40 ## |
41 ## If not all arguments are specified, the following defaults are used: | |
3449 | 42 ## @var{win_size} = 80, @var{inc} = 24, @var{num_coef} = 64, and |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
43 ## @var{win_type} = 1. |
3191 | 44 ## |
3449 | 45 ## @code{@var{y} = stft (@var{x}, @dots{})} returns the absolute values |
46 ## of the Fourier coefficients according to the @var{num_coef} positive | |
47 ## frequencies. | |
48 ## | |
49 ## @code{[@var{y}, @var{c}] = stft (@code{x}, @dots{})} returns the | |
50 ## entire STFT-matrix @var{y} and a 3-element vector @var{c} containing | |
51 ## the window size, increment, and window type, which is needed by the | |
52 ## synthesis function. | |
53 ## @end deftypefn | |
3191 | 54 |
3457 | 55 ## Author: AW <Andreas.Weingessel@ci.tuwien.ac.at> |
9072
bd8e388043c4
Cleanup documentation for signal.texi, image.texi, audio.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
56 ## Description: Short-Time Fourier Transform |
3191 | 57 |
14868
5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
58 function [y, c] = stft (x, win_size, inc, num_coef, win_type) |
3426 | 59 |
8506 | 60 ## Default values of unspecified arguments. |
3191 | 61 if (nargin < 5) |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
62 win_type = 1; |
3191 | 63 if (nargin < 4) |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
64 num_coef = 64; |
3191 | 65 if (nargin < 3) |
3426 | 66 inc = 24; |
67 if (nargin < 2) | |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
68 win_size = 80; |
3426 | 69 endif |
3191 | 70 endif |
71 endif | |
3426 | 72 elseif (nargin == 5) |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
73 if (ischar (win_type)) |
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
74 if (strcmp (win_type, "hanning")) |
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
75 win_type = 1; |
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
76 elseif (strcmp (win_type, "hamming")) |
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
77 win_type = 2; |
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
78 elseif (strcmp (win_type, "rectangle")) |
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
79 win_type = 3; |
3191 | 80 else |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
81 error ("stft: unknown window type '%s'", win_type); |
3191 | 82 endif |
83 endif | |
84 else | |
6046 | 85 print_usage (); |
3191 | 86 endif |
87 | |
8506 | 88 ## Check whether X is a vector. |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
89 [nr, nc] = size (x); |
3191 | 90 if (nc != 1) |
91 if (nr == 1) | |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
92 x = x'; |
3191 | 93 nr = nc; |
94 else | |
3457 | 95 error ("stft: X must be a vector"); |
3191 | 96 endif |
97 endif | |
98 | |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
99 ncoef = 2 * num_coef; |
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
100 if (win_size > ncoef) |
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
101 win_size = ncoef; |
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
102 printf ("stft: window size adjusted to %f\n", win_size); |
3191 | 103 endif |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
104 num_win = fix ((nr - win_size) / inc); |
3191 | 105 |
106 ## compute the window coefficients | |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
107 if (win_type == 3) |
8506 | 108 ## Rectangular window. |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
109 win_coef = ones (win_size, 1); |
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
110 elseif (win_type == 2) |
8506 | 111 ## Hamming window. |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
112 win_coef = hamming (win_size); |
8506 | 113 else |
114 ## Hanning window. | |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
115 win_coef = hanning (win_size); |
3191 | 116 endif |
3426 | 117 |
8506 | 118 ## Create a matrix Z whose columns contain the windowed time-slices. |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
119 z = zeros (ncoef, num_win + 1); |
3191 | 120 start = 1; |
121 for i = 0:num_win | |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
122 z(1:win_size, i+1) = x(start:start+win_size-1) .* win_coef; |
3191 | 123 start = start + inc; |
124 endfor | |
125 | |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
126 y = fft (z); |
3191 | 127 |
128 if (nargout == 1) | |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
129 y = abs (y(1:num_coef, :)); |
3191 | 130 else |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
131 c = [win_size, inc, win_type]; |
3191 | 132 endif |
133 | |
134 endfunction | |
17338
1c89599167a6
maint: End m-files with 1 blank line.
Rik <rik@octave.org>
parents:
15467
diff
changeset
|
135 |