Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6557731
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:06:43+00:00 2026-05-25T13:06:43+00:00

I would like to code something that could take some sort of input and

  • 0

I would like to code something that could take some sort of input and identify it as a square wave, triangle wave, or some sort of waveform. I also need some way of generating said waves.

I do have experience with C/C++, however, I’m not sure how I would approach simulating all of this. Eventually, I would like to translate it to a microcontroller program for reading its analog input to determine the waveform.

EDIT: Sorry; I should have mentioned it would be at a known frequency and the amplitude should be unknown.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T13:06:44+00:00Added an answer on May 25, 2026 at 1:06 pm

    Generating the waves is significantly easier than identifying them. I have a small project that does some wave generation. Here’s an example from my project:

        float amplitude;
        switch (sound->wavetype)
        {
            case LA_SQUARE:
                amplitude = sound->theta > .5 ? 1.0 : -1.0;
                break;
            case LA_SINE:
                amplitude = sin(2 * PI * sound->theta);
                break;
            case LA_TRIANGLE:
                amplitude = sound->theta > .5 ? 4 * sound->theta - 3 : -4 * sound->theta + 1;
                break;
            case LA_SAWTOOTH:
                amplitude = 2 * sound->theta - 1.0;
                break;
            case LA_NOISE:
                amplitude = ((float)rand() / RAND_MAX);
                break;
            default:
                ;
        }
    

    theta here is updated at every frame along the wave form and is dependent on the frequency of the wave you’re creating.

    As for identifying waves, if you know you’re just going to be getting simple, unmixed square, triangle or sine waves, you can probably just do some simple tests. Look at the change in amplitude at any two points along the wave. If they’re the same, square wave. If they’re changing linearly (that is, if the change in amplitude is constant) you’ve got a triangle wave (or a sawtooth, if you’re making that distinction). Otherwise, it’s a sine wave. Keep in mind this check only works if you’re expecting just those types of wave, and they’re not being mixed or anything. There’s some other edge cases in there I can think of but I’ll let you worry about that.

    If you’re doing anything fancier, you’re going to need to probably look up a book that specializes in this sort of thing, like the one suggested in the comments section.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to do something like the following: def add(a, b): #some code
I would like to be able to do something like (psuedo-code): if (classAvailable) {
I would like a code sample for a function that takes a tDateTime and
I would like to create (in code) tree of controls that would render as
I'm having something of a dilemma and would appreciate some input. I have this
I'm a LOB .NET applications developer that would like to do some www consumer
We have some configuration issues that we would like to solve by putting in
We have some code that looks like this: class Serializer { public: template<class Type>
I have JSF code like: <h:inputText id=from value=#{fromToMBean.fromName}/> I would like to get this
To help users, I would like my code to discover Oracle databases on the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.