⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fftplot.m

📁 很多matlab的源代码
💻 M
字号:
function [y,f] = fftplot(x,t)
% FFTPLOT FFT magnitude and phase spectra.
%
%        [Z,f] = FFTPLOT(X,TS) FFT magnitude and phase specta (re-ordered). 
%	 X = signal vector/array with sampling interval, TS [Default: TS = 1]
%	 Plots spectra if length(x)>128, else plots LINE spectra.
%	 Z returns the REORDERED complex (real/imag part or rectangular) form
%	 f returns the corresponding frequencies (Hz).
%
%        FFTPLOT invokes the following example:
%	 %Plot the FFT spectrum of a decaying exponential 
%        >>t0 = 0:.1:4;
%        >>xt = exp(-t0);
%        >>fftplot(xt,0.1);


% ADSP Toolbox: Version 2.0 
% For use with "Analog and Digital Signal Processing", 2nd Ed.
% Published by PWS Publishing Co.
%
% Ashok Ambardar, EE Dept. MTU, Houghton, MI 49931, USA
% http://www.ee.mtu/faculty/akambard.html
% e-mail: akambard@mtu.edu
% Copyright (c) 1998


if nargin==0,help fftplot,disp('Strike a key to see results of the example')
pause,t0=0:.1:4;xt=exp(-t0);fftplot(xt,0.1);,return,end

[mm,nn]=size(x);x=x(:);
y=fft(x);n=length(x);
n1=1:ceil(n/2);n2=ceil(n/2+1):n;
l=length(n2);y=[y(n2);y(n1)];
f1=(0:n-1)-l;mag=abs(y);zm=mag;
ang1=180*angle(y(n1))/pi;i=find(ang1>179.9);
if~isempty(i),[m1,m2]=size(i);ang1(i)=-ang1(i);end
ang2=180*angle(y(n2))/pi;i=find(ang2<-179.9);
if~isempty(i),[m1,m2]=size(i);ang2(i)=-ang2(i);end
ang=[ang1;ang2];
zp=ang;l2=length(n2);
aa=l2+1:n;bb=1:l2;
zm=[zm(aa);zm(bb)];
zp=[zp(aa);zp(bb)];
y=[y(aa);y(bb)];
f=f1/n/t;fm=1.2*max(abs(f));
y=fftshift(y);if mm==1,y=y.';zm=zm';zp=zp';else,f=f(:);end
m=1.2*max(mag);
p=1.2*max(abs(ang));


v=3;if exist('version')==5,v=4;end
%disp('STRIKE A KEY BETWEEN PLOTS'),if v==3,pause(3),end
 vx=matverch;
 if vx < 4, eval('clg');else,eval('clf');end
s=[-fm fm 0 m];
subplot(211),if v==3,axis(s);end,
if n>128,plot(f,mag),else,dtplot(f,mag,'.'),end
if v==4,axis(s);end,
title('FFT magnitude vs f (Hz)'),%pause
subplot(212),s=[-fm fm -p p];
if v==3,axis(s);end,
if n>128,plot(f,ang),else,dtplot(f,ang,'.'),end
if v==4,axis(s);end
title('FFT phase (deg) vs f (Hz)')
subplot

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -