两种方法:
(1).直接看波德图:
又有两种方法:
第一种:使用simulink
再不彷徨:Mablab Simulinkzhuanlan.zhihu.com
第二种:写代码来求波德图
s=tf('s');
G=(s^2+1)*(s^2+s+1)/((s+1)*(s^2+5*s+7));
bode(G);
grid
xlabel('频率f');title(' ');
或者:
num=conv([1,0,1],[1,1,1]);
den=conv([1,1],[1,5,7]);
bode(tf(num,den));
grid
xlabel('频率f');title(' ');
这里再举一个例子,看另外一个传递函数:
num=[1,1,2,1,1];
den=[1,6,12,7];
bode(tf(num,den));
grid
xlabel('频率f');title(' ');
下面链接里有些奇怪的例子。
传递函数的零点、极点怎么解释,有什么用?www.zhihu.com
sys=tf([1],[1,0,1]);
t=0:0.1:10;
y=impulse(sys,t);
plot(t,y);
这个图其实还可以从两种角度考虑:
第1种:
冲激函数输入,
直接进行拉氏逆变换:
第2种:分析冲激输入的频率分量构成,再分析传递函数的幅频,相频响应,看对输入频率的哪个频率作了衰减,为什么只输出w=1的这个纯净频率。
冲激函数输入,
,所有频率分量的模都是1。
下面看这一下这个传递函数的幅频/相频响应图:
num=[1];
den=[1,0,1];
bode(tf(num,den));
grid
xlabel('频率f');title(' ');
可以看到,在w=1的时候,应该是无衰减,其他频率分量会被衰减完毕。
有一个问题想了很久,冲激函数的拉氏变换表示,所有频率分量的模都相等,都是1,表示均匀包含各频率分量,然后通过此传递函数之后,只留下了
这个频率分量,那可不可以理解为此传递函数是个滤波器,精准滤掉了其他频率分量,只留下了
这个频率分量呢?
从传递函数的波德看,在
这个频点,确实系统响应很大,这本身就是系统的一个极点,但是其他频率分量也不是0啊,我认为输出即使最后只剩下了
这个频率分量,前期应该也有一个变化的过程呀,为什么看不到呢?因为波德图只画出正频率部分,那我想是不是负频率部分,相同频率分量都是模相等,幅角相反或者差多少度呢,直接抵消呢。所以我想看看负频率的模和幅角响应情况。可以自己写函数来看(其实这个例子不用写,因为传递函数是s的平方,不论正负频率,其模和相位响应一定是一样的,肯定没有共轭的关系)
自己写函数计算波德图
index=linspace(-1,1,5000);
w=power(10,index);
y=power(i*w,2);
f=abs(power(y+1,-1));
u=20*log(f);
plot(index,u); %波德图
plot(w,u);
计算负频率的波德图:
index=linspace(1,-1,5000);
w=-power(10,index);
y=power(i*w,2);
f=abs(power(y+1,-1));
u=20*log(f);
plot(index,u);
plot(w,u);
如果是滤波器,那么理论上,我输入其他频率信号,比如说sin(2t),那是不是应该输出为0呢?
看一下结果:
num = [1]; %Define numerator polynomial
den = [1 0 1]; %Define denominator polynomial
t = linspace(0, 20, 400001); %Define a time vector
u = sin(2*t); %Compute the cosine input function
u(1:22)=0;
figure(1);
[y, x] = lsim(num, den, u, t); %Compute the cosine input function
plot(t, y, 'r', t, u, 'b'); %Plot the output in red and the input in blue
xlabel('Time(s)');
ylabel('Amplitude');
如果我们输入变为sin(t)呢,可以看一下共振的结果:
num = [1]; %Define numerator polynomial
den = [1 0 1]; %Define denominator polynomial
t = linspace(0, 200, 400001); %Define a time vector
u = sin(t); %Compute the cosine input function
u(1:22)=0;
figure(1);
[y, x] = lsim(num, den, u, t); %Compute the cosine input function
plot(t, y, 'r', t, u, 'b'); %Plot the output in red and the input in blue
xlabel('Time(s)');
ylabel('Amplitude');
所以,这个传递函数没什么特别的,就是在w=1处是极点,不是我想的那种精准滤波的效果。
3.已知传递函数,及输入函数,求输出响应形式clc,clear;
num = [5 0]; %Define numerator polynomial
den = [1 2 101]; %Define denominator polynomial
t = linspace(0, 10, 401); %Define a time vector
u = cos(2*pi*t); %Compute the cosine input function
figure(1);
[y, x] = lsim(num, den, u, t); %Compute the cosine input function
plot(t, y, 'r', t, u, 'b'); %Plot the output in red and the input in blue
xlabel('Time(s)');
ylabel('Amplitude');
syms t
f=exp(t);
Lf=laplace(f);
ezplot(Lf);%这句要去掉
求冲激函数的拉氏变换:
syms t ;
u = sym('dirac(t)'); % 单位脉冲函数dirac(x-a),会有警告弹出来,不用管它
Lf=laplace(u);
ezplot(Lf);%这句要去掉
求阶跃函数的拉氏变换:
syms t ;
e = sym('heaviside(t)'); % 单位阶跃函数heaviside(t-a)
Lf=laplace(e);
ezplot(Lf);%这句要去掉
中间有点小插曲:
比如第1个:
syms t
f=exp(t);
Lf=laplace(f);
ezplot(Lf);%这句要去掉
我当时一直有一个问题想不通,对于拉氏变换作图,本质上想看到的是不同频率分量的模是多少,模应该只有正值,为什么还有负值呢?一直想不通。
后来意识到,这里ezplot,只是对这样一个函数
,或者你可以认为是函数
,
,画图的时候横坐标都是实数。而我们现在这里s是复数,
,所以画的图完全不是我们想要的。
所以laplace这个函数可以用来求一个时域函数的拉氏变换,这个例子中,可以打印中拉氏变换后的函数是什么
这已经达到了我们的目的,如果使用ezplot画图,没有任何意义,反倒会使人误解。
下面举一些例子:
1.冲激函数的合成过程
冲激函数的拉氏变换是1,表示所有频率分量都是1,根据拉氏反变换的公式:
通过MATLAB来模拟无数个
信号来合成冲激函数的过程
t=linspace(-10,10,5000);
u=0;
u1=0;
for k=1:1000
u1=exp(i*k*0.1*t)+exp(-i*k*0.1*t);% 每次加了两个w分量,频率间隔是0.1w
u=u+u1;
plot(t,u);
grid on;
drawnow;
end
https://www.zhihu.com/video/1248642255097053184
通过MATLAB来模拟
的合成过程
的拉氏变换为:
t=linspace(-10,10,100);
u=0;
u1=0;
for k=1:1000000
w=(k-1)*0.00001;
u1=1/(2*3.1415926)*(1/(i*w+3)*exp(i*w*t)+1/(-i*w+3)*exp(-i*w*t));% 每次加了两个w分量,频率间隔是0.1w
u=u+u1;
plot(t,u);
grid on;
drawnow;
end
https://www.zhihu.com/video/1248921905019019264
5.求复数的模和相位
w=linspace(-10,10,5000);
y=power(i*w,2);
f=power(y+1,-1);
u=abs(f);
u1=angle(f);
plot(w,u);
>> plot(w,u1);
6.拉氏变换三维图
二维:
,
第三维:模或者相角
matlab 拉普拉斯变换 - 百度文库wenku.baidu.com
例:阶跃函数
y1=-0.2:0.03:0.2;
>> [x,y]=meshgrid(x1,y1);
>> s=x+i*y;
>> fs=abs(1./s);
>> mesh(x,y,fs);
>> surf(x,y,fs);
>> title('单位阶跃信号拉氏变换曲面图');
>> colormap(hsv);
>> axis([-0.2,0.2,-0.2,0.2,0.2,60]);
>> rotate3d;