Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. could anyone tell me what's the error with this code?

could anyone tell me what's the error with this code?

Scheduled Pinned Locked Moved C / C++ / MFC
c++designtoolshelpquestion
24 Posts 8 Posters 0 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.
  • A ashwiny

    // nonrec.cpp -- non-recursive filter design // NRLowPass() build NR low-pass filter // NRHighPass() build NR high-pass filter // NRBandPass() build NR band-pass filter #include "tools.h" #include "ltisys.h" // sinc() or sin(x)/x function double sinc(double x) { if (x==0) return cos(x); else return sin(x)/x; } // Create non-recursive low-pass filter by Fourier Transform method LTISystem NRLowPass( double freq, // corner freq (fraction of sampling rate) int ncoeff // # coefficients ) // returns LTI system to specification { int i; // convert frequency double omega = 2 * PI * freq; // build half-sized window from sinc function int nhalf = ncoeff/2; Waveform hwv(nhalf,1.0); for (i=1;i<=nhalf;i++) hwv[i] = omega * sinc(i*omega)/PI; // window with (half-)hamming window for (i=1;i<=nhalf;i++) hwv[i] *= 0.54 + 0.46 * cos(i*PI/nhalf); // create new LTI System LTISystem lpfilt(2*nhalf,0); // copy impulse response into system // (indexed -nhalf .. 0 .. nhalf) lpfilt.a[nhalf] = omega/PI; for (i=1;i<=nhalf;i++) { lpfilt.a[nhalf-i] = hwv[i]; lpfilt.a[nhalf+i] = hwv[i]; } return lpfilt; } // create high-pass non-recursive filter from low-pass prototype LTISystem NRHighPass( double freq, // corner freq (fraction of sampling rate) int ncoeff // # coefficients ) // returns LTI system { // get low-pass version LTISystem hpfilt = NRLowPass(0.5-freq,ncoeff); // now modulate with cos(n*PI) = +1,-1,+1,-1,... int nhalf = hpfilt.a.count()/2; for (int i=1;i<=nhalf;i+=2) { hpfilt.a[nhalf-i] = -hpfilt.a[nhalf-i]; hpfilt.a[nhalf+i] = -hpfilt.a[nhalf+i]; } return hpfilt; } // create band-pass non-recursive filter from low-pass prototype LTISystem NRBandPass( double lofreq, // low corner freq (fraction of sampling rate) double hifreq, // high corner freq (fraction of sampling rate) } int ncoeff // # coefficients ) // returns LTI system { // get low-pass prototype LTISystem bpfilt = NRLowPass((hifreq-lofreq)/2,ncoeff); // now modulate with cos(n*centrefreq) int nhalf = bpfilt.a.count()/2; double cf = 2*PI*(lofreq+hifreq)/2; bpfilt.a[nhalf] = 2 * bpfilt.a[nhalf]; for (int i=1;i<=nhalf;i++) { bpfilt.a[nhalf-i] = 2 * bpfilt.a[nhalf-i] * cos(i*cf); bpfilt.a[nhalf+i] = 2 * bpfilt.a[nhalf+i] * cos(i*cf); } return bpfilt; }

    H Offline
    H Offline
    Hamid Taebi
    wrote on last edited by
    #3

    Did you get any error?

    1 Reply Last reply
    0
    • A ashwiny

      // nonrec.cpp -- non-recursive filter design // NRLowPass() build NR low-pass filter // NRHighPass() build NR high-pass filter // NRBandPass() build NR band-pass filter #include "tools.h" #include "ltisys.h" // sinc() or sin(x)/x function double sinc(double x) { if (x==0) return cos(x); else return sin(x)/x; } // Create non-recursive low-pass filter by Fourier Transform method LTISystem NRLowPass( double freq, // corner freq (fraction of sampling rate) int ncoeff // # coefficients ) // returns LTI system to specification { int i; // convert frequency double omega = 2 * PI * freq; // build half-sized window from sinc function int nhalf = ncoeff/2; Waveform hwv(nhalf,1.0); for (i=1;i<=nhalf;i++) hwv[i] = omega * sinc(i*omega)/PI; // window with (half-)hamming window for (i=1;i<=nhalf;i++) hwv[i] *= 0.54 + 0.46 * cos(i*PI/nhalf); // create new LTI System LTISystem lpfilt(2*nhalf,0); // copy impulse response into system // (indexed -nhalf .. 0 .. nhalf) lpfilt.a[nhalf] = omega/PI; for (i=1;i<=nhalf;i++) { lpfilt.a[nhalf-i] = hwv[i]; lpfilt.a[nhalf+i] = hwv[i]; } return lpfilt; } // create high-pass non-recursive filter from low-pass prototype LTISystem NRHighPass( double freq, // corner freq (fraction of sampling rate) int ncoeff // # coefficients ) // returns LTI system { // get low-pass version LTISystem hpfilt = NRLowPass(0.5-freq,ncoeff); // now modulate with cos(n*PI) = +1,-1,+1,-1,... int nhalf = hpfilt.a.count()/2; for (int i=1;i<=nhalf;i+=2) { hpfilt.a[nhalf-i] = -hpfilt.a[nhalf-i]; hpfilt.a[nhalf+i] = -hpfilt.a[nhalf+i]; } return hpfilt; } // create band-pass non-recursive filter from low-pass prototype LTISystem NRBandPass( double lofreq, // low corner freq (fraction of sampling rate) double hifreq, // high corner freq (fraction of sampling rate) } int ncoeff // # coefficients ) // returns LTI system { // get low-pass prototype LTISystem bpfilt = NRLowPass((hifreq-lofreq)/2,ncoeff); // now modulate with cos(n*centrefreq) int nhalf = bpfilt.a.count()/2; double cf = 2*PI*(lofreq+hifreq)/2; bpfilt.a[nhalf] = 2 * bpfilt.a[nhalf]; for (int i=1;i<=nhalf;i++) { bpfilt.a[nhalf-i] = 2 * bpfilt.a[nhalf-i] * cos(i*cf); bpfilt.a[nhalf+i] = 2 * bpfilt.a[nhalf+i] * cos(i*cf); } return bpfilt; }

      CPalliniC Offline
      CPalliniC Offline
      CPallini
      wrote on last edited by
      #4

      The results matched against the requirements. :zzz:

      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
      [my articles]

      In testa che avete, signor di Ceprano?

      M 1 Reply Last reply
      0
      • CPalliniC CPallini

        The results matched against the requirements. :zzz:

        If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
        [my articles]

        M Offline
        M Offline
        Maxwell Chen
        wrote on last edited by
        #5

        CPallini wrote:

        The results matched against the requirements.

        You really tested it?! :-D

        Maxwell Chen

        CPalliniC I 2 Replies Last reply
        0
        • M Maxwell Chen

          CPallini wrote:

          The results matched against the requirements.

          You really tested it?! :-D

          Maxwell Chen

          CPalliniC Offline
          CPalliniC Offline
          CPallini
          wrote on last edited by
          #6

          Nope. I just suggested the OP the results matched against the requirements will tell what the error is. Since we don't know both the results and the requirements, we have no chance to. :-D

          If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
          [my articles]

          In testa che avete, signor di Ceprano?

          1 Reply Last reply
          0
          • M Maxwell Chen

            CPallini wrote:

            The results matched against the requirements.

            You really tested it?! :-D

            Maxwell Chen

            I Offline
            I Offline
            Iain Clarke Warrior Programmer
            wrote on last edited by
            #7

            Well, as there weren't any requirements mentioned... It exceeded all expectations! Iain.

            CPalliniC 1 Reply Last reply
            0
            • I Iain Clarke Warrior Programmer

              Well, as there weren't any requirements mentioned... It exceeded all expectations! Iain.

              CPalliniC Offline
              CPalliniC Offline
              CPallini
              wrote on last edited by
              #8

              Did you forget the CPMRU (Code Project Mind Reader Unit)? :-D

              If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
              [my articles]

              In testa che avete, signor di Ceprano?

              A 1 Reply Last reply
              0
              • CPalliniC CPallini

                Did you forget the CPMRU (Code Project Mind Reader Unit)? :-D

                If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                [my articles]

                A Offline
                A Offline
                ashwiny
                wrote on last edited by
                #9

                Actually the coding is to design a low pass filter to remove ecg signal noise..the coding was given my lecture for the project..when I tried to run it i got this error. ‘fatal error C1083: Cannot open include file: 'tools.h': No such file or directory’

                CPalliniC 1 Reply Last reply
                0
                • A ashwiny

                  Actually the coding is to design a low pass filter to remove ecg signal noise..the coding was given my lecture for the project..when I tried to run it i got this error. ‘fatal error C1083: Cannot open include file: 'tools.h': No such file or directory’

                  CPalliniC Offline
                  CPalliniC Offline
                  CPallini
                  wrote on last edited by
                  #10

                  You should add the tools.h file folder to the Include Directories list of Visual Studio. (Tools->Options menu item, then Project and Solutions->VC++ Directories node, then Include files item of Show Directories for listbox). :)

                  If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                  [my articles]

                  In testa che avete, signor di Ceprano?

                  A 1 Reply Last reply
                  0
                  • CPalliniC CPallini

                    You should add the tools.h file folder to the Include Directories list of Visual Studio. (Tools->Options menu item, then Project and Solutions->VC++ Directories node, then Include files item of Show Directories for listbox). :)

                    If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                    [my articles]

                    A Offline
                    A Offline
                    ashwiny
                    wrote on last edited by
                    #11

                    sir i followed as you said but im still getting the same error.

                    CPalliniC 1 Reply Last reply
                    0
                    • A ashwiny

                      sir i followed as you said but im still getting the same error.

                      CPalliniC Offline
                      CPalliniC Offline
                      CPallini
                      wrote on last edited by
                      #12

                      Do you included it using double quotes, i.e. with #include "tools.h"?

                      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                      [my articles]

                      In testa che avete, signor di Ceprano?

                      A 1 Reply Last reply
                      0
                      • CPalliniC CPallini

                        Do you included it using double quotes, i.e. with #include "tools.h"?

                        If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                        [my articles]

                        A Offline
                        A Offline
                        ashwiny
                        wrote on last edited by
                        #13

                        yes sir..still getting the same error

                        1 Reply Last reply
                        0
                        • A ashwiny

                          // nonrec.cpp -- non-recursive filter design // NRLowPass() build NR low-pass filter // NRHighPass() build NR high-pass filter // NRBandPass() build NR band-pass filter #include "tools.h" #include "ltisys.h" // sinc() or sin(x)/x function double sinc(double x) { if (x==0) return cos(x); else return sin(x)/x; } // Create non-recursive low-pass filter by Fourier Transform method LTISystem NRLowPass( double freq, // corner freq (fraction of sampling rate) int ncoeff // # coefficients ) // returns LTI system to specification { int i; // convert frequency double omega = 2 * PI * freq; // build half-sized window from sinc function int nhalf = ncoeff/2; Waveform hwv(nhalf,1.0); for (i=1;i<=nhalf;i++) hwv[i] = omega * sinc(i*omega)/PI; // window with (half-)hamming window for (i=1;i<=nhalf;i++) hwv[i] *= 0.54 + 0.46 * cos(i*PI/nhalf); // create new LTI System LTISystem lpfilt(2*nhalf,0); // copy impulse response into system // (indexed -nhalf .. 0 .. nhalf) lpfilt.a[nhalf] = omega/PI; for (i=1;i<=nhalf;i++) { lpfilt.a[nhalf-i] = hwv[i]; lpfilt.a[nhalf+i] = hwv[i]; } return lpfilt; } // create high-pass non-recursive filter from low-pass prototype LTISystem NRHighPass( double freq, // corner freq (fraction of sampling rate) int ncoeff // # coefficients ) // returns LTI system { // get low-pass version LTISystem hpfilt = NRLowPass(0.5-freq,ncoeff); // now modulate with cos(n*PI) = +1,-1,+1,-1,... int nhalf = hpfilt.a.count()/2; for (int i=1;i<=nhalf;i+=2) { hpfilt.a[nhalf-i] = -hpfilt.a[nhalf-i]; hpfilt.a[nhalf+i] = -hpfilt.a[nhalf+i]; } return hpfilt; } // create band-pass non-recursive filter from low-pass prototype LTISystem NRBandPass( double lofreq, // low corner freq (fraction of sampling rate) double hifreq, // high corner freq (fraction of sampling rate) } int ncoeff // # coefficients ) // returns LTI system { // get low-pass prototype LTISystem bpfilt = NRLowPass((hifreq-lofreq)/2,ncoeff); // now modulate with cos(n*centrefreq) int nhalf = bpfilt.a.count()/2; double cf = 2*PI*(lofreq+hifreq)/2; bpfilt.a[nhalf] = 2 * bpfilt.a[nhalf]; for (int i=1;i<=nhalf;i++) { bpfilt.a[nhalf-i] = 2 * bpfilt.a[nhalf-i] * cos(i*cf); bpfilt.a[nhalf+i] = 2 * bpfilt.a[nhalf+i] * cos(i*cf); } return bpfilt; }

                          D Offline
                          D Offline
                          David Crow
                          wrote on last edited by
                          #14

                          ashwiny wrote:

                          #include "tools.h"

                          If you right-click this statement, can you open the tools.h file?

                          "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

                          "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                          A 1 Reply Last reply
                          0
                          • D David Crow

                            ashwiny wrote:

                            #include "tools.h"

                            If you right-click this statement, can you open the tools.h file?

                            "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

                            "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                            A Offline
                            A Offline
                            ashwiny
                            wrote on last edited by
                            #15

                            i have tried but cannot sir

                            D 1 Reply Last reply
                            0
                            • A ashwiny

                              i have tried but cannot sir

                              D Offline
                              D Offline
                              David Crow
                              wrote on last edited by
                              #16

                              Then that's your clue that the IDE has no idea how to find that file. What version of VS are you using?

                              "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

                              "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                              A 1 Reply Last reply
                              0
                              • D David Crow

                                Then that's your clue that the IDE has no idea how to find that file. What version of VS are you using?

                                "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

                                "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                                A Offline
                                A Offline
                                ashwiny
                                wrote on last edited by
                                #17

                                am using Visual c++ 6.0

                                D 1 Reply Last reply
                                0
                                • A ashwiny

                                  am using Visual c++ 6.0

                                  D Offline
                                  D Offline
                                  David Crow
                                  wrote on last edited by
                                  #18

                                  On the Options dialog, click the Directories tab. Is the directory that contains the tools.h file listed there?

                                  "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

                                  "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                                  A 1 Reply Last reply
                                  0
                                  • D David Crow

                                    On the Options dialog, click the Directories tab. Is the directory that contains the tools.h file listed there?

                                    "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

                                    "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                                    A Offline
                                    A Offline
                                    ashwiny
                                    wrote on last edited by
                                    #19

                                    yes it is there sir.

                                    D 1 Reply Last reply
                                    0
                                    • A ashwiny

                                      yes it is there sir.

                                      D Offline
                                      D Offline
                                      David Crow
                                      wrote on last edited by
                                      #20

                                      What happens if you change the #include statement so that it contains an absolute path to the tools.h file?

                                      "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

                                      "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                                      A 1 Reply Last reply
                                      0
                                      • D David Crow

                                        What happens if you change the #include statement so that it contains an absolute path to the tools.h file?

                                        "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

                                        "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                                        A Offline
                                        A Offline
                                        ashwiny
                                        wrote on last edited by
                                        #21

                                        i dont get you sir..how to change it?

                                        D 1 Reply Last reply
                                        0
                                        • A ashwiny

                                          i dont get you sir..how to change it?

                                          D Offline
                                          D Offline
                                          David Crow
                                          wrote on last edited by
                                          #22

                                          Change the #include statement to also include the absolute path to the tools.h file, like:

                                          #include "c:/some_path/tools.h"

                                          As it currently stands, you are using a relative path.

                                          "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

                                          "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                                          1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups