ct and dt operations

9
OPERATIONS ON DISCRETE – TIME SEQUENCES The following matlab code performs time scaling, shifting and reversal clc; clear; s=input('Enter length of sequence'); l=input('Enter lower limit'); u=l+s-1; j=1; %for loop for a random sequence n=[l:u]; for i=l:1:u xn(j)=ceil(5*rand+2); j=j+1; end subplot(3,1,1); stem(n,xn); grid on; xlabel(‘n’); ylabel(‘x[n]’); %plot x[an+k] a=input('Enter the scaling factor'); k=input('Enter shifting factor'); %k>0—advance and k<0—delay if k>0 l=l-k;u=u-k; n=[l:u]; end if k<0 l=l+abs(k);u=u+abs(k); n=[l:u]; end subplot(3,1,2); stem(n,xn); grid on; xlabel(‘n’); ylabel(‘x[n±k]’); title(‘Shifted sequence’); j=1; %abs(a)>1 - compression if abs(a)~=1 && abs(a)>1 for i=1:1:length(n) k=n(i)/a; if k-fix(k) == 0 n1(j)=k; xn1(j)=xn(i); disp(k); j=j+1; end end if a<0 xn1=fliplr(xn1); end subplot(3,1,3); stem(n1,xn1);grid on; xlabel(‘n’);ylabel(‘x[an]’); title(‘Compressed sequence’); end

Upload: vijaysankar

Post on 19-Nov-2015

3 views

Category:

Documents


0 download

DESCRIPTION

signal operations- MATLAB CODE

TRANSCRIPT

  • OPERATIONS ON DISCRETE TIME SEQUENCES

    The following matlab code performs time scaling, shifting and reversal

    clc;

    clear;

    s=input('Enter length of sequence');

    l=input('Enter lower limit');

    u=l+s-1;

    j=1;

    %for loop for a random sequence

    n=[l:u];

    for i=l:1:u

    xn(j)=ceil(5*rand+2);

    j=j+1;

    end

    subplot(3,1,1);

    stem(n,xn);

    grid on;

    xlabel(n); ylabel(x[n]);

    %plot x[an+k]

    a=input('Enter the scaling factor');

    k=input('Enter shifting factor');

    %k>0advance and k0

    l=l-k;u=u-k;

    n=[l:u];

    end

    if k1 - compression

    if abs(a)~=1 && abs(a)>1

    for i=1:1:length(n)

    k=n(i)/a;

    if k-fix(k) == 0

    n1(j)=k;

    xn1(j)=xn(i);

    disp(k);

    j=j+1;

    end

    end

    if a

  • %abs(a)
  • PLOT 1 :

    PLOT 2: x [-0.5n 1]

  • PLOT 2 :

  • OPERATIONS ON CONTINOUS TIME SIGNALS

    The following matlab code does time scaling and shifting on CT signals.

    clc;

    clear all;

    close all;

    %plot x(at + k)

    l=input('Enter lower bound of the plot');

    u=input('ENter upper bound');

    syms t;

    x=input('Enter the function');

    f=inline(x);

    disp(f);

    t=[l:0.01:u];

    a=input('Enter the scaling factor');

    k=input('Enter the shifting factor');

    xt=f(t);

    subplot(3,1,1);

    plot(t,xt);

    ;ylabel('x(t)');

    axis([-2*pi 2*pi -1 1]);

    title('CT signal');

    grid on;

    subplot(3,1,2);

    plot(t+k,xt);

    ylabel('x(t+k)')

    axis([-2*pi 2*pi -1 1]) ;

    title('Shifted signal');

    grid on;

    subplot(3,1,3);

  • if a
  • PLOT 1:

    X(t) = sin(t)

    X(-2t ) is plotted.

  • PLOT 2:

    x(-0.5t + 1) , where x(t)=t;

    PLOT 2: