generating waves

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • pillip

    #1

    generating waves

    I am trying to generate a number of waves. For square wave i am using a mod
    funcion in a loop:
    (i & 2)* amplitude , and running a circular buffer. For a triangular and saw
    tooth waves I am all out of ideas. Now i know a saw tooth function is
    already implemented in C, but i was wondering if it could be produced
    without it.
    Thanks in advance


  • Mac

    #2
    Re: generating waves

    On Fri, 06 Feb 2004 03:14:48 +0000, pillip wrote:
    [color=blue]
    > I am trying to generate a number of waves. For square wave i am using a mod
    > funcion in a loop:[/color]

    Generating waves requires special hardware that is not on-topic in this
    newsgroup. Of course, it sounds as though you really want to create a
    numerical representation of a wave. This could potentially be on topic
    here provided there is some C code involved.
    [color=blue]
    > (i & 2)* amplitude , and running a circular buffer. For a triangular and saw
    > tooth waves I am all out of ideas. Now i know a saw tooth function is
    > already implemented in C,[/color]

    Huh? What are you talking about? Implemented where, and by whom? Surely it
    is not part of standard C?
    [color=blue]
    > but i was wondering if it could be produced
    > without it.[/color]

    "It produced without it?" To what does "it" refer? Do you mean could a saw
    tooth function be produced without c? If so, this is definitely the wrong
    group. Do you mean could a sawtooth function be produced in c "from
    scratch?" If so, I'm sure it can. What have you tried? People don't
    usually just write your program for you. They expect you to try first, and
    then they'll help you.

    Can you write an equation for one iteration of a sawtooth in a
    mathematical notation?
    [color=blue]
    > Thanks in advance[/color]

    Good luck.

    --Mac

    Comment

    • pillip

      #3
      Re: generating waves

      Obviously you havent heard of:
      value = fmod(currentTim e, wavePeriod
      which generates a saw tooth for the desired period



      "Mac" <foo@bar.net> wrote in message
      news:pan.2004.0 2.06.06.50.06.6 37145@bar.net.. .[color=blue]
      > On Fri, 06 Feb 2004 03:14:48 +0000, pillip wrote:
      >[color=green]
      > > I am trying to generate a number of waves. For square wave i am using a[/color][/color]
      mod[color=blue][color=green]
      > > funcion in a loop:[/color]
      >
      > Generating waves requires special hardware that is not on-topic in this
      > newsgroup. Of course, it sounds as though you really want to create a
      > numerical representation of a wave. This could potentially be on topic
      > here provided there is some C code involved.
      >[color=green]
      > > (i & 2)* amplitude , and running a circular buffer. For a triangular and[/color][/color]
      saw[color=blue][color=green]
      > > tooth waves I am all out of ideas. Now i know a saw tooth function is
      > > already implemented in C,[/color]
      >
      > Huh? What are you talking about? Implemented where, and by whom? Surely it
      > is not part of standard C?
      >[color=green]
      > > but i was wondering if it could be produced
      > > without it.[/color]
      >
      > "It produced without it?" To what does "it" refer? Do you mean could a saw
      > tooth function be produced without c? If so, this is definitely the wrong
      > group. Do you mean could a sawtooth function be produced in c "from
      > scratch?" If so, I'm sure it can. What have you tried? People don't
      > usually just write your program for you. They expect you to try first, and
      > then they'll help you.
      >
      > Can you write an equation for one iteration of a sawtooth in a
      > mathematical notation?
      >[color=green]
      > > Thanks in advance[/color]
      >
      > Good luck.
      >
      > --Mac
      >[/color]


      Comment

      • CBFalconer

        #4
        Re: generating waves

        Mac wrote:[color=blue]
        > On Fri, 06 Feb 2004 03:14:48 +0000, pillip wrote:
        >[color=green]
        > > I am trying to generate a number of waves. For square wave i
        > > am using a mod funcion in a loop:[/color]
        >
        > Generating waves requires special hardware that is not on-topic in
        > this newsgroup. Of course, it sounds as though you really want to
        > create a numerical representation of a wave. This could potentially
        > be on topic here provided there is some C code involved.
        >[color=green]
        > > (i & 2)* amplitude , and running a circular buffer. For a
        > > triangular and saw tooth waves I am all out of ideas. Now i know
        > > a saw tooth function is already implemented in C,[/color]
        >
        > Huh? What are you talking about? Implemented where, and by whom?
        > Surely it is not part of standard C?
        >[color=green]
        > > but i was wondering if it could be produced without it.[/color]
        >
        > "It produced without it?" To what does "it" refer? Do you mean could
        > a saw tooth function be produced without c? ... snip ...[/color]

        Methinks the OP has already produced wave generators in c.l.c.
        :-) Of complaints, of revulsion, of trivial commentary, etc.

        --
        Chuck F (cbfalconer@yah oo.com) (cbfalconer@wor ldnet.att.net)
        Available for consulting/temporary embedded and systems.
        <http://cbfalconer.home .att.net> USE worldnet address!


        Comment

        • Simon Biber

          #5
          Re: generating waves

          "pillip" <pillip@pillip. com> wrote:[color=blue]
          > I am trying to generate a number of waves. For square wave i am using
          > a mod funcion in a loop: (i & 2)* amplitude , and running a circular
          > buffer. For a triangular and saw tooth waves I am all out of ideas.
          > Now i know a saw tooth function is already implemented in C, but i
          > was wondering if it could be produced without it.[/color]

          Here are some functions and ASCII art graphs of them.

          y = fmod(x, 1)

          0 1 2 3 4 5 6
          1 | /| /| /| /| /| /|
          | / | / | / | / | / | / |
          | / | / | / | / | / | / |
          | / | / | / | / | / | / |
          0 |/____|/____|/____|/____|/____|/____|________ x
          |
          |
          |
          |
          -1 |


          y = fabs(2 - fmod(x, 4.0)) - 1

          0 1 2 3 4 5 6 7 8
          1 |\ /\ /
          | \ / \ /
          | \ / \ /
          | \ / \ /
          0 |____\_________ _/________\______ ____/______ x
          | \ / \ /
          | \ / \ /
          | \ / \ /
          | \ / \ /
          -1 | \/ \/


          y = 2 * round(fmod(x, 1)) - 1

          0 1 2 3 4 5 6 7
          1 | _____ _____ _____
          | | | | | | |
          | | | | | | |
          | | | | | | |
          0 |_____|_____|__ ___|_____|_____ |_____|_______ x
          | | | | | | |
          | | | | | | |
          | | | | | | |
          -1 |_____| |_____| |_____| |_____

          --
          Simon.


          Comment

          • Mark A. Odell

            #6
            Re: generating waves

            "pillip" <pillip@pillip. com> wrote in
            news:8f5eba1952 e098e5c9b497e90 2aa6d24@news.te ranews.com:
            [color=blue]
            > Obviously you havent heard of:
            > value = fmod(currentTim e, wavePeriod
            > which generates a saw tooth for the desired period[/color]

            Which standard C library is that in? What header file should I include?
            What? It's not in the standard C library? Oh, then it is off-topic here.

            --
            - Mark ->
            --

            Comment

            • Mark A. Odell

              #7
              Re: generating waves

              "Mark A. Odell" <nospam@embedde dfw.com> wrote in
              news:Xns9487897 7A3EB7Copyright MarkOdell@130.1 33.1.4:
              [color=blue][color=green]
              >> Obviously you havent heard of:
              >> value = fmod(currentTim e, wavePeriod
              >> which generates a saw tooth for the desired period[/color]
              >
              > Which standard C library is that in? What header file should I include?
              > What? It's not in the standard C library? Oh, then it is off-topic here.[/color]

              Eh, heh. I'm just finishing up some crow over here. Obviously, I don't use
              the math lib on 8-bit micros that much. My apologies.

              --
              - Mark ->
              --

              Comment

              • Christopher Benson-Manica

                #8
                Re: generating waves

                Mark A. Odell <nospam@embedde dfw.com> spoke thus:
                [color=blue]
                > Eh, heh. I'm just finishing up some crow over here. Obviously, I don't use
                > the math lib on 8-bit micros that much. My apologies.[/color]

                Don't feel too bad - I had a similar post written and one :wq away
                from posting, but something said "Hm, better check K&R" first... ;)

                --
                Christopher Benson-Manica | I *should* know what I'm talking about - if I
                ataru(at)cybers pace.org | don't, I need to know. Flames welcome.

                Comment

                • Mac

                  #9
                  Re: generating waves

                  On Fri, 06 Feb 2004 14:45:13 +0000, pillip wrote:

                  [original post altered to fix top-posting]
                  [color=blue]
                  > "Mac" <foo@bar.net> wrote in message
                  > news:pan.2004.0 2.06.06.50.06.6 37145@bar.net.. .[color=green]
                  >> On Fri, 06 Feb 2004 03:14:48 +0000, pillip wrote:
                  >>[color=darkred]
                  >> > I am trying to generate a number of waves. For square wave i am using a[/color][/color]
                  > mod[color=green][color=darkred]
                  >> > funcion in a loop:[/color]
                  >>
                  >> Generating waves requires special hardware that is not on-topic in this
                  >> newsgroup. Of course, it sounds as though you really want to create a
                  >> numerical representation of a wave. This could potentially be on topic
                  >> here provided there is some C code involved.
                  >>[color=darkred]
                  >> > (i & 2)* amplitude , and running a circular buffer. For a triangular and[/color][/color]
                  > saw[color=green][color=darkred]
                  >> > tooth waves I am all out of ideas. Now i know a saw tooth function is
                  >> > already implemented in C,[/color]
                  >>
                  >> Huh? What are you talking about? Implemented where, and by whom? Surely it
                  >> is not part of standard C?
                  >>[color=darkred]
                  >> > but i was wondering if it could be produced
                  >> > without it.[/color]
                  >>
                  >> "It produced without it?" To what does "it" refer? Do you mean could a saw
                  >> tooth function be produced without c? If so, this is definitely the wrong
                  >> group. Do you mean could a sawtooth function be produced in c "from
                  >> scratch?" If so, I'm sure it can. What have you tried? People don't
                  >> usually just write your program for you. They expect you to try first, and
                  >> then they'll help you.
                  >>
                  >> Can you write an equation for one iteration of a sawtooth in a
                  >> mathematical notation?
                  >>[color=darkred]
                  >> > Thanks in advance[/color]
                  >>
                  >> Good luck.
                  >>
                  >> --Mac
                  >>[/color][/color]

                  [top-posting relocated here]
                  [color=blue]
                  > Obviously you havent heard of:
                  > value = fmod(currentTim e, wavePeriod
                  > which generates a saw tooth for the desired period
                  >
                  >
                  >[/color]

                  In what sense can a single value be considered a sawtooth wave? Anyway, it
                  seems that you clearly have the skill and resourcefulness to generate your
                  own sawtooth.

                  Here's one approach:

                  #include <stdio.h>
                  #include <stdlib.h>

                  struct waveform
                  { int size;
                  double *data;
                  };

                  void destroy_wavefor m(struct waveform *w)
                  { if (w != NULL)
                  free(w->data);
                  free(w);
                  }

                  struct waveform *sawtooth(doubl e amplitude, int period)
                  { struct waveform *w;
                  double delta;
                  int i;

                  if (period <= 1)
                  return NULL;
                  w = malloc(sizeof *w);
                  if (w == NULL)
                  return NULL;
                  w->data = malloc(sizeof *w->data * period);
                  if (w->data == NULL)
                  { free(w);
                  return NULL;
                  }
                  delta = amplitude / (period - 1);
                  for(i = 0; i < period; i++)
                  w->data[i] = delta * i;
                  w->size = period;
                  return w;
                  }

                  int main(void)
                  { int i;
                  struct waveform *w;
                  w = sawtooth(10, 10);
                  if (w == NULL)
                  { puts("Error, out of memory.\n");
                  return EXIT_FAILURE;
                  }
                  for (i = 0; i < w->size; i++)
                  printf("data[%d] = %f\n", i, w->data[i]);
                  return EXIT_SUCCESS;
                  }

                  regards,
                  Mac

                  Comment

                  Working...