<Work signals & systems with MATLAB>

来源:互联网 发布:景观大数据解压密码 编辑:程序博客网 时间:2024/05/22 16:48
Only for note when learning SIGNAL & SYSTEM with MATLAB

1_Preparation for MATLAB

  • Logic Operator
Logic Operator Name Explantion xor(a,b) Exclusive Or the Exclusive Or of A & B any(A) %%%% If there is at least a NON-ZERO elements in ‘A’, output is TRUE.(i.e 1) all(A) %%%% If all elements in ‘A’ are NON-ZERO elements , output is TRUE.(i.e 1)
  • Dot Multiply & Matrix Multiply
    (Dot divide & Matrix divide ,the same)
    eg:
 A=[1 1 1;1 1 1];B=A; Dot=A.*B; %%Dot=[1 1 1;1 1 1] %% multiply the same position elements Mat=A*B; %%Matrix mutiply
  • Some tips( important ):
dbstop if error     %% db, stop if error exist
t=[-1:0.05:2];  u=(t>0);    %%the definition of u(t)
%%x=sin(t)u(t),represent x1=x(t-0.5),x2=x(2t)x=sin(t).*u;x1tmp=[zeros(1,0.5/0.05),x];x1=x1tmp(1:length(x));x2=x(1:2:length(x));t2=t(1:2:length(x));    %%New definition of t for x2
  • Character caculation
x=sin(2*pi*t).*heaciside(t)     %%heaviside(t)=u(t)x1=subs(x,t,t-1);%% use 't-1' replace 't' in x%% so x1=x(t-1);
  • Ordinary MATLAB command
help general;help elmat;help elfun;%%Fundamental command   

2_LTI system

  • Solution to Differential Equation
    Solution to the H(s) of
    d3r(t)dt3+7d2r(t)dt2+16dr(t)dt+12r(t)=e(t)
a=[1,7,16,12];b=[1];sys=tf(b,a);sys

3_Continuous-Time system analysis

  • solve the differential equation’s homogeneous solution

Solve the homogeneous solution of

d3r(t)dt3+7d2r(t)dt2+16dr(t)dt+12r(t)=e(t)

p=[1 7 16 12];a=roots(p);a%%Output:%%a =%%  -3.0000 + 0.0000i%%  -2.0000 + 0.0000i%%  -2.0000 - 0.0000i%%Meaning:there is a two-fold root of the characteristic equation.It means the homogeneous solution is:%%              rh(t)=(A1t+A2)e^-2t+A3e^-3t
  • solve the particular root of the diffenrential equation
    d2r(t)dt2+2dr(t)dt+3r(t)=de(t)dt+e(t)

    solve:1-e(t)=t2; 2-e(t)=et
a=[1,2,3];b=[1,1];sys=tf(b,a);t=[0:0.01:10]';     %Control the accuracye1=t.^2;        %define e1(t)r1=lsim(sys,e1,t);e2=exp(t);      %define e2(t)r2=lsim(sys,e2,t);

4_Fourier Transfer

  • Use Matrix to complete Fourier Transfer
%%3 methods for Fourier Transfer%%Try to use matrix!!!clc;clear;close all;T=2;N=200;t=[-1:T/N:1-T/N]';f=0*t;f(t>-1/2&t<1/2)=1;W=16*pi;K=200;w=[-8*pi:W/K:8*pi-W/K]';% F=0*w;U=exp(-j*kron(w,t.'));          %%Equal to w*t.'%U=exp(-j*(w*j.'));F=T/N*U*f;V=exp(j*kron(t,w.'));           %%Equal to t*w.'fs=W/(2*pi*K)*V*F;% for k=1:K%     %for n=1:N%         F(k)=T/N*exp(-j*w(k)*t)*f';%         %F(k)=F(k)+T/N*f(n)*exp(-j*w(k)*t(n));%    %end% end% fs=0*t;% for n=1:N%     %for k=1:K%     fs(n)=W/(2*pi*K)*exp(j*w*t(n))*F';%     %fs(n)=fs(n)+W/(2*pi*K)*F(k)*exp(j*w(k)*t(n));%    % end% endfigure;plot(t,f,'-k',t,fs,':k');figure;plot(w,F,'-k');
  • Fourier series of Square Signal(Example)
% Fourier series of Square Signalclc;clear;close all;E=1;T1=1;omg1=2*pi/T1;N=1000;t=linspace(-T1/2,T1/2-T1/N,N)';f=0*t;f(:)=-E/2;f(t>-T1/4&t<T1/4)=E/2;k1=-10;k2=10;k=[k1:k2]';F=1/N*exp(-j*kron(k*omg1,t.'))*f;a0=F(11);ak=F(12:21)+F(10:-1:1);%fs=cos(kron(t,[0:5]*omg1))*[a0;ak(1:5)];f1=cos(kron(t,[0:1]*omg1))*[a0;ak(1:1)];f2=cos(kron(t,[0:2]*omg1))*[a0;ak(1:2)];f3=cos(kron(t,[0:3]*omg1))*[a0;ak(1:3)];f4=cos(kron(t,[0:4]*omg1))*[a0;ak(1:4)];f5=cos(kron(t,[0:5]*omg1))*[a0;ak(1:5)];f6=cos(kron(t,[0:6]*omg1))*[a0;ak(1:6)];f7=cos(kron(t,[0:7]*omg1))*[a0;ak(1:7)];f8=cos(kron(t,[0:8]*omg1))*[a0;ak(1:8)];f9=cos(kron(t,[0:9]*omg1))*[a0;ak(1:9)];plot(t,f,'-k',t,f1,':b',t,f2,':r');hold on,plot(t,f3,':g',t,f4,':m',t,f5,':c');hold on,plot(t,f6,':g',t,f7,':m',t,f8,':c');hold on,plot(t,f9,':y');

5_Laplace Transfer

  • Laplace

Example1:

solve the Laplace transfer & iLaplace transfer of

y=t3
F(s)=10(s+1)(s+5)s(s+1)(s+3)

%%examplesyms t;F=laplace(t^3)syms s;f=ilaplace(10*(s+2)*(s+5)/(s*(s+1)*(s+3))%%Result:%%F=6/s^4%%f=-10/3*exp(-3*t)-20*exp(-t)+100/3

The result:

F(s)=6s4

f=10e3t320et+1003

Example2:

use ‘residue’ to solve the ‘iLaplace transfer’
solve the iLaplace of

F(s)=s3+5s2+9s+7(s+1)(s+2)

b=[1,5,9,7];a1=[1,1];a2=[1,2];a=conv(a1,a2)       %%calculate the coefficient of the                      %%denominator[r,p,k]=residue(b,a);%%The result:%%r= -1 2%%p=-2 -1%%k=1 2       

Result:

F(s)=s+21s+2+2s+1

Next,the iLaplace transfer:
f(t)=δ(t)+2δ(t)e2t+2et,(t>=0)

  • zero point&pole point
%% the change of H(s) varying with the change of the pole pointst=[0:0.1:40]';figure,id=1;for omega=0.5:-0.25:0    for sigma=-0.06:0.03:0.06        p=sigma+j*omega;        if omega~=0            p=[p;p'];        end        [b,a]=zp2tf([],p,1);        subplot(3,5,id);        impulse(b,a,t);        set(gca,'Ylim',[-20,20]);        id=id+1;    endend

这里写图片描述

the graph is the impulse response with the change of the pole
point.(the direction is the same as the x-y coordinate system)

0 0
原创粉丝点击