|
Any chance you can show your code that includes your use of the sigma function parameter ? Does your code produce the correct values ?
|
|
|
|
|
 sure.
here's most of it:
void CalcIIRFactors (FloatType sigma)
{
const FloatType b0 = (FloatType)-1.783;
const FloatType b1 = (FloatType)-1.723;
const FloatType w0 = (FloatType)0.6318;
const FloatType w1 = (FloatType)1.997;
const FloatType b0OverSigma = b0 / sigma;
const FloatType b1OverSigma = b1 / sigma;
const FloatType w0OverSigma = w0 / sigma;
const FloatType w1OverSigma = w1 / sigma;
const FloatType pi = (FloatType)acos(-1.0);
const FloatType scale = sqrt (2 * pi) * sigma;
const FloatType a0 = (FloatType)1.680 / scale;
const FloatType a1 = (FloatType)3.735 / scale;
const FloatType c0 = (FloatType)-0.6803 / scale;
const FloatType c1 = (FloatType)-0.2598 / scale;
numerator_factors_positive [0] = a0 + c0;
numerator_factors_positive [1] =
(exp(b1OverSigma)*(c1*sin(w1OverSigma)-
(c0+2*a0)*cos(w1OverSigma)) +
exp(b0OverSigma)*(a1*sin(w0OverSigma) -
(2*c0+a0)*cos (w0OverSigma)));
numerator_factors_positive [2] =
(2 * exp(b0OverSigma+b1OverSigma) *
((a0+c0)*cos(w1OverSigma)*cos(w0OverSigma) -
a1*cos(w1OverSigma)*sin(w0OverSigma) -
c1*cos(w0OverSigma)*sin(w1OverSigma)) +
c0*exp(2*b0OverSigma) + a0*exp(2*b1OverSigma));
numerator_factors_positive [3] =
(exp(b1OverSigma+2*b0OverSigma) * (c1*sin(w1OverSigma) -
c0*cos(w1OverSigma)) + exp(b0OverSigma+2*b1OverSigma) *
(a1*sin(w0OverSigma) - a0*cos(w0OverSigma)));
numerator_factors_positive [4] = 0.0;
denominator_factors_positive [0] = 0.0;
denominator_factors_positive [1] =
-2 * exp(b1OverSigma) * cos(w1OverSigma) -
2 * exp(b0OverSigma) * cos (w0OverSigma);
denominator_factors_positive [2] =
4 * cos(w1OverSigma) * cos(w0OverSigma) *
exp(b0OverSigma + b1OverSigma) +
exp(2 * b1OverSigma) + exp(2 * b0OverSigma);
denominator_factors_positive [3] =
-2 * cos(w0OverSigma) * exp(b0OverSigma +
2*b1OverSigma) - 2*cos(w1OverSigma) *
exp(b1OverSigma + 2*b0OverSigma);
denominator_factors_positive [4] = exp(2*b0OverSigma + 2*b1OverSigma);
int i;
for (i = 0; i < FACTORS; i++)
{
denominator_factors_negative[i] = denominator_factors_positive[i];
}
numerator_factors_negative[0] = 0.0;
for (i = 1; i < FACTORS; i++)
{
numerator_factors_negative[i] =
numerator_factors_positive[i] -
denominator_factors_positive[i] *
numerator_factors_positive[0];
}
there's a little more after this, but it's working on things that aren't used inside the offending loop. and, yes, the values are correct. - even when slow, it's giving good results.
also, testing with finer precision, it looks like the slowdown isn't centered at 3.0 exactly, rather, it's looking more like sigma = 2.7 is the key. e ??
i wish i could post the whole thing, but... well, it's proprietary.
modified on Wednesday, September 30, 2009 6:11 PM
|
|
|
|
|
I understand about the proprietary requirements.
Your code produces normal values for the numerator/demonimator values over the range of sigma that I you mentioned in my experiments.
The only suggestion I have at this point is can you instrument your runtime statistics at a finer levels to see what portions of the your calculations could be responsible to efficiency reduction.
If you find the solution it would be nice if you could post a follow-up to the thread.
Good luck.
|
|
|
|
|
Since performance is an issue you could probably achieve a speed improvement if you compute some more temporary variables like sin, cos, and exp of various expressions because several of those are recomputed more than once. For example, cos(w1OverSigma) is computed seven times in that function.
|
|
|
|
|
the thing is, those are calculated ahead of the actual processing, and don't change. the actual work is pretty much 4x the loop i posted.
|
|
|
|
|
Hello. I'm writing some C code for an embedded application, and I've run into a problem wherein a compare against an enumerated value is not being executed correctly. Take the following code snippet, for example:
typedef unsigned int UINT16;
typedef enum enum_items_tag
{
ITEM_1,
ITEM_2,
ITEM_3,
ITEM_918,
MAX_ENUM_ITEMS
} enum_items_t;
UINT16 n;
for ( n = 0; n < MAX_ENUM_ITEMS; n++ )
{
}
The code executes as expected, until n is incremented to equal MAX_ENUM_ITEMS, at which time the compare fails, and execution continues within the loop (when it should have exited). I've done things like this in the past without any problems.
I've tried re-typing n as enum_items_t (i.e. declaring n as "enum_items_t n"), as well as type casting MAX_ENUM_ITEMS as UINT16. The only other thing I can think of at this point is that maybe there is an issue with the number of items there are in my enumerated type (919). Does anyone know if there are such constraints on enumerated types? I'm using a GCC based compiler. Or, if you have any other ideas, it would be much appreciated. Thanks.
|
|
|
|
|
why do not output value of MAX_ENUM_ITEMS to see what it is, you may miss some thing in the middle of the enum.
totally 919 items? MAX_ENUM_ITEMS should be 918.
|
|
|
|
|
You're right. Good catch! The enumerated type enum_items_t has a total of 920 items, including MAX_ENUM_ITEMS. I was thinking in terms of offset, or what n would be as the loop repeats.
Unfortunately, outputting constants information with embedded programming can be a little tricky, especially when you're stuck using a ***** compiler/IDE. I'll see what I can do, though. Thanks.
|
|
|
|
|
Just curiosity: what is the usefulness of such a enum ?
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.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
It's used for quickly indexing into an array, rather than having to use processor time to search for an element.
|
|
|
|
|
Well, I cannot see any speed advantage. Would you please elaborate a bit?
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.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
I found the problem. As usual, it turned out to be really simple. My INVALID_ITEM item was positioned at the beginning of the enumeration. When I moved it to the end, after MAX_ENUM_ITEMS, things lined up and started working.
|
|
|
|
|
I did a test for size change of MFC exe.
When a line of code or a small resource bitmap is deleted or added in the exe program, exe size keeps unchanged.
So I guess exe is aligned in size - similar to class aligned in size by its members.
Do you think it is correct or have more info about this?
|
|
|
|
|
Yes. By default applications are aligned on 512 byte boundaries. (Due to a quirk in the Windows 98 paging mechanism, before Visual Studio 2008, Win32 applications were aligned on 4096 byte boundaries unless you added the /OPT:NOWIN98 switch to the linker. The linker for VS 2008 and later now uses 512 alignment by default.)
|
|
|
|
|
Hi Joe,
The /OPT:NOWIN98 should be sdded at which place of project settings? How?
|
|
|
|
|
In Visual Studio 2003/2005 it's in Properties|Linker|Optimization. Select "No (/OPT:NOWIN98) Only set this for Release mode.
In Visual Studio 2008, this will generate a warning, so it should be set to Default.
In Visual C++ 6.0, go to Settings|Link. In the Project Options Edit control, go to end and manually add "/OPT:NOWIN98"
|
|
|
|
|
Joe, thanks,
The min change is from 4096 to 512 bytes now.
cheers.
|
|
|
|
|
How are you looking at the size? If you're looking at the Windows Explorer, it only shows size in "cluster" increments.
Open a command window and use the "dir" command to see the actual files size at the byte level.
Karl - WK5M
PP-ASEL-IA (N43CS)
PGP Key: 0xDB02E193
PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193
|
|
|
|
|
krmed wrote: Open a command window and use the "dir" command to see the actual files size at the byte level.
Better still, right click in Explorer and select Properties .
|
|
|
|
|
krmed wrote: If you're looking at the Windows Explorer, it only shows size in "cluster" increments.
It also shows the file's actual size, not just its size on disk.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Unless you have a different Windows Explorer than I do, it only shows one size - and it's not the actual size.
But perhaps you were responding to the idea of looking at the properties?
Karl - WK5M
PP-ASEL-IA (N43CS)
PGP Key: 0xDB02E193
PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193
|
|
|
|
|
krmed wrote: But perhaps you were responding to the idea of looking at the properties?
Correct.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
I've recently started using the XP styles look by using a manifest on an MFC application, and overall it looks fine.
The problem is a specific screen I have, which uses quite a few Comboboxes and Edit boxes. Everything works basically as before, only much much slower than it used to. When I change back and remove the manifest, everything changes back to regular speed.
Can anyone help me solve this speed issue? The hope is to be able to retain the XP-style look while not slowing down so significantly. Any help would be appreciated, thank you.
|
|
|
|
|
Using VC6 & MFC
I have dialog with an edit box for the user to enter an integer number. I have set the number property in the resource sheet (ES_NUMBER) to handle entering numbers. Now everything is fine in that I can enter numbers and catch the new member value in my OnChangeEdit......() function.
However !
If you have say "3" in the edit box and you want to change it to say "4", a legitimate way for the user to do this is to press backspace to delete the "3" character and type "4" to set the new value.
But if you do this I get a message box saying "Please enter a positive integer." on using the backspace key switfly followed by an exception and program crash. Not very elegant !!
I have tried to intercept this with break points in OnChangeEdit or DoDataExchange of the dialog but it never gets there before the message box pops up.
Appart from priseing out the backspace key from the keyboard is there way to get around this ? It looks to my like a glaring whole in the default way MFC works. Other more learned people than me must have hit this plenty of times ?
Neil
|
|
|
|
|
Have you added any filters or made any unusual changes? I have number edit-controls as well but I don't get message boxes nor exceptions.
There is sufficient light for those who desire to see, and there is sufficient darkness for those of a contrary disposition.
Blaise Pascal
|
|
|
|