Lab 07-Sampling Rate Conversion: Objectives
Lab 07-Sampling Rate Conversion: Objectives
1 Objectives:
. The goal of this laboratory is to perform sampling rate conversion for any given arbitrary sequence
(D.T) or signal (C.T) by interpolation, decimation, up sampling, down sampling and resampling (i.e.
fractional value)
2 Time Required: 3 hrs
.
3 Programming Language: MATLAB
.
4 Software Required:
. (a). MATLAB 7 or above
PRE - LAB
SAMPLING PROCESS:
It is a process by which a continuous time signal is converted into discrete time signal. X[n] is the
discrete time signal obtained by taking samples of the analog signal x(t) every T seconds, where T
is the sampling period.
SAMPLING THEOREM:
It states that the band limited signal x(t) having no frequency components above Fmax Hz is
specified by the samples that are taken at a uniform rate greater than 2 Fmax Hz (Nyquist rate), or
the frequency equal to twice the highest frequency of x(t).
Fs ≥ 2 Fmax
Sampling rate conversion is employed to generate a new sequence with a sampling rate higher or
lower than that of a given sequence. If x[n] is a sequence with a sampling rate of F Hz and it is
used to generate another sequence y[n] with desired sampling rate F’ Hz, then the sampling rate
alteration is given by,
F’/F = R
If R > 1, the process is called interpolation and results in a sequence with higher sampling rate. If
R< 1, the process is called decimation and results in a sequence with lower sampling rate.
Down sampling operation by an integer factor M (M>1) on a sequence x[n] consists of keeping
every Mth sample of x[n] and removing M-1 in between samples, generating an output sequence
y[n] according to the relation
y [n] = x[nM]
y [n] – sampling rate is 1/M that of x[n]
If we reduce the sampling rate, the resulting signal will be an aliased version of x[n]. To avoid
aliasing, the bandwidth of x[n] must be reduced to Fmax =Fx/2 π or max = π /M. The input
sequence is passed through LPF or an antialiasing filter before down sampling.
x [n] - y[n]
ANTIALIASING M
FILTER H (Z)
Up sampling by an integer factor L (L > 1) on a sequence x[n] will insert (L–1) equidistant samples
between an output sequence y[n] according to the relation
x[n/L], n = 0, 1, 2 ….
y[n] = 0, otherwise
The sampling rate of y[n] is L times that of x[n]. The unwanted images in the spectra of sampled
signal must be removed by a LPF called anti-imaging filter. The input sequence is passed through
an anti-imaging filter after up sampling.
We achieve this conversion, by first performing interpolation by the factor I and then
decimating the output of interpolator by the factor D, interpolation has to be performed before
decimation to obtain the new rational sampling rate.
Exercise 2: A sinusoidal, s having Fs=10Khz and F= 5.5Khz, how many samples per wave cycle
of s will be there. Sampled signal will be aliased or not, explain in 2 lines.
IN- LAB
LIBRARY FUNCTIONS:
ALGORITHM/PROCEDURE:
1. Generate a sinusoidal waveform
2. Using the appropriate library function for interpolation, decimation, up sampling,
3. down sampling and resampling, perform sampling rate conversion for the sinusoidal
waveform
4. Find the spectrum of all the signals and compare them in frequency domain.
5. Display the resultant waveforms
Source code :
clc;
clear all;
close all;
%continuous sinusoidal signal
a=input('Enter the amplitude:');
f=input('Enter the Frequency:');
t=-10:1:20;
x=a*sin(2*pi*f*t);
subplot(2,3,1);
plot(t,x);
xlabel('time');
ylabel('Amplitude');
title('Sinusoidal signal');
%decimating the signal
d=input('Enter the value by which the signal is to be decimated:');
y1=decimate(x,d);
subplot(2,3,2);
stem(y1);
xlabel('time');
ylabel('Amplitude');
title('Decimated signal');
%interpolating the signal
i=input('Enter the value by which the signal is to be interpolated:');
y2=interp(x,i);
subplot(2,3,3);
stem(y2);
xlabel('time');
ylabel('Amplitude');
title('Interpolated signal');
%resampling the signal
y3=resample(x,3,2);
subplot(2,3,4);
stem(y3);
xlabel('time');
ylabel('Amplitude');
title('Resampled signal');
%downsampling the signal
y4=downsample(x,2);
subplot(2,3,5);
stem(y4);
xlabel('time');
ylabel('Amplitude');
title('Downsampled signal');
%upsampling the signal
y5=upsample(x,3);
subplot(2,3,6);
stem(y5);
xlabel('time');
ylabel('Amplitude');
title('Upsampled signal');
Exercise 3: Decimate the Signal by 2 and Interpolate the Signal by the Factor of 2. Amplitude
should be 2 and F should be 0.05Hz.
Exercise 4: Plot (using stem) a sin wave, s having frequency of 3hz and sampling frequency of 60
Hz. How many samples /cycle will be plotted. Interpolate the s with L=3 and Decimate s with
M=2. Resample the s by the rate of 3/4.
POST-LAB
Exercise 5:
1. The sample rate used on compact discs is 44.1 kHz, while the sample rate used on digital
audio tape is 48 kHz. Create an input signal consisting of sum of sin waves sampled at
44.1 Khz. The sin waves should have frequencies of 2,4,8 Khz.
2. Change the sampling rate from 44.1 Khz to 48 Khz.
3. Append the following code to play both signals
P44_1 = audioplayer(x,44100);
P48 = audioplayer(xnew,48000);
play(P44_1)
play(P48)
Exercise 6:
1. Change the sample rate of a speech sample from 7418 Hz to 8192 Hz. The speech signal
is a recording of a speaker saying "MATLAB®".
2. Load the speech sample by typing load mtlb
3. Use the rat command to determine the ratio and resample it to 8192 Hz.
4. Plot the 2 signals.
5. Play both signals by Sound command at their appropriate Fs.