Matlab decimate time axis

Discussion in 'Programmer's Corner' started by sharkDawg, Apr 5, 2009.

  1. sharkDawg

    Thread Starter Member

    May 21, 2008
    10
    0
    Hi guys, my problem is that i want to show my original signal and decimated signal on the same plot but am not sure how to do this as the sampling rates are different. Any ideas? I am currently plotting them separately.

    Code ( (Unknown Language)):
    1. nsamp = 512;    %signal duration, 64ms
    2. fs1 = 8000;     %samp frequency
    3. N = 2;          %decimation factor
    4. fs2 = fs1/2;    %target samp frequency
    5. fc = 3500;      %cutoff frequency
    6. n = 40;         %filter order
    7. x1 = 0;
    8.  
    9. % generate the required signal
    10. for fa = 600:600:3600
    11.    
    12.     x1 = x1 + sin(2.*pi.*(0:nsamp-1).*fa/fs1);
    13.  
    14. end
    15.  
    16.  
    17. %filter
    18. Wn = fc/fs1;
    19. b=fir1(n, Wn);
    20. x1_fltrd = filter(b,1,x1);
    21.  
    22.  
    23. % decimate
    24. x2 = x1_fltrd(1:N:end);
    25.  
    26.  
    27. %plot
    28. figure(1);
    29. time_axis = ((0:nsamp-1)*0.064);
    30. plot(time_axis, x1);                        %   Plot original sine wave
    31.  
    32. figure(2);
    33. time_axis1 = ((0:nsamp-257)*0.064);
    34. plot(time_axis1, x2,'r');
     
Loading...