V = FLOW(N) produces a 2N-by-N-by-N array.
V = FLOW(X,Y,Z) evaluates the speed profile at the points (X,Y,Z). [X,Y,Z,V] = FLOW(...) returns the coordinates as well.
*MESHGRID X and Y arrays for 3-D plots.
[X,Y] = MESHGRID(x,y) transforms the domain specified by vectors
x and y into arrays X and Y that can be used for the evaluation of functions of two variables and 3-D surface plots.
The rows of the output array X are copies of the vector x and the columns of the output array Y are copies of the vector y.
[X,Y,Z] = MESHGRID(x,y,z) produces 3-D arrays that can be used to evaluate functions of three variables and 3-D volumetric plots. For example, to evaluate the function x*exp(-x^2-y^2) over the range -2 < x < 2, -2 < y < 2,
[X,Y] = meshgrid(-2:.2:2, -2:.2:2); Z = X .* exp(-X.^2 - Y.^2); mesh(Z)
七. 数字信号处理初步(Introduction to Signal Processing )
MATLAB主要包括信号处理(Signal Processing Toolbox)和滤波器设计(Filter Design Toolbox)两部分.
基本平台中提供了一些常用的信号处理函数(表 4-4),可实现数字信号处理的基本功能。
1. 快速傅立叶变换(FFT): MATLAB6.1 采用了新的快速傅立叶变换计算方法,速度高,可以作到实时处理。 函数fft的调用格式:
*Y=fft(X) 返回应用快速傅立叶方法计算得到的矢量X的离散傅立叶变换(DFT), 如果 X为矩阵,fft返回矩阵每一列的傅立叶变换,如果X为多维数组,fft运算从第一个非独立维开始执行。
*Y=fft(X,n) 返回n点的离散傅立叶变换,如果X的长度小于n,X中补0使其与n的长度相同,
;如果X的长度大于n,则X的多出部分将被删除;如X为矩阵,用同样方法处理矩阵列的长度。
*Y=fft(X,[],dim) 和Y=fft(X,n,dim)沿dim维进行FFT操作。
注:快速傅立叶变换的结果为复数。
例1: 产生一个正弦衰减曲线,进行快速傅立叶变换,并画出幅值(amplitude)图,相位(phase)图、实部(real)图和虚部(image)图。 tp=0:2048; %时域数据点数N
yt=sin(0.08*pi*tp).*exp(-tp/80); %生成正弦衰减函数 figure(1),
plot(tp,yt), axis([0,400,-1,1]), %绘正弦衰减曲线 t=0:800/2048:800; %频域点数Nf f=0:1.25:1000;
yf=fft(yt); %快速傅立叶变换 ya=abs(yf(1:801)); %幅值 yp=angle(yf(1:801))*180/pi; %相位 yr=real(yf(1:801)); %实部 yi=imag(yf(1:801)); %虚部 figure(2), subplot(2,2,1)
plot(f,ya),axis([0,200,0,60]) %绘幅值曲线 subplot(2,2,2)
plot(f,yp),axis([0,200,-200,10]) %绘相位曲线 subplot(2,2,3)
plot(f,yr),axis([0,200,-40,40]) %绘实部曲线 subplot(2,2,4)
plot(f,yi),axis([0,200,-60,10]) %绘虚部曲线
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
2. 快速傅立叶变换的长度与运算速度(Relation of the length of FFT and
the velocity of calculation speed )
使用fft函数时,可输入第二个参数n以指定变换点的数量: y=fft(x,n)
fft的运算速度取决于变换的长度。
*如n是2 的整数次幂,则运算速度最快;
*如n是合数,fft采用质因数分解的算法,速度取决于质因数的大小。 *如n是质数(prime number),计算速度最慢。
例: 创建70000×1阶的随机矢量x,取快速傅立叶变换的长度分别为质数65539、 2的16次方, 两个合数(composite number)66000和5535,分别计算使用这些长度fft所占用的cpu时间。 x=rand(70000,1);
isprime(65539) %质数 ans = 1 2^16 ans =
65536
(FACTOR(N) returns a vector containing the prime factors of N.) factor(66000) %合数 ans =
2 2 2 2 3 5 5 5 11 factor(65535) %合数 ans =
3 5 17 257
t=cputime; %开始运行时间 y=fft(x,65539);
e=cputime-t %运行结束与开始运行时的时间差 e=
0. 9900
t=cputime; y=fft(x,65536); e=cputime-t e=
0. 1600
t=cputime; y=fft(x,65535); e=cputime-t e =
0. 3800
由上例可见,变换长度的差别对运算速度的影响很大,这正是大多数的数字信号处理系统中FFT的长度取为2 的n次方的原因。