IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

MATLAB Discussion :

utilisation de @resppack


Sujet :

MATLAB

  1. #1
    Membre averti
    Profil pro
    ingénieur informatique
    Inscrit en
    Janvier 2008
    Messages
    41
    Détails du profil
    Informations personnelles :
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : ingénieur informatique

    Informations forums :
    Inscription : Janvier 2008
    Messages : 41
    Par défaut utilisation de @resppack
    A partir de l'exemple RLC_demo developpée par les auteurs: A. DiVergilio et P. Gahinet, jai réalisé ce programme qui donne les courbes suivantes: diagramme de bode, Pole-zero map, step response et diagramme de Nyquist. Mon souci est de mettre dans chaque type de tracés plusieurs (3) courbes correspondant à trois différentes fonctions de transfert. Ce que je n'arrive pas à faire. Toutes suggestions seraient les bienvenues. merci
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    function mamad_loop
    clc
    clear all
    close all
    % Figure
    pos = get(0,'DefaultFigurePosition');
    fg = figure(...
       'Name','Feedback Loop Response',...
       'Position',pos+pos(3)*[-0.1 0 .2 0],...
       'IntegerHandle','off',...
       'NumberTitle','off',...
       'DoubleBuffer','on',...
       'DefaultUIControlFontSize',8,...
       'DefaultAxesFontSize',8,...
       'DefaultTextFontSize',8,...
       'DefaultAxesBox','on',...
       'DefaultAxesDrawMode','fast',...
       'HandleVisibility','callback',...
       'Visible','off',...
       'DockControls', 'off');
     
    if isunix
       set(fg,'DefaultUIControlFontSize',10);
    end
     
    %---Data structure
    ud = struct(...
       'Type',1,...
       'b1',-4.25e-2,...
       'b0',4.4e-2,...
       'K',1e-5,...
       'Ts',1e3,...
       'Response',[],...
       'System',[],...
       'Resonance',[],...
       'Diagram',[]);
     
    %---Plot layout parameters
    xmax = 0.68;
    xmin = 0.03;
    ymin = 0.08;
    ymax = 0.99;
    xsp  = 0.07;
    ysp  = 0.1;
    ysp2 = 0.025;
    axw  = (xmax-xmin-xsp)/2;
    axh  = (ymax-ymin-ysp)/2;
    axh2 = (axh-ysp2)/2;
    AFC  = [.3 .3 .3];
     
    %---Bode plot
    ax = axes('Parent',fg,'Position',[0.03 0.5850 0.325 0.415],...
       'XColor',AFC,'YColor',AFC);
    grid(ax);
    gridline('Parent',ax,'Type','y','Value',0,'Linewidth',2,'LineStyle','-','Color',[.8 .80 .40]);
    % line('Parent',ax,'XData',w(:),'YData',(abs(h1(:))),'Color','r','LineWidth',2);
    BodePlot = resppack.bodeplot(ax, [1 1]);
    BodePlot.AxesGrid.XUnits = {'rad/sec'};
    BodePlot.AxesGrid.YUnits = {'dB';'deg'};
    r11 = BodePlot.addresponse;
    r11.setstyle('LineWidth',2,'Color','b')
     
    %---Pole-Zero Plot
    ax1 = axes('Parent',fg,'Position',[0.39 0.585 0.325 0.415],...
       'XColor',AFC,'YColor',AFC);
    grid(ax1);
    PZPlot = resppack.pzplot(ax1, [1 1]);
    r12 = PZPlot.addresponse;
    r12.setstyle('LineWidth',2,'Color','b')
     
    %---Step Plot
    ax2 = axes('Parent',fg,'Position',[0.03 0.08 0.325 0.415],...
        'XColor',AFC,'YColor',AFC);
    grid(ax2);
    StepPlot = resppack.timeplot(ax2, [1 1]);
    StepPlot.AxesGrid.Title = 'Step Response';
    r21 = StepPlot.addresponse;
    r21.setstyle('LineWidth',2,'Color','b')
     
    %---Nyquist Plot
    ax3 = axes('Parent',fg,'Position',[xmin+axw+xsp ymin 0.325 0.415],'XColor',AFC,'YColor',AFC);
    grid(ax3)
    NyqPlot = resppack.nyquistplot(ax3, [1 1]);
    r22 = NyqPlot.addresponse(1,1);
    r22.setstyle('LineWidth',2,'Color','b')
     
    % All response
    r = [r11 r12;r21 r22];
    ud.Responses = r;
    % save('ud.Responses')
    %---Control panel layout parameters
    CC = [0.7 0.7 0.7];
    xl = 0.75;
    xr = 0.99;
    yb = 0.08;
    yt = 0.98;
    axes('Parent',fg,'Position',[0.725 0.08 0.27 0.92],'Color',CC,'XTick',[],'YTick',[]);
     
    %---Sliders
    y = yb+.06;
    dy = 0.11;
    y+2*dy+.045;
    BDF = {@localBeginScan,ud.Responses};
    BUF = {@localEndScan,ud.Responses};
    rtslider('Parent',fg,'Position',[xl+.07 y+(3-0.10)*dy xr-xl-.1 .04],'Range',[0 4],'Value',ud.b0,'Label','b0',...
       'ButtonDownFcn',BDF,'Callback',{@localUpdate,fg,'b0'},'ButtonUpFcn',BUF);
    rtslider('Parent',fg,'Position',[xl+.07 y+(2-0.10)*dy xr-xl-.1 .04],'Range',[-2 0],'Value',ud.b1,'Label','b1',...
       'ButtonDownFcn',BDF,'Callback',{@localUpdate,fg,'b1'},'ButtonUpFcn',BUF);
    rtslider('Parent',fg,'Position',[xl+.07 y+(1-0.10)*dy xr-xl-.1 .04],'Range',[1e-7 1e6],'Value',ud.K,'Label','K',...
       'ButtonDownFcn',BDF,'Callback',{@localUpdate,fg,'K'},'ButtonUpFcn',BUF);
    rtslider('Parent',fg,'Position',[xl+.07 y-(0+0.10)*dy xr-xl-.1 .04],'Range',[1e-6 1e6],'Value',ud.Ts,'Label','Ts',...
       'ButtonDownFcn',BDF,'Callback',{@localUpdate,fg,'Ts'},'ButtonUpFcn',BUF);
    %---System/Topology
    ud.Diagram = axes('Parent',fg,'Position',[0.755 0.54 0.241 0.4],...
       'Color','none','XColor',[.7 .7 .7],'YColor',[.7 .7 .7],'XTick',[],'YTick',[]);
    ax = ud.Diagram;
    DrawFeedbackLoop(ud.Diagram);
     
    %---Store data structure and show figure
    set(fg,'UserData',ud)
     
    %---Initialize simulation
    localUpdate([],[],fg,'');
     
    %---Make figure visible
    set(fg,'Visible','on')
     
    %----------------------------------------------------------------------------%
    %---------------------------- Live Graphics ------------------------------%
    %----------------------------------------------------------------------------%
    function localBeginScan(eventSrc,eventData,r)
    %---Sets EraseMode to 'xor' for all lines being updated
     
    set(r,'RefreshMode','quick')
     
    function localEndScan(eventSrc,eventData,r)
    %---Sets EraseMode back to 'normal'
    set(r,'RefreshMode','normal')
    for ct=1:4
       draw(r(ct))  % update plots
    end
     
    %---Change parameter value (eventData = new value)
    %---Change b0, b1, K and Ts
     
    function localUpdate(eventSrc,eventData,fg,param)
    ud = get(fg,'UserData');
    switch param
    case 'b0', 
       ud.b0 = eventData;
    case 'b1', 
       ud.b1 = eventData;
    case 'K', 
       ud.K = eventData;
    case 'Ts', 
       ud.Ts = eventData;
    end
     
    %----------------------------------- Transfer Function 1 ----------------------------------------%
    Num = [(ud.b1-ud.b0),(-(4*ud.b1)/ud.Ts),(4/ud.Ts^2)*(ud.b1+ud.b0)];
    Denum = [4,0,0];
    %r=0.6;
    G = tf(Num,Denum);
     
    %------------------------------------ Transfer Function 2 ---------------------------------------------%
    Num_K = [(ud.b1-ud.b0*(1+ud.K)),-((4/ud.Ts)*(ud.b1-ud.b0*ud.K)),((4/(ud.Ts^2))*(ud.b0*(1-ud.K)+ud.b1))];
    Denum_K = [((ud.K+2)^2),-((4*ud.K*(ud.K+2))/(ud.Ts)),(4*((ud.K)^2))/(ud.Ts^2)];
    G_K = tf(Num_K,Denum_K);
    %G_Kz = c2d(G_K,1e4)
     
    %------------ Systems -----------------------%
    H_vco = 1/(1+G);
    H_hm = G/((1+G)*(1+G_K));
    H_cs = (G*G_K)/((1+G)*(1+G_K));
    sys = H_vco;
    sys1 = H_hm;
    sys2 = H_cs;
    % rlocus(G_K,G)
    % ts = 1e3;
    % H_vcoz = c2d(H_vco,ts)
    % H_hmz = c2d(H_hm,ts)
    % H_csz = c2d(H_cs,ts)
    % ltiview(H_vco,H_hm,H_cs)
     
    %---Data source and responses
    w = logspace(-8,9,128);
    f = unitconv(w,'rad/sec','hz');
    t = [0:50000:1e9];
    r = ud.Responses;
     
    % Time and frequency response
    y = step(sys,t);
    h = freqresp(sys,w);
    % save('h')
    y1 = step(sys1,t);
    h1 = freqresp(sys1,w);
     
    y2 = step(sys2,t);
    h2 = freqresp(sys2,w);
     
    % Bode
    d = r(1,1).Data;
    d.Frequency = w(:);
    d.Magnitude = (abs(h(:)));
    d.Phase = unwrap(angle(h(:)));
    d.Focus = [1e-8 1e9];
     
    % a = r(1,1).Data;
    % a.Frequency = w(:);
    % a.Magnitude = (abs(h1(:)));
    % a.Phase = unwrap(angle(h1(:)));
    % a.Focus = [1e-8 1e9];
     
    % Nyquist
    d = r(2,2).Data;
    d.Frequency = w(:);
    d.Response = h(:);
    d.Focus = [1e-8 1e8];
     
    % Step response
    d = r(2,1).Data;
    d.Time = t(:);
    d.Amplitude = y;
    d.Focus = [0 1e9];
     
    % Pole/zero
    d = r(1,2).Data;
    [d.Zero,d.Pole] = zpkdata(sys);
    % save('r(1,1).Data')
    % Redraw
    for ct=1:4
       draw(r(ct))
    end
     
    %---Draw feedback loops with plant data
    function DrawFeedbackLoop(ax)
     
    %-------------------------------- First Loop --------------------------%
    set(ax,'XLim',[-0.05 1.85],'YLim',[0.35 2.1]);
    text('Parent',ax,'String','Cs','Position',[0.01 2.05],...
          'FontSize',8,'FontWeight','bold','HorizontalAlignment','right','VerticalAlignment','top');
    wire('x',[0.02 0.3],'y',[2 2],'parent',ax,'arrow',0.06);
    sumblock('Parent',ax,'Position',[0.36 2],'label',{'-3'},'radius',.07,...
        'LabelRadius',0.01,'facecolor',[.8 1 1],'fontsize',20);
    wire('x',[0.43 0.85],'y',[2 2],'parent',ax,'arrow',0.06);
    sysblock('Parent',ax,'position',[0.85 1.88 0.25 0.25],'name','G_K',...
        'fontweight','bold','facecolor',[.8 1 1],'fontsize',10);
    wire('x',[1.1 1.43],'y',[2 2],'parent',ax,'arrow',0.06);
    text('Parent',ax,'String','HM','Position',[1.55 2.32],...
          'FontSize',8,'FontWeight','bold','HorizontalAlignment','right','VerticalAlignment','top');
    sumblock('Parent',ax,'Position',[1.5 2],'label',{'+3'},'radius',.07,...
        'LabelRadius',0.01,'facecolor',[.8 1 1],'fontsize',20);
    text('Parent',ax,'String','Z','Position',[1.8 2.095],...
          'FontSize',8,'FontWeight','bold','HorizontalAlignment','right','VerticalAlignment','top');
    wire('x',[1.5 1.5],'y',[2.25 2.08],'parent',ax,'arrow',0.06);
    wire('x',[1.565 1.8],'y',[2 2],'parent',ax,'arrow',0.06);
    wire('x',[1.7 1.7 0.35 0.35],'y',[2 1.78 1.78 1.94],'parent',ax,'arrow',0.06);
     
    %----------------------------- Second Loop --------------------------%
    text('Parent',ax,'String','Z','Position',[0.005 1.5],...
          'FontSize',8,'FontWeight','bold','HorizontalAlignment','right','VerticalAlignment','top');
    wire('x',[0.01 0.3],'y',[1.45 1.45],'parent',ax,'arrow',0.06);
    sumblock('Parent',ax,'Position',[0.36 1.45],'label',{'-3'},'radius',.07,...
        'LabelRadius',0.01,'facecolor',[.8 1 1],'fontsize',20);
    wire('x',[0.43 0.85],'y',[1.45 1.45],'parent',ax,'arrow',0.06);
    sysblock('Parent',ax,'position',[0.85 1.32 0.25 0.25],'name','G',...
        'fontweight','bold','facecolor',[.8 1 1],'fontsize',10);
    wire('x',[1.1 1.43],'y',[1.45 1.45],'parent',ax,'arrow',0.06);
    sumblock('Parent',ax,'Position',[1.5 1.45],'label',{'+3'},'radius',.07,...
        'LabelRadius',0.01,'facecolor',[.8 1 1],'fontsize',20);
    wire('x',[1.5 1.5],'y',[1.65 1.53],'parent',ax,'arrow',0.06);
    text('Parent',ax,'String','VCO','Position',[1.55 1.72],...
          'FontSize',8,'FontWeight','bold','HorizontalAlignment','right','VerticalAlignment','top');
    wire('x',[1.565 1.8],'y',[1.45 1.45],'parent',ax,'arrow',0.06);
    wire('x',[1.7 1.7 0.35 0.35],'y',[1.45 1.2 1.2 1.4],'parent',ax,'arrow',0.06);
    text('Parent',ax,'String','OUT','Position',[1.8 1.55 0],...
          'FontSize',8,'FontWeight','bold','HorizontalAlignment','right','VerticalAlignment','top');
     
    %-------------------------- Equations -----------------------------------%
    text('interpreter','latex','Parent',ax,'String','$$G_K(p)=\frac{(b_{0}(K+1)^{2}-b_{1}(1+K))p^{2}+\frac{4(b_{0}(1-K^{2})+b_{1}K)}{T_{s}}p+\frac{4(b_0(1-K)^2+b_1(1-K))}{Ts^2}}{(K+2)^{2}p^{2}-\frac{4}{T_s}K(K+2)p+\frac{4}{{T_s}^{2}}K^2}$$',...
        'Position',[1.859 0.8],'FontSize',7.45,'FontWeight','bold','HorizontalAlignment','right','VerticalAlignment','top','BackgroundColor','none');
    text('interpreter','latex','Parent',ax,'String','$$G(p)=\frac{(b_{0}-b_{1})p^{2}+\frac{4b_{0}}{T_{s}}p+\frac{4}{{T_{s}}^2}(b_{0}+b_{1})}{4p^{2}}$$',...
        'Position',[1.5 1.1],'FontSize',9,'FontWeight','bold','HorizontalAlignment','right','VerticalAlignment','top','BackgroundColor','none');
    text('interpreter','latex','Parent',ax,'String','$$OUT=\frac{1}{1+G}VCO + \frac{G}{(1+G)(1+G_K)}HM + \frac{G \cdot G_K}{(1+G)(1+G_K)}Cs$$',...
        'Position',[1.8 0.52],'FontSize',8.2,'FontWeight','bold','HorizontalAlignment','right','VerticalAlignment','top','BackgroundColor',[0.8 1 1]);
    text('Parent',ax,'String','Feeback Loops','Position',[0.9 2.32],...
          'FontSize',12,'FontWeight','bold','HorizontalAlignment','center','VerticalAlignment','top');
    text('Parent',ax,'String','Paramètres ajustables','Position',[0.65 0.28],...
          'FontSize',10,'FontWeight','bold','HorizontalAlignment','right','VerticalAlignment','top');
    Merci d'avance

  2. #2
    Membre émérite
    Profil pro
    Inscrit en
    Octobre 2007
    Messages
    769
    Détails du profil
    Informations personnelles :
    Âge : 42
    Localisation : France, Gironde (Aquitaine)

    Informations forums :
    Inscription : Octobre 2007
    Messages : 769
    Par défaut
    Je ne vois pas trop où est le problème.

    Tu veux faire un plot avec plusieurs courbes ?

  3. #3
    Membre averti
    Profil pro
    ingénieur informatique
    Inscrit en
    Janvier 2008
    Messages
    41
    Détails du profil
    Informations personnelles :
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : ingénieur informatique

    Informations forums :
    Inscription : Janvier 2008
    Messages : 41
    Par défaut
    exactement c'est ce que je veux faire

Discussions similaires

  1. utiliser les tag [MFC] [Win32] [.NET] [C++/CLI]
    Par hiko-seijuro dans le forum Visual C++
    Réponses: 8
    Dernier message: 08/06/2005, 16h57
  2. Réponses: 4
    Dernier message: 05/06/2002, 15h35
  3. utilisation du meta type ANY
    Par Anonymous dans le forum CORBA
    Réponses: 1
    Dernier message: 15/04/2002, 13h36
  4. [BCB5] Utilisation des Ressources (.res)
    Par Vince78 dans le forum C++Builder
    Réponses: 2
    Dernier message: 04/04/2002, 17h01
  5. Réponses: 2
    Dernier message: 21/03/2002, 00h01

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo