Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. Squarefunction
Forum Updated to NodeBB v4.3 + New Features

Squarefunction

Scheduled Pinned Locked Moved Solved C++ Gurus
3 Posts 2 Posters 351 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    felix6262
    wrote on last edited by
    #1

    Hey, guys. I want to creat a chart with an Square signal. I already wrote the function from the fourier transformation. But i only get a sinus function.

    double SimRechteckSensor::getValue()
    {
        static double x;
        double fx;
        fx=(4/M_PI)*((sin(x))+((1/3)*sin(3*x))+((1/5)*sin(5*x))+((1/7)*sin(7*x))+((1/9)*sin(9*x)));
        x+=0.1;
        return fx;
    }
    
    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      I haven't done this kind of math in around 10 years but isn't the square wave the limit of the fourier (i.e. you need infinite armonics to obtain it) making it impossible in practice to build that way?

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      4
      • F Offline
        F Offline
        felix6262
        wrote on last edited by
        #3

        yes thats true. But if you want to get a chart with a fourier transformation, i found out, that you have to type in:

        fx=(4/M_PI)*((sin(x))+((1/3.0)sin(3x))+((1/5.0)*sin(5x))+((1/7.0)sin(7x))+((1/9.0)sin(9x)));
        Because you are trying to divide a integer by integer. That gives you a integer back. In this case its zero. When you typ for example 3.0 insted of 3 you divide integer by double and then you get a double back. Now simply find a good solution for x to get a nice chart. Should be working. But, how VRonin said, its not a real square Chart (watch youtube).

        In my program i programmed some if else cases that gives me for y value 1 or 0 back.

        1 Reply Last reply
        3

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved