matlabmatlab-guidedistortionnonlinear-functionsmatlab-engine

How can I find the total harmonic distortion of a nonlinear signal. Using matlab


How can I find the total harmonic distortion of a nonlinear signal. For example, Forced Van der pol Oscillator with code as shown below. I have tried the 'thd' function in matlab but I guess I'm missing somethings. This is the equation x''-mu(1-x^2(t))x'(t)+x(t)=Pcos(w*t)

function vdpo()
t=0:0.001:10
mu=2
x0=-2;
v0=2;
p=10; w=7;
 [t,x]= ode45(@f, t, [x0,v0])
function dxdt=f(t,x)
dxdt1=x(2); dxdt2= mu(1-x(1)^2)*x(1)+p*cos(w*t); 
dxdt=[dxdt1 ;dxdt2];
end
end

Solution

  • Try the code below, in which function f(t,x) is our ODE equations and we call function ode45 to use Runge-Kutta methods to solve it.

    function [x]=vdpo()
      t=0:0.001:10
      mu=2
      x0=-2;
      v0=2;
      p=10; w=7;
      [t,x]= ode45(@f, t, [x0,v0])
      function dxdt=f(t,x)
        dxdt1=-x(2)-x(1)+(x(1)^3)/3; dxdt2=-x(1)+p*cos(w*t); 
        dxdt=[dxdt1 ;dxdt2];
      end
    end
    

    However, it is actually a math problem rather than a programming problem. The first thing that we have to do is to transform the equations into a more convenient form by defining y=x'+((x^3)/3-x)*mu, then we have 2 First Order Ordinary Differential Equations so we could call ode45 to solve it. I looked them through at here(page2).

    By calling

    X=vdpo();
    x=X(:,1);
    thd(x) 
    

    we could get an answer like: enter image description here

    p.s. NOT CERTAIN about THD part.