资源描述
,*,Robotics Laboratory,ME,NTU,國立台灣大學機器人實驗室,National Taiwan University,*,*,Robotics Laboratory,ME,NTU,國立台灣大學機器人實驗室,National Taiwan University,National Taiwan University,National Taiwan University,Robotics Laboratory,ME,NTU,國立台灣大學機器人實驗室,*,MATLAB Signal Processing Toolbox,報告日期,:2009/3/11,指導老師,:,黃漢邦教授,報告者,:,黃子豪,MATLAB Signal Processing Toolb,Outline,Time response,Convolution,Fourier,Laplace,Z-transform,DTFT and FFT,IIR and FIR filters,Signal Processing Toolbox Example,FDAtool Example,OutlineTime response,Convolu,波形產生,Wihte noise-randn(t),Square function-square(t),Sinc,函數,-sinc(t),鋸齒波,-sawtooth(t),波形產生Wihte noise-randn(t),步階響應與脈衝響應,差分方程式,y(n)+1.2y(n-1)+0.25y(n-2)=x(n),求出在,n=0,時的步階響應與脈衝響應,filter,指令格式,輸出信號,(yn)=filter(,輸入信號係數,bm,,輸出信號係數,ak,輸入信號,xn),步階響應與脈衝響應差分方程式y(n)+1.2y(n-1)+0,步階響應與脈衝響應,clear;close all;,t=-5:120;n0=0;%impulse starting point,a=1 1.2 0.25;%y(n)coefficient,b=1;%x(n)coefficient,%step signal,x_step=(t=n0);,%impulse signal,x_imp=(t=n0);,%check response,stp_rep=filter(b,a,x_step);,imp_rep=filter(b,a,x_imp);,%plot,figure,subplot(211),stem(t,x_step);xlabel(time sequence(n);ylabel(input signal x);title(Step input signal),subplot(212),步階響應與脈衝響應clear;close all;,步階響應與脈衝響應,stem(t,stp_rep);line(t,zeros(1,length(t);,xlabel(time sequence(n);,ylabel(output signal y(n);,title(Step response),figure,subplot(211),stem(t,x_imp);,xlabel(time sequence);,ylabel(input signal x);,title(Impulse input signal),subplot(212),stem(t,imp_rep);,line(t,zeros(1,length(t);,xlabel(time sequence(n);,ylabel(output signal y(n);,title(Impulse response),步階響應與脈衝響應stem(t,stp_rep);line(,線性摺積運算,輸出性號,y(n),可由將輸入訊號,x(n),與系統脈衝響應,T(n),作線性摺積而求得,函式,:c=conv(a,b),c,的向量長度為,length(a)+length(b)-1,範例,:,c=conv(1 1 1,1 1 1),c=,1 2 3 2 1,線性摺積運算輸出性號y(n)可由將輸入訊號x(n)與系統脈衝,線性摺積運算,差分方程式,y(n)+1.2y(n-1)+0.25y(n-2)=x(n),x(n)=0.5u(n),求出系統的響應,%CHECK linear convolution AND full response,clear;close all;,t=-5:20;,n0=0;%impulse starting point,a=1 1.2 0.25;%y(n)coefficient,b=1;%x(n)coefficient,%step signal,x_step=(t=n0);,x_in=(0.5.t).*x_step;%(0.5)n*u(n),%impulse signal,x_imp=(t=n0);,%impulse response,stp_rep1=filter(b,a,x_imp);,線性摺積運算差分方程式y(n)+1.2y(n-1)+0.25,%convolution,stp_rep2=conv(x_in,stp_rep1);%,輸入信號與脈衝響應的摺積,%check response,stp_rep3=filter(b,a,x_in);%,使用,filter,指令求出系統響應與,stp_rep2,的結果比較,%plot,figure,subplot(211),stem(t,x_in);,xlabel(time sequence(n);,ylabel(input signal x);,title(Input signal),subplot(212),stem(t,stp_rep1);,line(t,zeros(1,length(t);,xlabel(time sequence(n);,ylabel(impulse response y(n);,title(Impulse response),線性摺積運算,%convolution線性摺積運算,線性摺積運算,figure,subplot(211),stem(t,stp_rep2(6:length(t)+5);,line(t,zeros(1,length(t);,xlabel(time sequence(n);,ylabel(output signal y(n);,title(Convolution),subplot(212),stem(t,stp_rep3);,line(t,zeros(1,length(t);,xlabel(time sequence(n);,ylabel(output signal y(n);,title(full response),線性摺積運算figure,Fourier transform,Variable x(,預設輸入變數符號,),w(,預設輸出變數符號,),syms t w,Fourier transformVariable x(預,Inverse Fourier Transform,Variable w(,預設輸入變數符號,),x(,預設輸出變數符號,),Inverse Fourier TransformVari,離散傅立葉轉換,%sin signal,clear;close all;,w1=0.5*pi;%analogue signal frequency,to=1/w1;%analogue signal period,ts=0.5*0.5*to;%sampling period,td=0:ts:4;%time sequence,x_sin=sin(w1.*td);,%fourier transform,w=0:pi/50:2*pi;,for i=1:length(w),for k=1:length(x_sin);,x_ff(k)=x_sin(k)*exp(-j*w(i)*k);%,傅立葉轉換公式,end,x_f(i)=sum(x_ff(:);,end,離散傅立葉轉換%sin signal,離散傅立葉轉換,%plot sin,figure,subplot(211),stem(td,x_sin);,%plot the x-axis,line(td,zeros(1,length(td);,xlabel(time sequence n);,ylabel(Sampling sin(nt);,title(Sampling signal of Sin),subplot(212),plot(w/pi,abs(x_f);,xlabel(pi unit);,ylabel(Magnitude);,line(w/pi,zeros(1,length(w/pi);,title(Fourier transform of sin),離散傅立葉轉換%plot sin,離散傅立葉轉換,使用,fft,指令,FFT,是一種計算,DFT,的方法,可降低計算時間,範例,:,clear,%,時間向量與訊號產生,t=(0:1/100:10-1/100);%Time vector,x=sin(2*pi*15*t)+sin(2*pi*40*t);%Signal,%FFT,轉換,y=fft(x);%Compute FFT of x,m=abs(y);%Magnitude,p=unwrap(angle(y);%Phase(,使相位連續,),f=(0:length(y)-1)*99/length(y);%Frequency vector,離散傅立葉轉換使用fft指令FFT是一種計算DFT的方法,,離散傅立葉轉換,%,畫出振幅圖,plot(f,m);,title(Magnitude);,%,畫出相位圖,set(gca,XTick,15 40 60 85);,figure;,f=(0:length(y)-1)*99/length(y);,plot(f,p*180/pi);,title(Phase);,set(gca,XTick,15 40 60 85);,離散傅立葉轉換%畫出振幅圖,逆離散傅立葉轉換,-,使用,ifft,指令,%,時間向量與訊號,t=(0:1/255:1);,x=sin(2*pi*120*t);,figure;,plot(t,x);,title(x signal);,%,比較原始訊號,x,與重建訊號,y,y=real(ifft(fft(x);,figure;,plot(t,y);,title(y signal);,逆離散傅立葉轉換-使用ifft指令%時間向量與訊號,Laplace Transform,Variable,t(,預設輸入變數符號,),s(,預設輸出變數符號,),Laplace TransformVariable,Inverse Laplace Transform,Variable s(,預設輸入變數符號,),t(,預設輸出變數符號,),Inverse Laplace TransformVari,Z Transform,Variable n(,預設輸入變數符號,),z(,預設輸出變數符號,),範例,:,Syms z n,f=n4,;,ztrans(f),ans=,z*(z3+11*z2+11*z+1)/(z-1)5,Z TransformVariable n(預設輸入變數符,Inverse Z transform,Variable z(,預設輸入變數符號,),n(,預設輸出變數符號,),範例,:,syms z n,f=2*z/(z-2)2;,iztrans(f),ans=,2n*n,Inverse Z transformVariable z,零點,-,極點分析,%,求解根,b=2 3 4;,a=1 3 3 1;,zer=roots(b),pol=roots(a),k=b(1)/a(1),%,化回多項式,bb=k*poly(zer),aa=poly(pol),zplane(zer,pol),零點-極點分析%求解根,Signa
展开阅读全文