For those following along at home, here is the MATALB code for the Bode' Plot of a simple low pass filter using a 10k resistor and 0.1 ufd capacitor. MATLAB is smart enough to center the -3dB point in the center of the graph.
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));
opts = bodeoptions('cstprefs');
opts.PhaseVisible = 'on';
bodeplot(H, opts );
grid on; zoom on;
Octave hasn't implemented the Bode' Plot functionality. Bummer! Octave is free and MATLAB is not.
Octave uses different function names, see below.
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.
% plot transfer function of simple RC low-pass filter
% inputs
fmin = 10; %minimum frequency to plot
fmax = 100e3; %maximum frequency to plot
R = 33; % resistor
C = 4.32e-6; % capacitance
Resr = 2.6; % effective series resistance of capacitor
% calculation
f = logspace(log10(fmin), log10(fmax), 101); % frequencies
Zc = Resr + 1./(2j*pi*f*C); % complex impedance of capacitor
h = Zc ./ (R + Zc); % voltage divider for transfer function
% plot
figure
% plot gain in top panel
subplot(211);
semilogx(f, 20*log10(abs(h)), 'linewidth', 2);
set(gca, 'fontsize', 12, 'fontweight', 'bold');
ylabel('Gain (dB)');
xlabel('Frequency (Hz)');
title({'Low-Pass Filter Bode Plot', ...
[num2str(R),' Ohm R; ', num2str(C*1e6),' uF C with ', ...
num2str(Resr),' Ohm ESR']});
grid
% plot phase in bottom panel
subplot(212);
semilogx(f, angle(h)*180/pi, 'linewidth', 2);
set(gca, 'fontsize', 12, 'fontweight', 'bold');
ylabel('Phase (deg)');
xlabel('Frequency (Hz)');
grid
Cheers!
jason
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:
# 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:
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 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
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
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.
(https://www.eevblog.com/forum/beginners/bode-plot-question-phase-response-of-passive-lp-filter-seems-odd/?action=dlattach;attach=1605499;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. :-+
The Bode plot script you posted, but for Octave:
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.