画包络函数:

function hua_baol (y,fs,style,varargin)
%画包络函数是hua_baoluo的代码简化版
%输入参数要么是3个,要么是5个
%当三个的时候
y_hht=hilbert(y);%希尔伯特变换
y_an=abs(y_hht);%包络信号
%y_an=y_an-mean(y_an);%去除直流分量
    if nargin==3
        hua_fft(y_an,fs,style);
    elseif nargin==5
        f1=varargin{1};
        f2=varargin{2};
        hua_fft(y_an,fs,style,f1,f2);
    else
        error('调用函数的输入参数数目不正确,输入参数只能是三个或者五个');
    end
end

测试函数

x=@(t) (1+0.5*cos(9*pi*t)).*cos(200*pi*t+2*cos(10*pi*t))+sin(pi*t).*sin(30*pi*t);
t=0:0.01:9.99;
fs=1000;
y=x(t);
subplot(311);plot(t,y);
subplot(312);hua_fft(y,fs,1);%直接画出幅值谱
subplot(313);hua_fft(y,fs,1,0,250);%直接画出幅值谱,并且只画出0-250Hz范围的幅值谱
figure;
subplot(311);plot(t,y);
subplot(312);hua_baol(y,fs,1);%直接画出包络谱
subplot(313);hua_baol(y,fs,1,0,250);%直接画出包络谱,并且只画出0-250Hz范围的包络

 

好用的画包络谱和幅值谱matlab函数

Logo

一站式虚拟内容创作平台,激发创意,赋能创作,进入R空间,遇见同道,让优质作品闪耀发光。​

更多推荐