David Luong ‘06

Engineering 78 Lab 1 Part 2

CONV Convolution and polynomial multiplication.

C = CONV(A, B) convolves vectors A and B. The resulting

vector is length LENGTH(A)+LENGTH(B)-1.

If A and B are vectors of polynomial coefficients, convolving

them is equivalent to multiplying the two polynomials.

Class support for inputs A,B:

float: double, single

See also deconv, conv2, convn, filter and, in the Signal

Processing Toolbox, xcorr, convmtx.

Reference page in Help browser

doc conv

> a=[1 2 1]

a =

1 2 1

> b = [2 4 2]

b =

2 4 2

> conv(a,b)

ans =

2 8 12 8 2

CONV2 Two dimensional convolution.

C = CONV2(A, B) performs the 2-D convolution of matrices

A and B. If [ma,na] = size(A) and [mb,nb] = size(B), then

size(C) = [ma+mb-1,na+nb-1].

C = CONV2(H1, H2, A) convolves A first with the vector H1

along the rows and then with the vector H2 along the columns.

C = CONV2( ... ,'shape') returns a subsection of the 2-D

convolution with size specified by 'shape':

'full' - (default) returns the full 2-D convolution,

'same' - returns the central part of the convolution

that is the same size as A.

'valid' - returns only those parts of the convolution

that are computed without the zero-padded

edges. size(C) = [ma-mb+1,na-nb+1] when

all(size(A) >= size(B)), otherwise C is empty.

See also conv, convn, filter2 and, in the Signal Processing

Toolbox, xcorr2.

Overloaded functions or methods (ones with the same name in other directories)

help uint8/conv2.m

help uint16/conv2.m

Reference page in Help browser

doc conv2

> a=[1 2 1; 2 1 2; 2 3 4]; b = [6 6 7; 4 5 3; 3 6 8];

> c=conv2(a, b)

c =

6 18 25 20 7

16 31 49 30 17

23 56 98 80 42

14 37 65 49 28

6 21 46 48 32

CONVMTX Convolution matrix.

CONVMTX(C,N) returns the convolution matrix for vector C.

If C is a column vector and X is a column vector of length N,

then CONVMTX(C,N)*X is the same as CONV(C,X).

If R is a row vector and X is a row vector of length N,

then X*CONVMTX(R,N) is the same as CONV(R,X).

See also conv.

Reference page in Help browser

doc convmtx

> c=[1 2 1]; x=[3 2 1];

> n=length(x);

> x*convmtx(c,n)

ans =

3 8 8 4 1

> conv(c,x)

ans =

3 8 8 4 1

DECONV Deconvolution and polynomial division.

[Q,R] = DECONV(B,A) deconvolves vector A out of vector B. The result

is returned in vector Q and the remainder in vector R such that

B = conv(A,Q) + R.

If A and B are vectors of polynomial coefficients, deconvolution

is equivalent to polynomial division. The result of dividing B by

A is quotient Q and remainder R.

Class support for inputs B,A:

float: double, single

See also conv, residue.

Reference page in Help browser

doc deconv

> a=[1 2 4]; b=[5 4 3];

> [q,r]=deconv(b,a)

q =

5

r =

0 -6 -17

> b=conv(a,q) + r

b =

5 4 3

XCORR Cross-correlation function estimates.

C = XCORR(A,B), where A and B are length M vectors (M>1), returns

the length 2*M-1 cross-correlation sequence C. If A and B are of

different length, the shortest one is zero-padded. C will be a

row vector if A is a row vector, and a column vector if A is a

column vector.

XCORR produces an estimate of the correlation between two random

(jointly stationary) sequences:

C(m) = E[A(n+m)*conj(B(n))] = E[A(n)*conj(B(n-m))]

It is also the deterministic correlation between two deterministic

signals.

XCORR(A), when A is a vector, is the auto-correlation sequence.

XCORR(A), when A is an M-by-N matrix, is a large matrix with

2*M-1 rows whose N^2 columns contain the cross-correlation

sequences for all combinations of the columns of A.

The zeroth lag of the output correlation is in the middle of the

sequence, at element or row M.

XCORR(...,MAXLAG) computes the (auto/cross) correlation over the

range of lags: -MAXLAG to MAXLAG, i.e., 2*MAXLAG+1 lags.

If missing, default is MAXLAG = M-1.

[C,LAGS] = XCORR(...) returns a vector of lag indices (LAGS).

XCORR(...,SCALEOPT), normalizes the correlation according to SCALEOPT:

'biased' - scales the raw cross-correlation by 1/M.

'unbiased' - scales the raw correlation by 1/(M-abs(lags)).

'coeff' - normalizes the sequence so that the auto-correlations

at zero lag are identically 1.0.

'none' - no scaling (this is the default).

See also xcov, corrcoef, conv, cov and xcorr2.

Reference page in Help browser

doc xcorr

> t=-5:.1:5;

> a=sin(t); b=cos(t);

> x=xcorr(a,a); y=xcorr(a,b);

> hold on

> h=1:length(x);

> z=xcorr(b,b);

> legend('xcorr(a,a)', 'xcorr(a,b)', 'xcorr(b,b)')

> plot(h,x,h,y,h,z)

> legend('xcorr(a,a)', 'xcorr(a,b)', 'xcorr(b,b)')

XCORR2 Two-dimensional cross-correlation.

XCORR2(A,B) computes the crosscorrelation of matrices A and B.

XCORR2(A) is the autocorrelation function.

See also conv2, xcorr and filter2.

Reference page in Help browser

doc xcorr2

> a=[1 2 3; 1 2 3; 1 2 4]; b=[ 3 4 5; 5 6 7; 7 4 1];

> xcorr2(a,a)

ans =

4 10 17 8 3

7 18 31 16 6

10 26 49 26 10

6 16 31 18 7

3 8 17 10 4

> xcorr2(a,b)

ans =

1 6 18 26 21

8 26 56 54 36

13 40 83 76 52

12 34 71 52 29

5 14 31 22 12

> xcorr2(b,b)

ans =

3 16 42 48 35

26 72 140 120 74

57 136 226 136 57

74 120 140 72 26

35 48 42 16 3

FFT Discrete Fourier transform.

FFT(X) is the discrete Fourier transform (DFT) of vector X. For

matrices, the FFT operation is applied to each column. For N-D

arrays, the FFT operation operates on the first non-singleton

dimension.

FFT(X,N) is the N-point FFT, padded with zeros if X has less

than N points and truncated if it has more.

FFT(X,[],DIM) or FFT(X,N,DIM) applies the FFT operation across the

dimension DIM.

For length N input vector x, the DFT is a length N vector X,

with elements

N

X(k) = sum x(n)*exp(-j*2*pi*(k-1)*(n-1)/N), 1 <= k <= N.

n=1

The inverse DFT (computed by IFFT) is given by

N

x(n) = (1/N) sum X(k)*exp( j*2*pi*(k-1)*(n-1)/N), 1 <= n <= N.

k=1

See also fft2, fftn, fftshift, fftw, ifft, ifft2, ifftn.

Overloaded functions or methods (ones with the same name in other directories)

help uint8/fft.m

help uint16/fft.m

Reference page in Help browser

doc fft

> x=sin(t);

> plot(1:length(x),fft(x))

FFT2 Two-dimensional discrete Fourier Transform.

FFT2(X) returns the two-dimensional Fourier transform of matrix X.

If X is a vector, the result will have the same orientation.

FFT2(X,MROWS,NCOLS) pads matrix X with zeros to size MROWS-by-NCOLS

before transforming.

Class support for input X:

float: double, single

See also fft, fftn, fftshift, fftw, ifft, ifft2, ifftn.

Reference page in Help browser

doc fft2

> fft2(a,3,3)

ans =

19.0000 -5.0000 + 3.4641i -5.0000 - 3.4641i

-0.5000 + 0.8660i -0.5000 - 0.8660i 1.0000

-0.5000 - 0.8660i 1.0000 -0.5000 + 0.8660i

> fft2(b,3,3)

ans =

42.0000 1.5000 - 0.8660i 1.5000 + 0.8660i

-3.0000 - 5.1962i 0 + 6.9282i -6.0000 + 3.4641i

-3.0000 + 5.1962i -6.0000 - 3.4641i 0 - 6.9282i

IFFT Inverse discrete Fourier transform.

IFFT(X) is the inverse discrete Fourier transform of X.

IFFT(X,N) is the N-point inverse transform.

IFFT(X,[],DIM) or IFFT(X,N,DIM) is the inverse discrete Fourier

transform of X across the dimension DIM.

IFFT(..., 'symmetric') causes IFFT to treat F as conjugate symmetric

along the active dimension. This option is useful when F is not exactly

conjugate symmetric merely because of round-off error. See the

reference page for the specific mathematical definition of this

symmetry.

IFFT(..., 'nonsymmetric') causes IFFT to make no assumptions about the

symmetry of F.

See also fft, fft2, fftn, fftshift, fftw, ifft2, ifftn.

Overloaded functions or methods (ones with the same name in other directories)

help uint8/ifft.m

help uint16/ifft.m

Reference page in Help browser

doc ifft

> a=cos(t);

> fft(a);

> plot(t,ifft(fft(a)))

> a=cos(t);

> fft(a);

> hold on

> plot(1:length(fft(a)),fft(a))

Warning: Imaginary parts of complex X and/or Y arguments ignored.

FFTSHIFT Shift zero-frequency component to center of spectrum.

For vectors, FFTSHIFT(X) swaps the left and right halves of

X. For matrices, FFTSHIFT(X) swaps the first and third

quadrants and the second and fourth quadrants. For N-D

arrays, FFTSHIFT(X) swaps "half-spaces" of X along each

dimension.

FFTSHIFT(X,DIM) applies the FFTSHIFT operation along the

dimension DIM.

FFTSHIFT is useful for visualizing the Fourier transform with

the zero-frequency component in the middle of the spectrum.

Class support for input X:

float: double, single

See also ifftshift, fft, fft2, fftn, circshift.

Reference page in Help browser

doc fftshift

SPECTRUM Power spectrum estimate of one or two data sequences.

SPECTRUM has been replaced by SPECTRUM.WELCH. SPECTRUM still works but

may be removed in the future. Use SPECTRUM.WELCH (or its functional

form PWELCH) instead. Type help SPECTRUM/WELCH for details.

See also spectrum/psd, spectrum/msspectrum, spectrum/periodogram.

Overloaded functions or methods (ones with the same name in other directories)

help dspopts/spectrum.m

Reference page in Help browser

doc spectrum

> a=sin(t); b=cos(t);

> spectrum(a,b)

specplot

PLOT Plot method for dspdata objects.

PLOT(H) plots the data in the object H.

EXAMPLE: Use the periodogram to estimate the power spectral density of

a noisy sinusoidal signal with two frequency components.

Then store the results in PSD data object and plot it.

Fs = 32e3; t = 0:1/Fs:2.96;

x = cos(2*pi*t*1.24e3)+ cos(2*pi*t*10e3)+ randn(size(t));

Pxx = periodogram(x);

hpsd = dspdata.psd(Pxx,'Fs',Fs); % Create a PSD data object.

plot(hpsd); % Plot the PSD.