could anyone tell me what's the error with this code?
-
// 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; }
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] -
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]CPallini wrote:
The results matched against the requirements.
You really tested it?! :-D
Maxwell Chen
-
CPallini wrote:
The results matched against the requirements.
You really tested it?! :-D
Maxwell Chen
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] -
CPallini wrote:
The results matched against the requirements.
You really tested it?! :-D
Maxwell Chen
Well, as there weren't any requirements mentioned... It exceeded all expectations! Iain.
-
Well, as there weren't any requirements mentioned... It exceeded all expectations! Iain.
Did you forget the
CPMRU
(Code Project Mind Reader Unit)? :-DIf 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] -
Did you forget the
CPMRU
(Code Project Mind Reader Unit)? :-DIf 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] -
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’
You should add the
tools.h
file folder to theInclude Directories
list ofVisual Studio
. (Tools->Options
menu item, thenProject and Solutions->VC++ Directories
node, thenInclude files
item ofShow 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] -
You should add the
tools.h
file folder to theInclude Directories
list ofVisual Studio
. (Tools->Options
menu item, thenProject and Solutions->VC++ Directories
node, thenInclude files
item ofShow 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] -
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] -
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] -
// 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; }
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
-
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
-
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
-
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
-
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
-
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
-
What happens if you change the
#include
statement so that it contains an absolute path to thetools.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
-
What happens if you change the
#include
statement so that it contains an absolute path to thetools.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
-
Change the
#include
statement to also include the absolute path to thetools.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
-
// 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; }
While ask this species questions we prefer to shown only debug window's result will be very easy way to find a solution.