Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Plot diff plot from a periodic function

  1. Feb 25, 2012 #1
    Hi everyone!
    I've written a M-file to draw a sawtooth periodic function as below:

    function y = sawtooth_w(x)
    % We find the period number of every element
    % in the input vector
    p = 1;
    %k = 4;
    tn = ceil((x+p)/(2*p));

    % and we subtract that corresponding period from
    % the base value. We want final values from -1 to 1
    y = ((x - tn*2*p) + 2*p)/p*4;

    clear, clc, close all

    x = -6 : .01 : 6;
    y = sawtooth_w(x);

    axis([0 6 -5 5])
    ylabel('\bf{Magnetic flow(Web)}')

    now, I want to draw derivative of this function which consists of impulse signals.
    i tried to use diff(y,x) to extract the derivative but it didn't work

    does anybody has any solution???
  2. jcsd
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Can you offer guidance or do you also need help?
Draft saved Draft deleted

Similar Discussions: Plot diff plot from a periodic function