Author Topic: Bode Plot Question - phase response of passive LP filter seems odd...  (Read 2778 times)

0 Members and 1 Guest are viewing this topic.

Offline RoGeorge

  • Super Contributor
  • ***
  • Posts: 6202
  • Country: ro
Re: Bode Plot Question - phase response of passive LP filter seems odd...
« Reply #25 on: October 04, 2022, 01:35:26 pm »
Octave  hasn't implemented the Bode' Plot functionality.  Bummer!  Octave is free and MATLAB is not.

Octave has Bode plots, too.  :-+

In Octave it's called "bode" what in Matlab is "bodeplot".  Octave's "bode" is from the package "control" and has to be loaded before using, and of course installed in case it wasn't installed already.  Also, "bodeoptions" is something specific to matlab, to load user's preferred lookout for charts.

TL;DR, to install Octave in Ubuntu 22.04 LTS I did this:
Code: [Select]
# add octave repository and update the list of available software
sudo apt-add-repository ppa:octave/stable
sudo apt-get update

# install Octave, then install the most needed Octave packages, "control" (octave-control) is one of them
sudo apt-get install octave
sudo apt-get install octave-control octave-image octave-io octave-optim octave-signal octave-statistics

# the install commands I've just run are from https://wiki.octave.org/Octave_for_Debian_systems

The Bode plot script you posted, but for Octave:
Code: [Select]
pkg load control;

close all
clearvars

s = tf('s')
R = 1.0*10^4;   % 10k resistor
C = 0.1*10^-6;  % 0.1 ufd capacitor
H = 1/(1+s*(R*C));

bode(H);
grid on; zoom on;
 
The following users thanked this post: rstofer, jasonRF

Offline RoGeorge

  • Super Contributor
  • ***
  • Posts: 6202
  • Country: ro
Re: Bode Plot Question - phase response of passive LP filter seems odd...
« Reply #26 on: October 04, 2022, 02:04:27 pm »
... the images.  I tried to make them inline

The inline feature doesn't work on this forum.  To insert inline pics, you have to post the message first (with its pics as attachements at the end), then edit your message again to add links to the now already posted images.

After hitting "Publish", go to your own post and click on one of the thumbnails to enlarge it.  Once enlarged the pic, right click and "Copy Image Link" get the image URL.

Then edit your just published post, and paste the copied URL inside the text, but you have to put the URL between the img tags (press the binocular "Insert Image" icon from the edit-post icons-bar, then paste the image URL between the img tags).  In text edit mode, it should look like this:

instead of
Code: [Select]
Now, the theory (including the ESR) says I should measure the following phase shown in the third image.
[attachimg=3]
This is close enough to the measurement that I would say the measurement is expected.

should become
Code: [Select]
Now, the theory (including the ESR) says I should measure the following phase shown in the third image.
[img]https://www.eevblog.com/forum/beginners/bode-plot-question-phase-response-of-passive-lp-filter-seems-odd/?action=dlattach;attach=1605499;image[/img]
This is close enough to the measurement that I would say the measurement is expected.

and it will display like this:
Now, the theory (including the ESR) says I should measure the following phase shown in the third image.

This is close enough to the measurement that I would say the measurement is expected.


By the way, thanks for the plots and the detailed explanation+measurements you posted, I found that very useful.  :-+
« Last Edit: October 04, 2022, 02:12:53 pm by RoGeorge »
 
The following users thanked this post: jasonRF

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 9890
  • Country: us
Re: Bode Plot Question - phase response of passive LP filter seems odd...
« Reply #27 on: October 04, 2022, 03:20:37 pm »
Octave  hasn't implemented the Bode' Plot functionality.  Bummer!  Octave is free and MATLAB is not.

Octave has Bode plots, too.  :-+


I kept getting 'not implemented errors' and gave up too soon!  Old age and a short attention span...

I prefer to use MATLAB but I prefer to post Octave code.   I usually test the code on both platforms just to insure compatibility and, in this case, the 'pkg load control' statement is not compatible with MATLAB.  Just comment it out, no big deal.

Thanks for the fix!

« Last Edit: October 04, 2022, 03:23:27 pm by rstofer »
 
The following users thanked this post: jasonRF

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 9890
  • Country: us
Re: Bode Plot Question - phase response of passive LP filter seems odd...
« Reply #28 on: October 05, 2022, 12:43:23 am »
Thanks for posting that code!  I use Matlab every day at work and didn't realize it had built-in Bode plots - although I don't do electronics for a living so perhaps that is why. 

Anyway, I think posting a snippet of code is a great idea, so here is a little code to generate the Bode plot of the low-pass filter including the ESR of the capacitor.  It should work in both Octave and Matlab.  Not as clean as using built-in Matlab functions, but I only have Octave at home.   The actual calculation is just a couple of lines, but making a reasonable-looking plot takes a few more. 

Using the built-in MATLAB functions can cause incompatibility with Octave.  I try to avoid that and I failed.  Turns out I had a Bode' plot in my Octave folder and overlooked it.

I use every opportunity to post code snippets or other plots/graphic images.  I think it adds a lot to the conversation.
 

Offline ledtester

  • Super Contributor
  • ***
  • Posts: 3036
  • Country: us
Re: Bode Plot Question - phase response of passive LP filter seems odd...
« Reply #29 on: October 05, 2022, 02:19:29 pm »

The Bode plot script you posted, but for Octave:
Code: [Select]
pkg load control;

close all
clearvars

s = tf('s')
R = 1.0*10^4;   % 10k resistor
C = 0.1*10^-6;  % 0.1 ufd capacitor
H = 1/(1+s*(R*C));

bode(H);
grid on; zoom on;


FWIW, I was able to run this code at https://octave-online.net/ -- a free online Octave IDE.

Just paste the code into the "Octave Command Prompt" at the bottom of the page.
Clicking on the "graph" icon allows you to save the plots as either a png or svg.

 
The following users thanked this post: RoGeorge, jasonRF


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf