用C ++创建时变信号

时间:2017-02-24 23:41:52

标签: c++ signals abb-control-systems

我想创建信号r(t),以便:

r(t) = 1.......0<t<=30 sec 
r(t) = -(1/16)*(t-30)+1 ...... 30 to 34 sec
r(t) = 0.75 ..... 34 to 50 sec
r(t) = +(1/16)*(t-54)+1......50 to 54 sec
r(t) = 1 ....54 to 60 sec
Signal sample rate(Accuracy need) = 0.01 sec

这里我想从

开始
float r = 1 

如上所述随时间变化,并继续将这些值写入txt文件

Matlab代码:

    dt = 0.01;
    T = [0:dt:80];
    j = 1;
    for i=0:dt:(30-dt)
    r(j) = 1;
    j = j+1;
    end
    for i=30:dt:(34-dt)
    r(j) = (-1/16)*(i-30)+1;
    j = j+1;
    end
    for i=34:dt:(50-dt)
    r(j) = 0.75;
    j = j+1;
    end
    for i=50:dt:(54-dt)
    r(j) = 1/16*(i -54)+1;
    j = j+1;
    end
    for i=54:dt:(80)
    r(j) = 1;
    j = j+1;
    end

I am working on i7 intel ubuntu 14.06 

1 个答案:

答案 0 :(得分:0)

    [![void referencesignal()
    {
    ofstream ref1;
    ref1.open("ref_gen.txt");
    vector<float> r;
    float dt = 0.01;
    float i; float j = 0.0; float p;
       for (i=j;i<=30;i=i+dt)
         {
        r.push_back(1);
         }
    j = i;
       for (i= j+dt;i<=34;i=i+dt)
        { 
        p = (-0.0625*(i-j)+1);
        r.push_back(p);
        }
    j = i;
       for (i=j+dt;i<=50;i=i+dt)
        { 
        r.push_back(0.75);
        }
    j = i;
       for (i=j+dt;i<=54;i=i+dt)
        {   
        p = (0.0625*(i-54)+1);
        r.push_back(p);
        }
    j = i;
       for (i=j+dt;i<=80;i=i+dt)
        { 
        r.push_back(1); 
        }
    ostream_iterator<float> output_iterator(ref1,"\n");
    copy(r.begin(),r.end(),output_iterator);
    }][1]][1]

https://i.stack.imgur.com/kt5BI.png