Hi...
I need to simulate a signal in MatLab but I can't make my simple script to work properly.
The function is a Transfer Function of a given circuit.
The expression is the following
The script I'm trying to use to simulate this expression is:
if true
R1=100;
R2=1e3;
C=1e-6;
% fc=1/(2*pi*R*C);
f=1:1:1e4;
ter1=R2^2;
ter2=(2*pi.*f*C*R1*R2).^2;
ter3=(R1+R2).^2;
ter4=(2*2*pi.*f*C*R1*R2).^2;
mhf=(ter1+ter4)/(ter2+ter3);
mhf=power(mhf, 0.5);
% mod_hf=abs(hf);
% fase_hf=angle(hf);
figure(1);
subplot(2,1,1); plot(f,mhf); grid on;
title('Funcao de Transferencia do Filtro Passa-baixo RC')
xlabel('Frequencia (Hz)')
ylabel('|H(f)|')
% subplot(2,1,2); plot(f,fase_hf);grid on;
% xlabel('Frequency (Hz)')
% ylabel('arg[H(f)] (rad)')
end
I have calculated the result for a few frequencies in calculator and I fot the following values:
f=0Hz--> |H(f)| = 0.9091
f=50Hz--> |H(f)| = 0.9081
f=200Hz--> |H(f)| = 0.8932
f=500Hz--> |H(f)| = 0.8274
f=1000Hz--> |H(f)| = 0.7072
f=5000Hz--> |H(f)| = 0.5169
f=5MHz--> |H(f)| = 0.5
which matches an High-Pass Filter but I can't get the correct plot!!! Any help?

 Akzeptierte Antwort

Star Strider
Star Strider am 12 Sep. 2014

2 Stimmen

Change:
mhf=(ter1+ter4)/(ter2+ter3);
to:
mhf=(ter1+ter4)./(ter2+ter3);
and it works. You need to do element-by-element division as well.

5 Kommentare

Star Strider
Star Strider am 12 Sep. 2014
José Carlos Ferreira’s ‘Answer’ moved here:
Ok, it's working but it's not consistent with results from calculator...
It should start around 0.9091 for f=0Hz and stabilize around 0.5 for high frequencies!!! And the plot is starting around 0.9 and goes up until 2...
Star Strider
Star Strider am 12 Sep. 2014
I would have to see your circuit and analyse it myself to see if there is a problem. You coded your equation correctly with respect to the equation you posted as far as I can determine.
Ok, I'll try to represent it here:
____R1____
________| |______________________________o
|_____C1___| |
__|__
| |
| |
R2 C2
| |
|_____|
|
____________________________|_____________________o
Where C1 = C2 = 1uF and R1 = 100 ohms and R2 = 1000ohms
Star Strider
Star Strider am 13 Sep. 2014
No matter how I analyse that circuit, I get a lowpass characteristic out of it. I can’t reproduce your result.
Stopping here.
José Carlos Ferreira
José Carlos Ferreira am 13 Sep. 2014
Bearbeitet: José Carlos Ferreira am 13 Sep. 2014
If you try to calculate a few values for H(f) and for H(f) phase in a calculator, are your calcs consistent with MatLAb?

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

José Carlos Ferreira
José Carlos Ferreira am 12 Sep. 2014

0 Stimmen

I've changed a little bit the script to use the original Transfer Function and let MatLab compute the Abosulte and Angle values for it but I can't understand why the results from MatLab are not consistent with my calculator results...
R=2.2e3;
C=0.33e-6;
fc=1/(2*pi*R*C);
f=1:1:1e5;
hf=(R2+j*2*pi.*f*C*R1*R2)./((R1+R2)+j*2*pi.*f*C*R1*R2);
mod_hf=abs(hf);
fase_hf=angle(hf);
figure(1);
subplot(2,1,1); plot(f,mod_hf); grid on;
title('Funcao de Transferencia do Filtro Passa-baixo RC')
xlabel('Frequencia (Hz)')
ylabel('|H(f)|')
subplot(2,1,2); plot(f,fase_hf);grid on;
xlabel('Frequency (Hz)')
ylabel('arg[H(f)] (rad)')

2 Kommentare

José-Luis
José-Luis am 12 Sep. 2014
Please don't place a comment as a new answer.
José Carlos Ferreira
José Carlos Ferreira am 12 Sep. 2014
This was not a comment. Was actually a new reply... I'm not very used to this kind of forum! Sorry!

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by