📄 winplt.m
字号:
% winplt.m (ver 04Sep06) ---------------------------------------------------
%
% ----- Author: ----- Paul Mennen
% ----- Email: ----- paul@mennen.org
%
% After struggling with Matlab's window display tool (wintool), I found
% it cumbersome and limited. I wanted a way to quickly change window
% parameters and see the effect on the time and frequency shapes and
% the most common window measures (scalloping and processing loss,
% frequency resolution, and equivalent noise bandwidth). I couldn't
% modify wintool for my taste since most of the code was hidden (pcode).
% So I wrote winplt.m to create a more useable gui for displaying
% windows (winplt - with no arguments) and to catalog and compute time
% shapes for all the windows I knew about (winplt - with arguments).
%
% If you know of some FFT windows I have not included, feel free to let
% me know about them, and I will add them to the next release. Or if you
% want to keep them secret, you will find it easy to add them to winplt
% yourself. Also feel free to suggest new features. (You can always
% reach me at paul@mennen.org).
%
% winplt(-1) ---------------------------------------------------------------
% Displays a list of all windows and their id codes.
%
% [name, kernel] = winplt(id) ----------------------------------------------
% Returns the name of the window associated with that id number (0 to 29)
% The second output argument (if given) will contain the convolution
% kernel. For windows not defined by a kernel the Matlab function
% used to compute it is returned, along with the window parameters.
% Window id's 13 and 14 both return exactly the same Blackman window,
% but keeping both is useful since the implementations are different
% and is a good check that the code has not been broken.
%
% winplt(id,points) --------------------------------------------------------
% Returns the amplitude corrected window time shape (of length points).
% This means that the window is computed, so that its average value is
% one, which insures that: sum(winplot(id,points)) = points
%
% winplt(id,points,1) ------------------------------------------------------
% Returns the power corrected window time shape (of length points)
% This means that the window is computed, so that the average of the
% window squared is one, so that: sum(winplot(id,points).^2) = points
%
% winplt(id,points,pwr,opt) ------------------------------------------------
% id: An index specifying one of the FFT windows
% points: The number of points in the time window to be generated
% pwr: 0/1 = amplitude/power correction (default = 0)
% opt: optional window parameter
%
% winplt (with no arguments) -----------------------------------------------
% Opens a GUI to display fft window time and frequency shapes.
% The time shape is shown as a purple trace and the frequency shape
% is shown as a green trace.
%
% Click on the "Help" tag (near the lower left corner of the figure)
% for instructions on zooming and panning the display, enabling traces,
% and using the cursors.
%
% Use the popup control to select one of 29 different windows -
% including most known windows and a few unknowns. When you select a
% window defined by a convolution kernel, that kernel appears above
% the plot (far upper right).
%
% Use the number of bins slider to control how many fft bins are to
% be plotted on either side of the center. For some window types, an
% additional slider appears to adjust the parameter used by that window.
% The parameter name and the upper/lower slider limits change depending
% on the window selected.
%
% Window id 1 (Hanning/Rife Vincent) is somewhat unique. The parameter
% slider controls the number of times that hanning window is applied.
% So select "1" to get the hanning window, and select "5" to get the
% hanning window applied 5 times (which is usually referred to as
% the "Rife Vincent 5" window).
%
% Whenever a new window is selected, or when any window parameters are
% changed, these four window characteristics are computed and displayed
% in the upper left corner of the plotting area:
% 1.) Scalloping loss (dB) --------------------------------------------
% The scalloping loss relates to the uncertainty of the amplitude
% measurement due to the non-flatness of the frequency shape.
% It's computed as the difference between the maximum and minimum
% values of the frequency response between -.5 and +.5 bins.
% 2.) Frequency resolution (bins) -------------------------------------
% Also known as the "6dB bandwidth" and is a measure of how precisely
% one can estimate the frequency of an input tones. A window
% with a wider main lobe will have a larger 6dB bandwidth and more
% uncertaintly in the frequency measurement.
% 3.) Equivalent Noise Bandwidth (bins) -------------------------------
% The enbw is the width of an ideal rectangular filter which would
% accumulate the same noise power from white noise as the window
% function's kernel. The processing loss is equal to the square
% root of the enbw. e.g. if enbw = 2 bins, processing loss = 3dB.
% 4.) Worst Case Processing loss (dB) ---------------------------------
% This is the sum of the processing loss (10*log10(enbw)) and
% the scalloping loss.
%
% winplt remembers the previous two frequency and time shapes displayed.
% These stored traces make it easy for you to compare two or three
% different window types, or to compare up to three windows of the same
% type but using a different parameter value. To enable these comparisons
% for the frequency shapes, click on the trace IDs (in the traceID box to
% the left of the plot) of the 2nd and 3rd traces (red/blue respectively).
% To enable these comparisons for the time shapes, click on the trace IDs
% of the 5th and 6th traces (cyan/yellow respectively). Note that the last
% two characters of each label indicates the window type being shown on
% that trace. As an example, suppose you select these three windows,
% in this order, using the popup control:
% 11: Hamming
% 13: Blackman
% 20: Potter 210
% The first trace will show the frequency shape of the Potter 210 window
% (since that is the window currently selected) and it's trace ID will
% be "Freq20". The second trace will have an ID of "Freq13" and if
% enabled will show the Blackman frequency shape since that was the
% shape "previously" shown. The third trace will have an ID of "Freq11"
% and if enabled will show the Hamming frequency shape since that was
% the shape "previously, previously" shown. The 4th, 5th, and 6th traces
% will display the time traces associated with the frequency plots
% shown on the first three traces and are named similarly to that described
% for the frequency traces. If you must compare more than 3 different
% windows, your other option is to start multiple copies of the winplt
% application.
%
% On the right side of the graph (above the right axis label) is a
% checkbox called "power corrected". When checked (as it is by default)
% the time trace is power corrected. When this checkbox is unchecked,
% the time trace is amplitude corrected. (See above for an explanation
% of the meaning of power and amplitude correction).
%
% You can display a window of your own design by selecting the last
% window type in the popup control ("user"). When you pick that selection,
% the string "userwin(points,param)" appears above the popup control.
% This means that a function with that name is called to compute the
% power corrected shape to be displayed in the plot area. So one way of
% displaying your own window function, is to simply name it userwin.m
% with its first argument indicating the number of time points to
% compute, and its second argument containing the value shown in the
% parameter slider (between the popup control and the # of bins slider.)
% Or if you prefer, you can change the function string to match the
% window function you have. To change the function string, just click
% on it. The string will change colors to indicate "edit mode" and a
% underline cursor will appear. The left/right arrow keys, and the
% delete/backspace keys will work as expected as you are editing the
% string. As an example, suppose you have the taylorwin function
% (included as part of the Matlab 2006a release) defined as follows:
% function w = taylorwin(points,nbar,dBsidelobes). To view this window
% click on the userwin string and replace it with (for example):
% taylorwin(points,5,-param). Winplt will now show the taylor window
% with the nbar parameter set to 5. The sidelobe level will be controlled
% by the "Parameter" slider. Note the minus sign in front of "param"
% was required because taylorwin expects the sidelobe level to be
% expressed in dB as a negative number, but the parameter slider range
% is set to range between zero and positive 200.
%
% Note: Matlab's window functions return windows with a normalized scaling
% (i.e. with a max value of one), although that type of scaling has little
% use in spectral analysis. Using winplot, you can compute a normalized
% window as follows:
% w = winplot(id,points);
% w = w/max(w);
%
% Note: You will notice that for some of the flat top windows, the
% sum(winplot(id,points)) is slightly less than points. This is on purpose,
% and is done to minimize the scalloping loss. The scaling for the power
% corrected windows is always exact however.
function [out1,out2] = winplt(id,points,pwr,opt)
% Define indices of WPh -----------------
LINEF = 1; % line: frequency trace
LINEFp = 2; % line: previous frequency trace
LINEFpp = 3; % line: previous previous frequency trace
LINET = 4; % line: time trace
LINETp = 5; % line: previous time trace
LINETpp = 6; % line: previous previous time trace
POPUPW = 7; % popup: window selection
CHECKC = 8; % checkbox: window correction factor
SLIDEB = 9; % slider: number of bins
SLIDEH = 10; % slider: number of Hann's
SLIDEP = 11; % slider: window parameter
EDITU = 12; % edit text: user window
Spare = 13; %
TEXTK = 14; % text: kernel
TEXTS = 15; % text: scallop loss
TEXTR = 16; % text: frequency resolution
TEXTE = 17; % text: equivalent noise bandwidth
TEXTP = 18; % text: w.c. process loss
% ----------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -