Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

How to plot frequency error ?

Asked by Aniket on 7 Feb 2013

I am giving input signal as a chirp with time varying frequencies. i want to plot frequency error of input signal frequency and frequency adapted by oscillator. how should i do it ? please suggest me.

here is code ......

************************

Fs=1000; % sample rate
tf=50; % 2 seconds
t=0:1/Fs:tf-1/Fs;
f1=100;
f2=200; % start @ 100 Hz, go up to 200Hz
semi_t=0:1/Fs:(tf/2-1/Fs);
sl=2*(f2-f1/2);
f1=f1*semi_t+(sl.*semi_t/50);
f2=f1(end)+f2*semi_t-sl.*semi_t/2;
f=[f1 f2];
y=1.33*cos(2*pi*f.*t);
ti = tt ;
[T Y]= ode45(@(t,y) myeqd(t,y,ti,xx),tt,[5;5;90]);
plot (T,Y)

***********************

the ode function

*************************

function dz = myeqd(t,y,ti,xx)
dz = zeros(3,1);
mu=1;
r= sqrt(y(1)^2 + y(2)^2);
K=1000;
F=interp1(ti,xx,t);
dz(1)= (mu - r^2)*y(1) - y(3)*y(2) +K*F;
dz(2) = (mu - r^2)*y(2) + y(3)*y(1);
dz(3) = (-K*F) * (y(2)/sqrt(y(1)^2 + y(2)^2));

********************************************

0 Comments

Aniket

Products

No products are associated with this question.

0 Answers

Contact us