This action might not be possible to undo. Are you sure you want to continue?
Remainder after division: REM(x,y) is x-n.*y where n=fix(x/y) if y~=0. If y is not an integer and the quotient x/y is within roundoff error of an integer , then n is the integer .By convention ,REM(x,0) is NaN . the input x and y must be real arrays of the same size ,or real scalars. REM(x,y) has the same sign as x while MOD(x,y) has the same sign as y. REM(x,y) and MOD(x,y) are equal if x and y have the same sign ,but differ by y if x and y have different signs.
Hamming window: HAMMING(N) column vector. returns the N-point symmetric hamming window in a
HAMMING(N,SFLAG) generates the N-point hamming window using the SFLAG window sampling . SFLAG may be either “symmetric” or “periodic”. By default ,a symmetric window is returned.
Hanning window : HANNING(N) returns the N-point symmetric hanning window in a column vector ,Note that the first and last zero-weighted window samples are not included . HANNING(N,’symmetric ‘) returns the same result as HANNING(N). HANNING(N,’periodic’) returns the N-point periodic Hanning window , and includes the first zero-weighted window sample .
NOTE: Use the HANN function to get a hanning window which has the first and last weighted window samples.
FIR filter design using the window method. B=FIR1 (N,Wn) designs an N’th order lowpass FIR digital filter and returns the coefficients in the filter coefficients in length N+1 vector B. The cut-off frequency Wn must between 0<Wn<1.0,with 1.0 corresponding to half the sample rate . The filter B is real and has linear phase. The normalized gain of the filter at Wn is -6dB. B=FIR1(N,Wn,’high’) designs an N’th order highpass filter. You can also use B=FIR1(N<Wn,’low’) to design a lowpass filter. If Wn is a two-element vector, Wn=[w1,w2],Fir1 returns an order N bandpass filter with passband W1<W<W@. you can also specify B=Fir1(N,Wn,’bandpass’).If Wn=[W1 W2],B=Fir(N,Wn,’stop’) will design a bandpass filter. If Wn is a multi-element vector, Wn=[W1 W2 W3 W4 W5…WN], FIR1 returns an order N multiband filter with bands 0<W<W1,W1<W<W2,…,WN<W<1. B=FIR1(N,Wn,’DC-1’) makes the first band a passband. B=FIR1(N,Wn,’DC-0’) makes the first band a stopband. B=FIR1(N,Wn,WIN) designs an N-th order FIR filter using the N+1 length vector Win to window the impulse response. If empty or omitted,FIR1 uses a Hamming window of length N+1. For a complete list of available windows, see the help for the WINDOW function. KAISER and CHEBWIN can be specified with an optional trailing argument .For example,B=FIR1(N<Wn,Kaiser(N+1,4)) uses a Kaiser window with beta=4. B=FIR1(N<Wn,’high’,chebwin(N+1,R)) uses a Chebyshev window with R decibels of relative sidelobe attenuation. For filters with a gain other than zero at Fs/2,e.g.,highpass and bandpass filters, N must be even. Otherwise, N will be incremented by one. In this case the window length should be specified as N+2. By default, the filter is scaled so the center of the first pass band has magnitude exactly one after windowing. Use a trailing ‘noscale’ argument to
prevent this scaling, e.g. B=FIR1(N,Wn,’noscale’), B=FIR1(N,Wn,’high’,’noscale’),B=FIR1(N,Wn,wind,’noscale’). You can also specify the scaling explicitly, e.g.FIR1(N,Wn,’scale’),etc.
Digital filter frequency response: [H,W]=FREQZ(B,A,N) returns the N-point complex frequency response vector H and the N-point frequency vector W in radians/sample of the filter: jw -jw -jmw jw B(e) b(1)+b(2)e+…+b(m+1)e H(e)= ------ =--------------------------------------jw -jw -jnw A(e) a(1)+a(2)e+….+a(n+1)e gives numerator and denominator coefficients in vectors B and A. The frequency response is evaluated at N points equally spaced around the upper half of the unit circle. If N isn’t specified ,it defaults to 512. [H,W]=FREQZ(B,A,N, ’whole’) uses N points around the whole unit circle. H=FREQZ(B,A,W) returns the frequency response at frequencies designated in vector W, in radians/sample(normally between 0 and pi). [H,F]=FREQZ(B,A,N,Fs) and [H,F]=FREQZ(B,A, N, ’whole’, Fs) return frequency vector F(in Hz), where Fs is the sampling frequency (in Hz). H=FREQZ(B,A,F,Fs) returns the complex frequency response at the frequencies designated in vector F(in Hz), where Fs is the sampling frequency (in Hz). FREQZ(B,A,…) with no output arguments plots the magnitude and unwrapped phase of the filter in the current figure window.
Creates axes in tiled positions. H=SUBPLOT(m,n,p)< or SUBPLOT(mnp),breaks the figure window into an m-by-n matrix of small axes, selects the p-th axes for the current plot, and returns the axis handle. The axes are counted along the top row of the figure window, then the second row , etc. For example, SUBPLOT(2,1,1),PLOT(income)
SUBPLOT(2,1,2),PLOT(outgo)plots income on the top half of the window and outgo on the bottom half. SUBPLOT(m,n,p), if the axis already exists, makes it current. SUBPLOT(m,n,p,’replace’),if the axis already exists, deletes it and creates a new axis. SUBPLOT(m, n, p, ’align’) places the axes so that the plot boxes are aligned instead of preventing the labels and ticks from overlapping. SUBPLOT(m, n, P),where P is a vector ,specifies an axes position that covers all the subplot positions listed in P. SUBPLOT(H), where H is an axis handle, is another way of making an axis current for subsequent plotting commands. SUBPLOT(‘position’,[left bottom width height]) creates an axis at the specified position in normalized coordinates(in the range from 0.0 to 1.0). SUBPLOT(m,n,p,PROP1,VALUE1,PROP2,VALUE2,…) sets the specified property-value pairs on the subplot axis. To add the subplot to a specific figure pass the figure handle as the value for the ‘Parent’ property. If a SUBPLOT specification causes a new axis to overlap an existing axis, the existing axis is deleted –unless the position of the new and existing axis are identical. For example, the statement SUBPLOT(1,2,1) deletes all existing axes overlapping the left side of the figure window and creates a new axis on that sideunless there is an axes there with a position that exactly matches the position of the new axes(and ‘replace’ was not specified), in which case all other overlapping axes will be deleted and the matching axes will become the current axes. SUBPLOT(111) is an exception to the rules above, and is not identical in behavior to SUBPLOT(1,1,1).for reasons of backwards compatibility, it is a special case of subplot which does not immediately creates an axes, but instead sets up the figure so that the next graphics command executes CLF RESET in the figure (deleting all children of the figure), and creates a new axes in the default position. This syntax does not return a handle, so it is an error to specify a return argument. The delayed CLF RESET is accomplished by setting the figure’s Next Plot to ‘replace’.
BOXCAR still works but may be removed in the future. Use RECTWIN instead. Type help RECTWIN for details.
Butterworth digital and analog filter design: [B,A]=BUTTER(N,Wn) designs an Nth order lowpass digital Butterworth filter and returns the filter coefficients in length N+1 vectors B(numerator) and A (denominator). The coefficients in listed in descending powers of z. The cutoff frequency Wn must be 0.0<Wn<1.0, with 1.0 corresponding to half the sample rate. If Wn is a two-element vector, Wn=[W1 W2],BUTTER returns an order 2N bandpass filter with passband W1<W<W2. [B,A]=BUTTER(N,Wn,’high’) designs a highpass filter. [B,A]=BUTTER(N,Wn,’low’) designs a lowpass filter. [B,A]=BUTTER(N,Wn,’stop’) is a bandstop filter. If Wn=[W1 W2]. When used with three left-hand arguments, as in [Z,P,K]=BUTTER(…),the zeros and poles are returned in length N column vectors Z and P, and the gain in scalar K. When used with four left-hand arguments ,as in [A,B,C,D]=BUTTER(…),state-space matrices are returned. BUTTER(N,Wn,’s’),BUTTER(N,Wn,’high’,’s’) and BUTTER(N,Wn,’stop’,’s’) design analog Butterworth filters. In this case, Wn is in [rad/s] and it can be greater than 1.0.
Linear plot: PLOT(X,Y) plots vector Y versus vector. If X or Y is a matrix, then the vector is plotted versus the rows or columns of the matrix, whichever line up. If X is a scalar and Y is a vector, length(Y) disconnected points are plotted. PLOT(Y) plots the columns of Y versus their index. If Y is complex, PLOT(Y) is equivalent to PLOT(real(Y),imag(Y)). In all other uses of PLOT, the imaginary part is ignored. Various line types, plot symbols and colors may be obtained with PLOT(X,Y,S) where S is a character string made from one element from any or all the following tables:
SYMBO LS b g r c . o x + : -. -m Y K * s d (none) v ^ < > p h
DESCRIPTION Blue Green Red Cyan Point circle x-mark Plus Solid Dotted Dash dot Dashed Magenta Yellow Black Star Square Diamond No line Triangle(down) Triangle(up) Triangle(left) Triangle(right) Pentagram Hexagram
For example, PLOT(X, Y, ’c+:’) plots a cyan dotted line with a plus at each data point; PLOT(X, Y, ‘bd’) plots blue diamond at each data point but does not draw any line.PLOT(X1, Y1, S1,X2,Y2,S2,X3,Y3,S3,…) combines the plots defined by the(X,Y,S) triples, where the X’s and Y’s are vectors or matrices and the S’s are strings. For example, Plot(X,Y,’y-‘,X,Y,’go’) plots the data twice, with a solid yellow line interpolating green circles at the data points. The PLOT command, if no color is specified, makes automatic use of the colors specified by the axes ColorOrder property. The default ColorOrder is listed
in the table above for color systems where the default is blue for one line, and for multiple lines, to cycle through the first six colors in the table. For monochrome systems, PLOT cycles over the axes LineStyleOrder property. If you do not specify a marker type, PLOT uses no marker. If you do not specify a line style, PLOT uses a solid line. PLOT(AX,….) plots into the axes with handle AX. PLOT returns a column vector of handles to line series objects, one handle per plotted line. The X,Y pairs, or X,Y,S triples, can be followed by parameter/value pairs to specify additional properties of the lines. For example, PLOT(X,Y,’LineWidth’,2,’Color’,[.6 0 0]) will create a plot with a dark red line width of 2 points. Backwards compatibility: PLOT (‘v6’…) creates line objects instead of line series objects for compatibility with MATLAB 6.5 and earlier.
Chebyshev Type I filter order selection: [N,Wn]=CHEB1ORD(Wp,Ws,Rp,Rs) returns the order N of the lowest order digital Chebyshev Type I filter that loses no more than Rp dB in the pass band and has at least Rs dB of attenuation in the stop band. Wp and Ws are the pass band and stop band edge frequencies, normalized from 0 to 1(where 1 corresponds to pi radians/sample). For example, Low pass: Wp=.1, Ws=.2 High pass: Wp=.2, Ws=.1
Band pass: Wp=[.2 .7], Ws=[.1 .8] Band stop: Wp=[.1 .8], Ws=[.2 .7] CHEB1ORB also returns Wn,the Chebyshev natural frequency to use with CHEBY1 to achieve the specifications. [N,Wn]=CHEB1ORB(Wp,Ws,Rp,Rs,'s') does the computation for an analog filter,in which case Wp and Ws are in radians/second.
Chebyshev Type I digital and analog filter design: [B,A]=CHEBY1(N,R,WN) designs an Nth order low pass digital Chebyshev filter with R decibels of peak-to-peak ripple in the pass band. CHEBY1 returns the
filter coefficients in length N+1 vectors B (numerator) and A (denominator). The cutoff frequency Wn must be 0.0<wn<1.0,with 1.0 corresponding to half the sample rate,Use R=0.5 as a starting point,if you are unsure about choosing R. If Wn is a two-element vector,Wn=[W1,W2],CHBY1 returns an order 2N bandpass filter with passband W1<W<W2. [B,A]=CHEBY1(N,R,Wn,’high’) designs a highpass filter. [B,A]=CHEBY1(N,R,Wn,’low’) designs a lowpass filter. [B,A]=CHEBY1(N,R,Wn,’stop’) is a bandstop filter. If Wn=[W1 W2]. When used with three left-hand arguments, as in [Z,P,K]=CHEBY1(…),the zeros and poles are returned in length N column vectors Z and P, and the gain in scalar K. When used with four left-hand arguments ,as in [A,B,C,D]=CHEBY1(…),state-space matrices are returned. CHEBY1(N,R,Wn,’s’),CHEBY1(N,R,Wn,’high’,’s’) and CHEBY1(N,R,Wn,’stop’,’s’) design analog Chebyshev Type I filters. In this case, Wn is in [rad/s] and it can be greater than 1.0. See also cheb1ord,cheby2,butter,ellip ,freqz,filter. Overloaded functions or methods (ones with the same name in other directories ) help fdesign/cheby1.m
Discrete Fourier Transform: Syntax: Y=fft(X) Y=fft(X,n) Y=fft(X,,dim) Y=fft(X,n,dim) Definition: The function X=fft(x) and x=ifft(X) implement the transform and inverse transform pair given for vectors of length by: where is an th root of unity. Description:
Y=fft(X) returns the discrete Fourier transform (DFT) of vector X,computed with a fast Fourier transform (FFT) algorithm. If X is a matrix,fft returns the Fourier transform of each column of the matrix. If X is a multidimensional array,fft operates on the first non -singleton dimension. Y=fft(X,n) returns the n=point DFT. If the length of X is less than n,X is padded with trailing zeros to length n. If the length of X is greater than n, the sequence X is truncated. When X is a matrix, the length of the columns are adjusted in the same manner. Y=fft(X,,dim) and Y=fft(X,n,dim) applies the FFT operation across the dimension dim. Examples: A common use of Fourier transforms is to find the frequency components of a signal buried in a noisy time domain signal. Consider data sampled at 1000 Hz. Form a signal containing 50 Hz and 120 Hz and corrupt it with some zero-mean random noise: t=0:0.001:0.6; x=sin(2*pi*50*t)+sin(2*pi*120*t); y=x+2*randn(size(t)); plot(1000*t(1:50),y(1:50)) title('Signal Corrupted with Zero-Mean Random Noise') xlabel('time(milliseconds)') It is difficult to identify the frequency components by looking at the original signal. Converting to the frequency domain,the discrete Fourier transform of the noisy signal y is found by taking the 512-point fast Fourier transform (FFT):Y=fft(y,512); The power spectrum, a measurement of the power at various frequencies,is Pyy=Y.*conj(Y)/512; Graph the first 257 points (the other 255 points are redundant) on a meaningful frequency axis: f=1000*(0:256)/512; plot(f,Pyy(1:257)) title('Frequency content of y') xlabel('frequency(Hz)') This represents the frequency content of y in the range from DC up to and including the Nyquist frequency.(The signal produces the strong peaks.)
Convolution and polynomial multiplication Syntax: w=conv(u,v) Description : w=conv(u,v) convolves vectors u and v. Algebraically, convolution is the same operation as multiplying the polynomials whose coefficients are the elements of u and v. Definition : Let m=length(u) and n=length(v). Then w is the vector of length m+n-1 whose kth element is The sum is over all the values of j which lead to legal subscripts for u(j) and v(k+1-j),specifically j=max(1,k+1-n):min(k,m).when m=n,this gives w(1)=u(1)*v(1) w(2)=u(1)*v(2)+u(2)*v(1) w(3)=u(1)*v(3)+u(2)*v(2)+u(3)*v(1) … w(n)=u(1)*v(n)+u(2)*v(n-1)+...+u(n)*v(1) … w(2*n-1)=u(n)*v(n) Algorithm: The convolution theorem says,roughly, that convolving two sequences is the same as multiplying their Fourier transforms.In order to make this precise,it is necessary to pad the two vectors with zeros and ignore roundoff error. Thus ,if X=fft([x zeros(1,length(y)-1]) and Y=fft([y zeros(1,length(x)-1]), then conv(x,y)=ifft(X.*Y). See also conv2,convn,deconv,filter convmtx and xcorr in the Signal Processing Toolbox.