Digital Signal Processing using Matlab 5.3
     <<Home Lab 11                                          (Multirate DSP)
   

MATLAB has a number of built-in functions for sampling rate conversion and multirate processing, Some of these include following.

  • decimate

  • interp

  • upfirdn

  • resample

 Decimating the signal                                                                                                                                                                                                                                                                     

Example 1                                                                                                                                  

 A discrete time signal is given by

y = sin(0.1л n)

Decimate the signal by a factor of 2 and 4.

Plot the original and decimated signals. Use the decimate function.

 Solution                                                                                                                                     

n=0:1:100;

y=sin(0.1*pi*n);

y1=decimate(y,2);

y2=decimate(y,4);

subplot(311)

stem(y(1:length(y)))

ylabel('Orignal Signal')

grid

subplot(312)

stem(y1(1:length(y1)))

ylabel('decimated by 2')

grid

subplot(313)

stem(y2(1:length(y2)))

xlabel('Tiem')

ylabel('Decimated by 4')

grid

Result                                                                                                                                         

 Decimating the signal using resample                                                                                           

                                                                                                                                                  

Example 2                                                                                                                                  

 Repeat the above example with resample function

 Solution                                                                                                                                     

n=0:1:100;

y=sin(0.1*pi*n);

y1=resample(y,1,2);

y2=resample(y,1,4);

subplot(311)

stem(y(1:length(y)))

ylabel('Orignal Signal')

grid

subplot(312)

stem(y1(1:length(y1)))

ylabel('Decimated by 2')

grid

subplot(313)

stem(y2(1:length(y2)))

xlabel('Time')

ylabel('Decimated by 4')

grid

Result                                                                                                                                         

                                 

 Interpolating the signal                                                                                                               

                                                                                                                                                  

Example 3                                                                                                                                  

  Consider the signal of example 1. Interpolate the signal by a factor of 2 and 4 using interp function.

 Solution                                                                                                                                     

n=0:1:100;

y=sin(0.1*pi*n);

y1=interp(y,2);

y2=interp(y,4);

subplot(311)

stem(y(1:length(y)))

ylabel('Orignal Signal')

grid

subplot(312)

stem(y1(1:length(y1)))

ylabel('Interpolted by 2')

grid

subplot(313)

stem(y2(1:length(y2)))

xlabel('Time')

ylabel('Interpolated by 4')

grid

 Result                                                                                                                                       

 Interpolating the signal                                                                                                               

                                                                                                                                                  

Exercise 1                                                                                                                                  

  Repeat example 3 using resample function.

 Solution                                                                                                                                    

n=0:1:100;

y=sin(0.1*pi*n);

y1=resample(y,2,1);

y2=resample(y,4,1);

subplot(311)

stem(y(1:length(y)))

ylabel('Orignal Signal')

grid

subplot(312)

stem(y1(1:length(y1)))

ylabel('Interpolted by 2')

grid

subplot(313)

stem(y2(1:length(y2)))

xlabel('Time')

ylabel('Interpollted by 4')

grid

 Result                                                                                                                                       

 Decimating & Interpolating the signal                                                                                          

                                                                                                                                                  

Exercise  2 and 3                                                                                                                        

  Repeat example 2 to decimate the signal by a factor of 2/3

  Repeat example 2 to interpolate the signal by a factor of 5/2

 Solution                                                                                                                                     

n=0:1:100;

y=sin(0.1*pi*n);

y1=resample(y,2,3);

y2=resample(y,5,2);

subplot(311)

stem(y(1:length(y)))

ylabel('Orignal Signal')

grid

subplot(312)

stem(y1(1:length(y1)))

ylabel('Decimated by 2/3')

grid

subplot(313)

stem(y2(1:length(y2)))

xlabel('Time')

ylabel('Interpollted by 5/2')

grid

 Result                                                                                                                                       

 Decimating & Interpolating the signal                                                                                          

                                                                                                                                                  

Exercise  4                                                                                                                                 

  A continuous time signal is characterized by the following function.

x(t) = Acos(2лf1t) + Bcos (2лf2t)

a) Generate, with the aid of MATLAB, a discrete time equivalent of the signal. Assume  a sampling frequency of 1 kHz, f1 = 50 kHz,  f2 = 100 kHz, A=1.5 and B = 1.

b) Interpolate the discrete time signal by a factor of 4 using interp command.

c) Determine the output  of the interpolator in step (b) by a factor of 4 using the decimate function

d) Plot the original, interpolated and decimated discrete time signals.

 Solution                                                                                                                                     

t=0:1:100;

a=1.5;

b=1;

fs=1000;

ts=1/fs;

f1= 50;

f2=100;

y=a*cos(2*pi*f1/fs*t) + b*cos(2*pi*f2/fs*t);

y1=interp(y,4);

y2=decimate(y1,4);

subplot(311)

stem(y(1:length(y)))

ylabel('Orignal Signal')

grid

subplot(312)

stem(y1(1:length(y1)))

ylabel('Interpolated by 4')

grid

subplot(313)

stem(y2(1:length(y2)))

xlabel('Time')

ylabel('Decimated by 4')

grid

 Result                                                                                                                                        

 Decimating & Interpolating the signal                                                                                          

                                                                                                                                                  

Exercise  5                                                                                                                                 

  Repeat exercise "4" using  resample function

 Solution                                                                                                                                     

t=0:1:100;

a=1.5;

b=1;

fs=1000;

ts=1/fs;

f1= 50;

f2=100;

y=a*cos(2*pi*f1/fs*t) + b*cos(2*pi*f2/fs*t);

y1=resample(y,4,1);

y2=resample(y1,1,4);

subplot(311)

stem(y(1:length(y)))

ylabel('Orignal Signal')

grid

subplot(312)

stem(y1(1:length(y1)))

ylabel('Interpolated by 4')

grid

subplot(313)

stem(y2(1:length(y2)))

xlabel('Time')

ylabel('Decimated by 4')

grid

 Result                                                                                                                                        

 HELP                                                                                                                                       

 DECIMATE                                                                                                                              

 DECIMATE Resample data at a lower rate after lowpass filtering.
Y = DECIMATE(X,R) resamples the sequence in vector X at 1/R times the original sample rate. The resulting resampled vector Y is R times shorter, LENGTH(Y) = LENGTH(X)/R. DECIMATE filters the data with an eighth order Chebyshev type I lowpass filter with cutoff frequency .8*(Fs/2)/R, before resampling. Y = DECIMATE(X,R,N) uses an N'th order Chebyshev filter. Y = DECIMATE(X,R,'FIR') uses the 30 point FIR filter generated by FIR1(30,1/R) to filter the data.
Y = DECIMATE(X,R,N,'FIR') uses the N-point FIR filter.
Note: For large R, the Chebyshev filter design might be incorrect due to numeric precision limitations. In this case, DECIMATE will use a lower filter order. For better anti-aliasing performance, try  breaking R up into its factors and calling DECIMATE several times.

 INTERP                                                                                                                                     

INTERP Resample data at a higher rate using lowpass interpolation.
Y = INTERP(X,R) resamples the sequence in vector X at R times the original sample rate. The resulting resampled vector Y is R times longer, LENGTH(Y) = R*LENGTH(X).
A symmetric filter, B, allows the original data to pass through unchanged and interpolates between so that the mean square error between them and their ideal values is minimized.
Y = INTERP(X,R,L,ALPHA) allows specification of arguments L and ALPHA which otherwise default to 4 and .5 respectively. 2*L is the number of original sample values used to perform the interpolation. Ideally L should be less than or equal to 10. The length of B is 2*L*R+1. The signal is assumed to be band
limited with cutoff frequency 0 < ALPHA <= 1.0.  [Y,B] = INTERP(X,R,L,ALPHA) returns the coefficients of the interpolation filter B.

 RESAMPLE                                                                                                                                

 RESAMPLE Change the sampling rate of a signal.
Y = RESAMPLE(X,P,Q) resamples the sequence in vector X at P/Q times the original sample rate using a polyphase implementation. Y is P/Q times the length of X (or the ceiling of this if P/Q is not an integer).  P and Q must be positive integers.
RESAMPLE applies an anti-aliasing (lowpass) FIR filter to X during the resampling process, and compensates for the filter's delay. The filter is designed using FIRLS. RESAMPLE provides an easy-to-use alternative to UPFIRDN, which does not require you to supply a filter or compensate for the signal delay introduced by filtering.
Y = RESAMPLE(X,P,Q,N) uses a weighted sum of 2*N*max(1,Q/P) samples of X  to compute each sample of Y. The length of the FIR filter RESAMPLE applies is proportional to N; by increasing N you will get better accuracy at the expense of a longer computation time. If you don't specify N, RESAMPLE uses N = 10 by default. If you let N = 0, RESAMPLE performs a nearest neighbor interpolation; that is, the output Y(n) is X(round((n-1)*Q/P)+1) ( Y(n) = 0 if round((n-1)*Q/P)+1 > length(X) ).
Y = RESAMPLE(X,P,Q,N,BETA) uses BETA as the design parameter for the  Kaiser window used to design the filter. RESAMPLE uses BETA = 5 if you don't specify a value.
Y = RESAMPLE(X,P,Q,B) uses B to filter X (after upsampling) if B is a vector of filter coefficients. RESAMPLE assumes B has odd length and linear phase when compensating for the filter's delay; for even length  filters, the delay is overcompensated by 1/2 sample. For non-linear phase filters consider using UPFIRDN.
[Y,B] = RESAMPLE(X,P,Q,...) returns in B the coefficients of the filter applied to X during the resampling process (after upsampling).
If X is a matrix, RESAMPLE resamples the columns of X.


DSP Lab 1   DSP Lab2   DSP Lab 3   DSP Lab4   DSP Lab 5   DSP Lab 6   DSP Lab7  DSP Lab8  DSP Lab9  DSP Lab10   DSP Lab 11  Other material


   
 
                                                                                                                   <<Home
  
Ziauddin Siddiqui, B02ME CSN 07, Mehran University Of Engineering & Technology
Jamshoro, Sindh.
Email. [email protected]

1