function animate_shear_frame(Phi,mode,fn)

% Phi  = eigenvector matrix (ndof x nmodes)
% mode = mode number to animate
% fn   = natural frequency vector (Hz)

ndof = size(Phi,1);

if mode > size(Phi,2)
    error('Requested mode exceeds available modes');
end

% Extract and normalize mode shape
phi = Phi(:,mode);
phi = phi/max(abs(phi));

% Geometry
storyH = 4;
width  = 6;
colx   = [-width/2 width/2];

% Animation scaling
scale = width*0.35;

% Frames
nFrames = 200;

figure

for i = 1:nFrames

    clf

    % ----- 4 oscillations + final extreme -----
    theta = (i/nFrames)*(8*pi + pi/2);
    t = sin(theta);

    % lateral displacement
    u = scale * phi * t;

    % floor elevations
    y = (1:ndof)*storyH;

    %% FRAME ANIMATION
    subplot(1,2,1)
    hold on

    % base
    plot([-10 10],[0 0],'k','LineWidth',2)

    % columns
    for c = 1:2
        
        xcol = zeros(ndof+1,1);
        ycol = zeros(ndof+1,1);

        xcol(1) = colx(c);
        ycol(1) = 0;

        for k = 1:ndof
            xcol(k+1) = colx(c) + u(k);
            ycol(k+1) = y(k);
        end

        plot(xcol,ycol,'k','LineWidth',2)

    end

    % floors
    for k = 1:ndof

        x1 = colx(1) + u(k);
        x2 = colx(2) + u(k);

        plot([x1 x2],[y(k) y(k)],'b','LineWidth',4)

    end

    axis equal
    xlim([-12 12])
    ylim([-1 storyH*(ndof+1)])

    title(sprintf('Mode %d    f = %.3g Hz',mode,fn))

    set(gca,'XTick',[],'YTick',[])

    %% MODE SHAPE PLOT
    subplot(1,2,2)

    yplot = [0 y];
    phiplot = [0 phi'];

    plot(phiplot,yplot,'-o','LineWidth',2)
    grid on

    xlabel('\phi')
    ylabel('Story Height')

    title('Mode Shape')

    ylim([0 storyH*(ndof+1)])

    drawnow

end