In: Electrical Engineering
How to generate spectral plots in MatLab of transfer function
hw = (0.15*s^3+937500*s)/(0.15*s^3+375*s^2+1062500*s+2500000000)
over the range from 100 Hz to 10 kHz, using 200 points per decade.
You can use the logspace command for this purpose.
For example, logspace(a,b,n) will generate n points which are logarithmically equally spaced between decades 10^a rad/s and 10^b rad/s.
If you want to store that in a vector say, y, then you will have to write y=logspace(a,b,n)
Now, for your given question, 100 Hz corresponds to 628 rad/s. 628 rad/s=10^2.8 rad/s. So, here a=2.8
10 kHz corresponds to 62800 rad/s. 62800 rad/s=10^4.8 rad/s. So here b=4.8.
Again, since your requirement is 200 points per decade and there are 2 decades between 100 Hz and 10 kHz, so n=2*200=400. Let the given system is G1. The matlab code is wriiten below.
Matlab code:
s=tf('s'); %% declare s for laplace domain
G1=(0.15*s^3+937500*s)/(0.15*s^3+375*s^2+1062500*s+2500000000); %%G1 as a transfer function
y=logspace(2.8,4.8,400); %%stores the data of 200 points per decade in vector y between 100 Hz and 10 kHz
[mag,phase,y]=bode(G1,y); %%calculates the spectral data (magnitude and phase of G1) at the points in vector y and stores the magnitude data in 'mag' and phase data in 'phase'
Run the code. You will see three vectors y, mag and phase at your workspace. You will get the required data at the required points there
Further in the command window, type
bode_points=[ y, 20*log10 (mag(:,:)'), phase(:,:)' ] %% this will create a 400 x 3 vector with first column as the frequency points y, second column as the magnitude in dB and the third column gives phase in degrees at 400 points, 200 points per decade.
Create a new worspace variable Var1 and copy the frequency data in Var1, create Var2 and copy the magnitude data in Var2, create Var3 and copy the phase data in Var3. Now to get magnitude and phase plots, write in command window:
plot(Var1, Var2); %% gives magnitude plots, do not forget to convert the x-axis to log scale in place of linear
plot(Var1,Var3); %% gives phase plots, do not forget to convert the x-axis to log scale in place of linear.
You will get the required plots