2014-01-05 108 views
2

我想寫一個腳本來繪製帶通濾波器傳遞函數[H(f)]的圖,| H(f)|對頻率和H(f)(度)對頻率的階段,即時通訊非常新的matlab,所以語法不是100%,我感到困惑,因爲一切都是以矩陣形式自動格式化。下面 是我的腳本:如何在Matlab中繪製帶通濾波器傳遞函數的頻率響應?

% RCL circuit: band-pass filter 
R=55590; L=0.9571; C=48.811*10.^(-9);  % values of the Resistor and Capacitor 
f=(0:60e3); w=2*pi*f;      % frequency (f) range of measurements 
H=(R./(sqrt(R^2+(w*L-(1./(w*C))).^2))); % Transfer Function 

% Magnitude (absolute value) of the transfer function 
plot(f,abs(H),'LineWidth',2); grid on; hold on 
xlabel('Frequency [Hz]','FontSize',20); ylabel('|H(f)|','FontSize',20) 

plot(f,angle(H)*180/pi,'LineWidth',2); grid on; hold on 
xlabel('Frequency [Hz]','FontSize',18); 
ylabel('phase of H(f) [degrees]','FontSize',20) 

這是使用 enter image description here

傳遞函數公式IM下面是什麼我的實驗結果是另一個PIC和預期的圖,我只是不明白爲什麼MATLAB沒有繪製我想要的? enter image description here

+0

因此,您計算H並繪製其絕對值與頻率的關係曲線。問題是什麼? –

+0

我的問題是爲什麼它沒有這樣做? – Theo

回答

5

您是否知道bodeplot功能?

一個簡單的第二階帶通傳遞函數爲:

enter image description here

你只需要與bodeplot插入你的價值觀到Matlab的tf功能並繪製它:

R = 55590; 
L = 0.9571; 
C = 48.811*10.^(-9); 

% tf creates transfer function object 
sys = tf([R*C 0] , [L*C R*C 1]);  % [R*C 0] vector of numerator coeffcients 
             % R*C*s + 0*1 
             % [L*C R*C 1] vector of denominator coeff. 
             % L*C*s^2 + R*C*s + 0*1 

bodeplot(sys)       % plot command to plot frequency response 
             % of magnitude and phase 

,它地塊:

enter image description here

或者,如果您需要更多輸出(如幅度和相位)作爲變量,則使用bode,則圖相等。但bodeplot提供更多額外的情節定製選項。


關於你的評論,你需要一個線性軸:

你只需要繪圖命令前加上下面幾行:

P = bodeoptions;   % handle to plot options 
P.MagScale = 'linear'; 
P.MagUnits = 'abs'; 
bodeplot(sys,P)   % plot command with custom options 

所以它看起來如下:

enter image description here

用於調整頻率軸限制,可使用:

P.XLim = [1 60e3]; 

或模擬的幅度:

P.YLim = [0 1]; 

我會建議對線性頻率軸,但如果你真的想要的話,你可以使用:

P.FreqScale = 'linear'; 
P.FreqUnits = 'Hz';  % optional 

如果您想繪製您的實驗數據以及上面的圖,請按照this example

使用bode可以從您的傳輸函數中獲得同樣格式的數據,如您的實驗數據並使用semilogx來繪製它。

freqVec = logspace(-1, 3, 5000); 
[mag, phs] = bode(sys, freqVec * (2*pi)); 
mag = db(mag(:)); 
phs = phs(:); 
figure; 
subplot(211) 
semilogx(freqVec, mag); hold on 
semilogx(freqVec, experimentalDataMagnitude); hold off 
grid on 
title('System Bode Plot') 
ylabel('Magnitude (dB)') 
subplot(212) 
semilogx(freqVec, phs); hold on 
semilogx(freqVec, experimentalDataPhase); hold off 
grid on 
ylabel('Phase (deg)') 
xlabel('Frequency (Hz)') 
+0

不我不是,但它不是真正的事情之後,我需要線性軸,因爲我的圖形需要類似於我的實驗數據。 – Theo

+0

@Theo線性頻率軸非常罕見,因爲線性大小可以查看我的編輯。 – thewaywewalk

+0

非常感謝你,但是你可以評論你的腳本,因爲有很多新功能,你在哪裏輸入傳遞函數方程?或者它是預定義函數的一部分?謝謝 – Theo

相關問題