Click here to Skip to main content
15,891,657 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Plot graph using MFC Pin
Iain Clarke, Warrior Programmer28-Jan-08 23:07
Iain Clarke, Warrior Programmer28-Jan-08 23:07 
GeneralRe: Plot graph using MFC Pin
Maxwell Chen28-Jan-08 23:10
Maxwell Chen28-Jan-08 23:10 
QuestionRe: Plot graph using MFC Pin
Mark Salsbery29-Jan-08 5:57
Mark Salsbery29-Jan-08 5:57 
GeneralRe: Plot graph using MFC Pin
Kennis29-Jan-08 16:24
Kennis29-Jan-08 16:24 
GeneralRe: Plot graph using MFC Pin
Mark Salsbery30-Jan-08 5:08
Mark Salsbery30-Jan-08 5:08 
QuestionRe: Plot graph using MFC Pin
Mark Salsbery30-Jan-08 5:15
Mark Salsbery30-Jan-08 5:15 
GeneralRe: Plot graph using MFC Pin
Kennis30-Jan-08 15:06
Kennis30-Jan-08 15:06 
Questioncould anyone tell me what's the error with this code? Pin
ashwiny28-Jan-08 20:14
ashwiny28-Jan-08 20:14 
// 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;
}
AnswerRe: could anyone tell me what's the error with this code? Pin
Stephen Hewitt28-Jan-08 20:15
Stephen Hewitt28-Jan-08 20:15 
AnswerRe: could anyone tell me what's the error with this code? Pin
Hamid_RT28-Jan-08 20:43
Hamid_RT28-Jan-08 20:43 
AnswerRe: could anyone tell me what's the error with this code? Pin
CPallini28-Jan-08 21:27
mveCPallini28-Jan-08 21:27 
GeneralRe: could anyone tell me what's the error with this code? Pin
Maxwell Chen28-Jan-08 21:33
Maxwell Chen28-Jan-08 21:33 
GeneralRe: could anyone tell me what's the error with this code? Pin
CPallini28-Jan-08 22:35
mveCPallini28-Jan-08 22:35 
GeneralRe: could anyone tell me what's the error with this code? Pin
Iain Clarke, Warrior Programmer28-Jan-08 22:36
Iain Clarke, Warrior Programmer28-Jan-08 22:36 
JokeRe: could anyone tell me what's the error with this code? Pin
CPallini28-Jan-08 23:03
mveCPallini28-Jan-08 23:03 
GeneralRe: could anyone tell me what's the error with this code? Pin
ashwiny28-Jan-08 23:54
ashwiny28-Jan-08 23:54 
GeneralRe: could anyone tell me what's the error with this code? Pin
CPallini29-Jan-08 0:18
mveCPallini29-Jan-08 0:18 
GeneralRe: could anyone tell me what's the error with this code? Pin
ashwiny29-Jan-08 0:49
ashwiny29-Jan-08 0:49 
QuestionRe: could anyone tell me what's the error with this code? Pin
CPallini29-Jan-08 0:56
mveCPallini29-Jan-08 0:56 
GeneralRe: could anyone tell me what's the error with this code? Pin
ashwiny29-Jan-08 1:27
ashwiny29-Jan-08 1:27 
AnswerRe: could anyone tell me what's the error with this code? Pin
David Crow29-Jan-08 3:01
David Crow29-Jan-08 3:01 
GeneralRe: could anyone tell me what's the error with this code? Pin
ashwiny29-Jan-08 3:08
ashwiny29-Jan-08 3:08 
QuestionRe: could anyone tell me what's the error with this code? Pin
David Crow29-Jan-08 3:10
David Crow29-Jan-08 3:10 
GeneralRe: could anyone tell me what's the error with this code? Pin
ashwiny29-Jan-08 3:35
ashwiny29-Jan-08 3:35 
QuestionRe: could anyone tell me what's the error with this code? Pin
David Crow29-Jan-08 3:42
David Crow29-Jan-08 3:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.