Click here to Skip to main content
15,908,909 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
SuggestionRe: How can i calculate seconds value here? Pin
pasztorpisti15-Aug-12 22:32
pasztorpisti15-Aug-12 22:32 
AnswerRe: How can i calculate seconds value here? Pin
Jochen Arndt16-Aug-12 1:43
professionalJochen Arndt16-Aug-12 1:43 
GeneralRe: How can i calculate seconds value here? Pin
pasztorpisti16-Aug-12 1:52
pasztorpisti16-Aug-12 1:52 
AnswerRe: How can i calculate seconds value here? Pin
Richard MacCutchan15-Aug-12 22:23
mveRichard MacCutchan15-Aug-12 22:23 
AnswerRe: How can i calculate seconds value here? Pin
pasztorpisti15-Aug-12 22:38
pasztorpisti15-Aug-12 22:38 
AnswerRe: How can i calculate seconds value here? Pin
Jochen Arndt15-Aug-12 22:49
professionalJochen Arndt15-Aug-12 22:49 
GeneralRe: How can i calculate seconds value here? Pin
Le@rner15-Aug-12 23:27
Le@rner15-Aug-12 23:27 
QuestionI want to find out where the focus belongs after EN_KILLFOCUS? Pin
Falconapollo15-Aug-12 18:24
Falconapollo15-Aug-12 18:24 
AnswerRe: I want to find out where the focus belongs after EN_KILLFOCUS? Pin
Software_Developer15-Aug-12 19:26
Software_Developer15-Aug-12 19:26 
GeneralRe: I want to find out where the focus belongs after EN_KILLFOCUS? Pin
Falconapollo15-Aug-12 20:32
Falconapollo15-Aug-12 20:32 
QuestionDisabling Windows ShortCut Keys Pin
Don Guy14-Aug-12 13:42
Don Guy14-Aug-12 13:42 
AnswerRe: Disabling Windows ShortCut Keys Pin
Albert Holguin14-Aug-12 14:17
professionalAlbert Holguin14-Aug-12 14:17 
AnswerRe: Disabling Windows ShortCut Keys Pin
«_Superman_»14-Aug-12 17:39
professional«_Superman_»14-Aug-12 17:39 
AnswerRe: Disabling Windows ShortCut Keys Pin
Software_Developer14-Aug-12 21:02
Software_Developer14-Aug-12 21:02 
AnswerRe: Disabling Windows ShortCut Keys Pin
pasztorpisti14-Aug-12 21:08
pasztorpisti14-Aug-12 21:08 
AnswerRe: Disabling Windows ShortCut Keys Pin
Joan M14-Aug-12 23:25
professionalJoan M14-Aug-12 23:25 
QuestionAccessing Pixels with CreateDIBSection Pin
Member 925534913-Aug-12 20:38
Member 925534913-Aug-12 20:38 
AnswerRe: Accessing Pixels with CreateDIBSection Pin
Eugen Podsypalnikov13-Aug-12 21:05
Eugen Podsypalnikov13-Aug-12 21:05 
GeneralRe: Accessing Pixels with CreateDIBSection Pin
Member 925534913-Aug-12 22:23
Member 925534913-Aug-12 22:23 
AnswerRe: Accessing Pixels with CreateDIBSection Pin
pasztorpisti13-Aug-12 22:54
pasztorpisti13-Aug-12 22:54 
GeneralRe: Accessing Pixels with CreateDIBSection Pin
Member 925534914-Aug-12 7:58
Member 925534914-Aug-12 7:58 
GeneralRe: Accessing Pixels with CreateDIBSection Pin
pasztorpisti14-Aug-12 8:09
pasztorpisti14-Aug-12 8:09 
QuestionSpeed up a numerical Calculation. Circular Queue Pin
whitbuzben1813-Aug-12 7:55
whitbuzben1813-Aug-12 7:55 
Hi Guys

I have designed a digital controller in matlab. The continuos s domain controller is as follows:

1.16e006 s^2 + 6.287e006 s + 2.436e006
--------------------------------------
s^2 + 10 s

The discretised z domain version (with a sampling rate of 100Hz) is as follows:

1.16e006 z^2 - 2.26e006 z + 1.1e006
-----------------------------------
z^2 - 1.905 z + 0.9048

Now i have managed to program this in C++ and it "sort of" works. However the code is by no means optimal and therefore does not execute as quickly as it should. The code basically looks like this:
C++
    float SpeedDemand;
    float SpeedError;
    float MeasuredGeneratorSpeed;
    float y;

    float numcoeff[3];
    float dencoeff [3];

    numcoeff[0] = 1160000;
    numcoeff[1] = -2260000;
    numcoeff[2] = 1100000;

    dencoeff[0] = 1;
    dencoeff[1] = -1.905;
    dencoeff[2] = 0.9048;

    static float xprevious[3];
    static float yprevious[3];



SpeedError = MeasuredGeneratorSpeed - SpeedDemand;
xprevious[0] = SpeedError; //current input value
y = xprevious[0]*numcoeff[0];  // get it started

y += ((xprevious[1]*numcoeff[1])+(xprevious[2]*numcoeff[2])-(yprevious[1]*dencoeff[1])-(yprevious[2]*dencoeff[2]));

xprevious[2] = xprevious[1]; //Shift the values down
xprevious[1] = xprevious[0];
yprevious[2] = yprevious[1];
yprevious[1] = y; // Current Output 


Where xprevious[],yprevious[] are arrays that i define earlier in the program. They are used to store the previous input and output values. X is the input and Y is the output. The numbers stored in the numcoeff[] and dencoeff[] arrays correspond to the coefficients in the z domain transfer function shown at the top. Is there a faster way to do this calculation in c++, perhaps by using a circular queue!!??. Unfortunately my programming knowledge is not great(I'm a Matlab guy). If there is a better way to do it that would speed up the calculation perhaps someone could give me an eample of how to do it. By the way all the variables and arrays are floating point. Any help or advice would be much appreciated.

Many Thanks
Ben

modified 14-Aug-12 5:16am.

AnswerRe: Speed up a numerical Calculation. Circular Queue Pin
Chris Losinger13-Aug-12 9:25
professionalChris Losinger13-Aug-12 9:25 
GeneralRe: Speed up a numerical Calculation. Circular Queue Pin
pasztorpisti13-Aug-12 13:19
pasztorpisti13-Aug-12 13:19 

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.