(1) sampling -...

15
Islamic University of Gaza Faculty of Engineering Electrical Engineering Department Spring-2012 ___________________________________________________________________________________________ _ DSP Laboratory (EELE 4110) Lab#2 Sampling and Quantization OBJECTIVES: When you have completed this assignment, you will: understand the concept of sampling, aliasing, quantization and reconstruction. demonstrate the effect of aliasing on the reconstruction process. INTRODUCTION: Digital communications has proved to be a very efficient means of transporting speech, music, video, and data over different kinds of media. These media include satellite, microwave, fiber-optic, coaxial, and cellular channels. One special advantage that digital communication holds over analog communication is in the superior handling of noise in the channel. Baseband signals such as speech, music, and video are naturally occurring analog signals. Hence, the processes of analog to digital (A/D) conversion at the transmitter and digital to analog conversion (D/A) at the receiver are integral sections of the entire communication. THEORETICAL PART: (1) Sampling . In order to store, transmit or process analog signals using digital hardware, we must first convert them into discrete-time signals by sampling. The processed discrete-time signal is usually converted back to analog form by interpolation, resulting in a reconstructed analog signal xr(t). The sampler reads the values of the analog signal xa(t) at equally spaced sampling instants. The time interval Ts between adjacent samples is known as the sampling period (or sampling interval). The sampling rate, measured in samples per second, is fs =1/Ts. x[n]= xa(nTs) , n=…, - 1, 0, 1, 2, …. Also it possible to reconstruct xa(t) from its samples: xa(t) = x[tFs].

Upload: others

Post on 02-Nov-2019

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: (1) Sampling - site.iugaza.edu.pssite.iugaza.edu.ps/ymmatar/files/2016/02/DSP-Lab2-Sampling-Quantization.pdf · process will give you the ability to vary the sampling rate of a discrete

Islamic University of Gaza

Faculty of Engineering Electrical Engineering Department

Spring-2012 ___________________________________________________________________________________________ _

DSP Laboratory (EELE 4110)

Lab#2 Sampling and Quantization

OBJECTIVES:

When you have completed this assignment, you will:

− understand the concept of sampling, aliasing, quantization and reconstruction.

− demonstrate the effect of aliasing on the reconstruction process.

INTRODUCTION:

Digital communications has proved to be a very efficient means of transporting speech, music, video, and

data over different kinds of media. These media include satellite, microwave, fiber-optic, coaxial, and

cellular channels. One special advantage that digital communication holds over analog communication is in

the superior handling of noise in the channel.

Baseband signals such as speech, music, and video are naturally occurring analog signals. Hence, the

processes of analog to digital (A/D) conversion at the transmitter and digital to analog conversion (D/A) at

the receiver are integral sections of the entire communication.

THEORETICAL PART:

(1) Sampling .

In order to store, transmit or process analog signals using digital hardware, we must first convert them into

discrete-time signals by sampling.

The processed discrete-time signal is usually converted back to analog form by interpolation, resulting in a

reconstructed analog signal xr(t).

The sampler reads the values of the analog signal xa(t) at equally spaced sampling instants. The time

interval Ts between adjacent samples is known as the sampling period (or sampling interval). The sampling

rate, measured in samples per second, is fs =1/Ts.

x[n]= xa(nTs) , n=…, -1, 0, 1, 2, ….

Also it possible to reconstruct xa(t) from its samples: xa(t) = x[tFs].

matrix
Highlight
matrix
Highlight
matrix
Highlight
matrix
Highlight
matrix
Sticky Note
عبارة عن عملية تحويل الاشارة من cont. الي discrete من خلال اخد عينات من الاشارة كل فترة ثابتة من الزمن تسمي sampling time اول عملية عند تحويل الاشارة من analog الى digital
Page 2: (1) Sampling - site.iugaza.edu.pssite.iugaza.edu.ps/ymmatar/files/2016/02/DSP-Lab2-Sampling-Quantization.pdf · process will give you the ability to vary the sampling rate of a discrete

Figure 2.1: Sampling and Reconstruction process

Sampling Theorem

The uniform sampling theorem states that a bandlimited signal having no spectral components above

fm hetez can be determined uniquely by values sampled at uniform intervals of : 𝑇𝑠 ≤1

2𝑓𝑚

The upper limit on Ts can be expressed in terms of sampling rate, denoted fs=1/Ts. The restriction, stated in

term of the sampling rate, is known as the Nyquist criterion. The statement is: 𝑓𝑠 ≥ 2𝑓𝑚

The sampling rate 𝑓𝑠 = 2𝑓𝑚 is also called Nyquist rate .The allow Nyquist criterion is a theoretically

sufficient condition to allow an analog signal to be reconstructed completely from a set of a uniformly

spaced discrete-time samples.

Impulse Sampling

Assume an analog waveform x(t) ,as shown in figure 4.2(a), with a Fourier transform, X(f) which is zero

outside the interval (− fm < f < fm ) ,as shown in figure 4.2(b). The sampling of x(t) can be viewed as the

product of x(t) with a periodic train of unit impulse function xδ(t), shown in figure 4.2(c) and defined as

𝑥𝛿 𝑡 = 𝛿(

𝑛=−∞

𝑡 − 𝑛𝑇𝑠)

where 𝑇𝑠 is the sampling period and δ(t) is the unit impulse or Dirac delta function .Let us choose

𝑇𝑠 = 1/2𝑓𝑚 , so that the Nyquist criterion is just satisfied. The sifting property of the impulse function

states that

𝑥 𝑡 𝛿 𝑡 − 𝑡𝑜 = 𝑥 𝑡𝑜 𝛿 𝑡 − 𝑡𝑜

Using this property, we can see that 𝑥𝑆 𝑡 , the sampled version of x(t) shown in figure 4.2(e), is given by

𝑥𝑆 𝑡 = 𝑥(𝑡)𝑥𝛿(𝑡) = 𝑥(𝑡)𝛿(

𝑛=−∞

𝑡 − 𝑛𝑇𝑠) = 𝑥(𝑛𝑇𝑠)𝛿(

𝑛=−∞

𝑡 − 𝑛𝑇𝑠)

matrix
Highlight
matrix
Highlight
matrix
Highlight
matrix
Sticky Note
nyruist rate عبارة عن اقل sampling frequncy مسموح به حتى نتمكن من استعادة الائارة بشكل صحيح و لكن لا ينصح باستخدامه عمليا
matrix
Highlight
matrix
Highlight
matrix
Sticky Note
train of impulses المستخدم في عملية sampling
matrix
Highlight
matrix
Sticky Note
هي عبارة عن خاصية من خواص pulse و تتمثل في ان عندما نضرب اي اقتران في pulse فان الجواب يكون صفر ما عدا عند النقطة الموجود عندها pulse
matrix
Highlight
Page 3: (1) Sampling - site.iugaza.edu.pssite.iugaza.edu.ps/ymmatar/files/2016/02/DSP-Lab2-Sampling-Quantization.pdf · process will give you the ability to vary the sampling rate of a discrete

Using the frequency convolution property of the Fourier transform we can transform the time-domain

product 𝑥(𝑡)𝑥𝛿(𝑡) to the frequency-domain convolution 𝑓 ∗ 𝑋𝛿 𝑓 ,

𝑋𝛿 𝑓 =1

𝑇𝑠

𝛿(

𝑛=−∞

𝑓 − 𝑛𝑓𝑠)

where 𝑋𝛿 𝑓 is the Fourier transform of the impulse train 𝑥𝛿(𝑡) . Notice that the Fourier transform of an

impulse train is another impulse train; the values of the periods of the two trains are reciprocally related to

one another. Figure 4.2(c) and (d) illustrate the impulse train 𝑥𝛿(𝑡) and its Fourier transform 𝑋𝛿 𝑓 ,

respectively.

We can solve for the transform 𝑋𝑆 𝑓 of the sampled waveform:

𝑋𝑆 𝑓 = 𝑋 𝑓 ∗ 𝑋𝛿 𝑓 = 𝑋 𝑓 * 1

𝑇𝑠

𝛿(∞𝑛=−∞ 𝑓 − 𝑛𝑓𝑠)

𝑋𝑆 𝑓 =1

𝑇𝑠 𝛿(

𝑛=−∞

𝑓 − 𝑛𝑓𝑠)

Figure 2.2: Sampling theorem using the frequency convolution property of the Fourier transform

We therefore conclude that within the original bandwidth, the spectrum 𝑋𝑆 𝑓 is, to within a constant

factor (1/Ts) , exactly the same as that of x(t) in addition, the spectrum repeats itself periodically in

frequency every fs hertz.

matrix
Highlight
matrix
Highlight
matrix
Sticky Note
الان تحويل train of pulses من time domain الي frequncy domain عبارة عن train of pulse ايضا و لكن في الاول يتكرر كل Ts اما الاخر يتكرر كل Fs
matrix
Sticky Note
train of pulses in frequency domain
matrix
Highlight
matrix
Sticky Note
شكل مهم جدا جدا يوضح عملية sampling في frequncy domain وفي time domain
Page 4: (1) Sampling - site.iugaza.edu.pssite.iugaza.edu.ps/ymmatar/files/2016/02/DSP-Lab2-Sampling-Quantization.pdf · process will give you the ability to vary the sampling rate of a discrete

Aliasing

Aliasing in Frequency Domain

If fs does not satisfy the Nyquist rate, 𝑓𝑠 < 2𝑓𝑚 , the different components of 𝑋𝑆 𝑓 overlap and will not

be able to recover x(t) exactly as shown in figure 4.3(b). This is referred to as aliasing in frequency

domain.

Figure 2.3: Spectra for various sampling rates. (a) Sampled spectrum fs > 2𝑓m

(b) Sampled spectrum fs < 2𝑓m

Aliasing in time domain

As we shall presently see, the frequency content of the analog signal xa(t) has to be limited before

attempting to sample it. This means that xa(t) cannot change too fast; consequently, the average value

over the interval nTs −Δ to nTs+Δ is a good approximation of the ideally sampled value xa(t) of nTs .

𝑡 = 𝑛𝑇𝑆 , 1

𝐹=

1

𝑓

1

𝐹𝑆 , 𝐹 = 𝑓𝐹𝑆 , Ω = ω𝐹𝑆

where, F : is the frequency of x(t) , f : is the frequency of x[n]

Note that the range of the frequency variable F for continuous-time sinusoids are

−∞ < 𝐹 < ∞ , − ∞ < Ω < ∞

However, the situation is different for discrete-time sinusoids

−1

2< 𝑓 <

1

2 , − 𝜋 < ω < 𝜋

Discrete- time sinusoid whose radian frequencies are separated by integer multiples of 2π are identical.

Sequence that result from a sinusoid with a frequency |w| > π is identical to a sequence obtained from a

sinusoidal with frequency : -π ≤ w ≤ π .

But for continuous-time sinusoids result in distinct signals for Ω or F in the range : -∞< F <∞

or -∞< Ω <∞

matrix
Highlight
matrix
Sticky Note
عبارة عن مشكلة تظهر عند تحويل الاشارة من digital الى analog حيث تتمثل المشكلة في ان الاشارة الناتجة تكون مختلفة عن الاشارة المتوقع الحصول عليها و هذا بسبب عدم تحقق الشرط الاتي Fs>=2 Fm
matrix
Highlight
matrix
Highlight
matrix
Sticky Note
عملية sampling تحقق الشرط Fs>=2Fm
matrix
Sticky Note
عملية sampling لا تحقق الشرط Fs>= 2 Fm و ان التداخل او التقاطع بين الاشكال يسمى aliasing
matrix
Highlight
matrix
Highlight
matrix
Highlight
matrix
Sticky Note
بمعنى اخر يجب ان يكون هناك قيمة منطقية ل Fmax حتى نتمكن من عمل sampling بشكل صحيح
matrix
Highlight
matrix
Sticky Note
راجع المناقشة من اجل الاثبات
Page 5: (1) Sampling - site.iugaza.edu.pssite.iugaza.edu.ps/ymmatar/files/2016/02/DSP-Lab2-Sampling-Quantization.pdf · process will give you the ability to vary the sampling rate of a discrete

Figure 4.4 shows a simple example .The solid line describes a 0.5Hz continuous-time sinusoidal signal

and the dash-dot line describes a 1.5 Hz continuous time sinusoidal signal. When both signals are

sampled at the rate of Fs =2 samples/sec, their samples coincide, as indicated by the circles. This means

that x1[nTs] is equal to x2[nTs] and there is no way to distinguish the two signals apart from their sampled

versions. This phenomenon is known as aliasing.

Figure 2.4: Two sinusoidal signals are indistinguishable from their sampled versions

𝑥1 𝑛𝑇𝑆 = cos 2𝜋𝐹1𝑛𝑇𝑆 = cos 2𝜋 ×1

2 × 𝑛 ×

1

2 = cos 0.5𝜋𝑛

𝑥2 𝑛𝑇𝑆 = cos 2𝜋𝐹2𝑛𝑇𝑆 = cos 2𝜋 ×3

2 × 𝑛 ×

1

2 cos 1.5𝜋𝑛 = cos 1.5𝜋𝑛 − 2𝜋𝑛

= cos −0.5𝜋𝑛 = cos −0.5𝜋𝑛 = cos 0.5𝜋𝑛 𝑥1 𝑛𝑇𝑆 = 𝑥2 𝑛𝑇𝑆

Reconstruct 𝑥1 𝑡 𝑎𝑛𝑑 𝑥2 𝑡 𝑥1 𝑡 = 𝑥 𝑡𝐹𝑆 = cos 0.5𝜋 𝑡𝐹𝑆 = cos 0.5𝜋 𝑡 × 2 = cos 2𝜋 × 0.5 × 𝑡 = 𝑥2 𝑡

On the other hand,

𝑭𝒂𝒍𝒊𝒂𝒔𝒆𝒅 = 𝑭𝒃𝒂𝒔𝒆 + 𝒌 𝑭𝑺 , 𝒌 = ±𝟏, ±𝟐, …. 𝒇𝒂𝒍𝒊𝒂𝒔𝒆𝒅 = 𝒇𝒃𝒂𝒔𝒆 + 𝒌 , 𝒌 = ±𝟏, ±𝟐, ….

where 𝐹𝑎𝑙𝑖𝑎𝑠𝑒𝑑 𝑎𝑛𝑑 𝑓𝑎𝑙𝑖𝑎𝑠𝑒𝑑 are outside the fundamental frequency range:

−𝐹𝑆

2 ≤ 𝐹𝑏𝑎𝑠𝑒 ≤

𝐹𝑆

2 and −

1

2 ≤ 𝑓𝑏𝑎𝑠𝑒 ≤

1

2

Avoiding Aliasing

In order to avoid aliasing we must restrict the analog signal xa(t) to the frequency range, Fo less than

Fs/2. Thus, every sampler must be preceded by an analog low-pass filter, known as an anti-aliasing

filter; with a cut-off frequency fc equals fs /2.

This means that the high frequency artifacts of the continuous-time signal will be lost. This is the cost

of managing aliasing. In practice, the anti-aliasing filter will have a cutoff frequency at roughly 90% of

matrix
Highlight
matrix
Sticky Note
Figure 2.4
matrix
Sticky Note
لاحظ ان الاشارة المرسومة بالخط المتصل ترددها 0.5 هيرتز و الاخرى المتقطعة ترددها 1.5 هيرتز و عند عمل sampling على تردد يساوي 1.5 هيرتز نلاحظ ان الاشارة المتصلة تحقق الشرط Fs>=sFm ولكن الاشارة الخرى ( المتقطة ) لا تحقق هذا الشرط لذلك يحدث aliasing حيث ان النقاط الحمراء هي النقاط الناتجة من عملية sampling و لكن هذه النقاط تخص اي اشارة ؟؟؟ لذلك عند استعادة الاشارة لانستطيع تحديد التردد الصحيح و هذه هي مشكلة aliasing
matrix
Sticky Note
توضيح رياضي لعملية aliasing
matrix
Highlight
matrix
Highlight
matrix
Sticky Note
القانون الاول في حالة analog اما الثاني فهو في حالة الديجيتال
matrix
Highlight
matrix
Highlight
matrix
Sticky Note
طرقة لتخلص من aliasing عن طريق استخدام filter ويكون BW لهذا الفلتر يساوي Fs/2
matrix
Highlight
Page 6: (1) Sampling - site.iugaza.edu.pssite.iugaza.edu.ps/ymmatar/files/2016/02/DSP-Lab2-Sampling-Quantization.pdf · process will give you the ability to vary the sampling rate of a discrete

the Nyquist frequency and use the other 10% for roll-off. The on-board codec of the DSK has a

sampling rate of fs = 8 kHz and an anti-aliasing filter with cutoff frequency 3.6 kHz, which is 90% of

fs/2 (Nyquist Frequency).

Figure 2.5: Avoiding aliasing in signal processing

(2) Downsampling .

If the desired sampling rate is lower than the sampling rate of the available data, in this case, we

may use a process called downsampling or decimation to reduce the sampling rate of the signal.

Decimating, or downsampling, a signal x(n) by a factor of D is the process of creating a new signal

y(n) by taking only every Dth sample of x(n). Therefore y(n) is simply x(Dn).

Using this method we can resample the discrete signals with no need for reconstruction first. This

process will give you the ability to vary the sampling rate of a discrete signal by discarding some of

its values in the time domain depending on the desired sampling rate.

For example, if we want to reduce the sampling rate to the half, we down a sample between every two

samples. In this case, we downsampled the signal by 2, or (↓ 2 ).

Similarly, (↓ 3 ) x[n] will produce a signal that has a sample rate equals one third the sampling rate of

x[n] by taking every third sample of x[n] and discarding two samples in between.

As an example, if the original sequence with a sampling period T= 0.1 second (sampling rate = 10

samples per sec) is given by

x(n) : 8 7 4 8 9 6 4 2 2 5 7 7 6 4 . . .

and we downsample the data sequence by a factor of 3, we obtain the downsampled sequence as

y(m) : 8 8 4 5 6 . . .

with the resultant sampling period T = 3 x 0.1 = 0.3 second (the sampling rate now is 3.33 samples per

second).

After downsampling by a factor of D, the new sampling period becomes DT, and therefore the new

sampling frequency is

FS,D =1

DTs=

FS

D , where 𝐹𝑆 is the original sampling rate.

matrix
Sticky Note
يستخدم لتخلص من aliasing و لكن على حساب المعلومات الموجودة في الاشارة حيث يقوم الفلتر بالتخلص من الترددات العالية في الاشارة التي تسبب alisaing و في الغالب تكون المعلومات متركزة في الترددات المنخفضة
matrix
Highlight
matrix
Sticky Note
الفكرة الاساسية هنا انا عملنا sampling على تردد عالي و حصلنا على كمية كبيرة من samples و نريد تقليل هذه الكمية فنستخدم downsampling ولها اسم اخر هو decimation
matrix
Highlight
matrix
Highlight
matrix
Sticky Note
مثال توضيحي لعملية dawnsampling لو فرضننا اننا نريد عمل عملية dawnsampling لاشارة بمعدل او بمعامل 3 فاننا من كل تلات pulses ناخذ اول وحدة او مثلا ناخد المعدل ل pulses الثلاثة يعني كل تلات pulses بدنا نحولهم ل pulse واحدة فقط
matrix
Sticky Note
الفائدة الاساسية لعملية dawnsampling هو انا نسطيع عمل resampling لاشارة لتناسب اي تطبيق نريده بدون تحويلها الي analog ثم عمل sampling مرة اخرى
matrix
Highlight
matrix
Sticky Note
لاحظ هنا اننا عملنا dawnsampling بمعامل 3 يعني لو الاشارة فيها 9 pulses ستكون الاشارة الناتجة بها 3 pulses
matrix
Highlight
matrix
Highlight
matrix
Highlight
matrix
Sticky Note
توضيح لتغير الذي يحصل على Ts و Fs عند عمل عملية downsampling
Page 7: (1) Sampling - site.iugaza.edu.pssite.iugaza.edu.ps/ymmatar/files/2016/02/DSP-Lab2-Sampling-Quantization.pdf · process will give you the ability to vary the sampling rate of a discrete

By MATLAB, we can do this in an easy way. For example,

>> x=1:1:10

x =

1 2 3 4 5 6 7 8 9 10 >> x2=x(1:2:end)

x2 =

1 3 5 7 9

(3) Quantization .

The second stage in the A/D process is amplitude quantization, where the sampled discrete-time signal

x(n), is quantized into a finite set of output levels . The quantized signal can take only one of L levels,

which are designed to cover the dynamic range: xmin ≤ x(n) ≤ xmax

The step size or resolution of the uniform quantizer is given as:

Δ = 𝑥𝑚𝑎𝑥 − 𝑥 𝑚𝑖𝑛

L − 1

The step size can be either integer or fraction and is determined by the number of levels L. For binary

coding, L is usually a power of 2, and practical values are 256 (=2 ^8) or greater.

The difference between the actual analog value and quantized digital value is called quantization error.

This error is due to rounding.

and,

A continuous time signal, such as voice, has a continuous range of amplitudes and therefore its samples

have a continuous amplitude range i.e. they are only discrete in time not in amplitude. In other words,

within the finite amplitude range of the signal, we find an infinite number of amplitude levels. It is not

necessary in fact to transmit the exact amplitude of the samples. Any human sense (the ear or the eye), as

ultimate receiver, can detect only finite intensity differences. This means that the original continuous

time signal may be approximated by a signal constructed of discrete amplitudes selected on a minimum

error basis from an available set. Clearly, if we assign the discrete amplitude levels with sufficiently

close spacing we may take the approximated signal practically indistinguishable from the original

continuous signal.

Amplitude quantization is defined as the process of transforming the sample amplitude m(nTs) of a

message signal m(t) at time t=nTs into a discrete amplitude v(nTs) taken from a finite set of possible

amplitudes.

Quantization error : ( ) ( ) ( )q qe n x n x n

2 2error

matrix
Highlight
matrix
Highlight
matrix
Sticky Note
معامل downsampling
matrix
Highlight
matrix
Highlight
matrix
Highlight
matrix
Highlight
matrix
Sticky Note
عملة quantization هي عملية تقريب pulses الناتجة من عملية sampling لاقرب level حيث نقسم الاشارة الي levels محصورة من عند اكبر قيمة بالاشارة حتى اقل قيمة
matrix
Highlight
matrix
Highlight
matrix
Highlight
matrix
Highlight
matrix
Sticky Note
لو فرضنا انا هناك pulse موجودة في منتصف المسافة بين two level فاننا لو قربناها الي اي level منهم سيكون مقدار الخطا يساوي step size/2
matrix
Highlight
matrix
Sticky Note
عملية quantization تهدف لتحويل الاشارة من discrete الى ديجيتال حيث يمكن التعبير عن الاشارة بارقام binary وبذلك يسهل التعامل معها و نقلها و حيث ان عملية quantization تسبب فقدان في الاشارة و هي عملية غير قابلة للعكس ولا يمكن ازلة تاثيرها و لكن تاثيرها لا يمكن ادراكه من قبل الانسان اذا كان عدد level كتير
matrix
Highlight
Page 8: (1) Sampling - site.iugaza.edu.pssite.iugaza.edu.ps/ymmatar/files/2016/02/DSP-Lab2-Sampling-Quantization.pdf · process will give you the ability to vary the sampling rate of a discrete

Practical Parts:

Part 1: Aliasing in Time Domain

The signal 𝑥 𝑡 = sin 2𝜋𝐹𝑜𝑡 can be sampled at the rate 𝐹𝑆 =1

𝑇𝑆 to yield 𝑥(𝑛) = 𝑐𝑜𝑠 2𝜋

𝐹𝑜

𝐹𝑆 𝑛

Aliasing will be observed for various 𝐹𝑜

a) Let 𝐹𝑆=10 kHz and 𝐹𝑜=1 kHz. Compute and plot x[n] using stem.m.

n=0:50; Fs=10000; Fo=1000; xn=sin(2*pi*(Fo/Fs)*n) figure(1) stem(xn)

b) Use subplot to plot x(t) for 𝐹𝑜=300 Hz, 700 Hz, 1100 Hz and 1500 Hz.

Fs=10000; t=0:0.0001:50/Fs; Fo=[300,700,1100,1500]; for i=1:4; subplot(4,1,i) xt=sin(2*pi*Fo(i)*t) plot(t,xt)

end

Comment on the following words for the result figure in (b):

(a) The period: .

(b) The rate of oscillation: .

c) Use subplot to plot x[n] for 𝐹𝑜=300 Hz, 700 Hz, 1100 Hz and 1500 Hz.

Fs=10000;

n=0:50; Fo=[300,700,1100,1500]; for i=1:4; subplot(4,1,i) xn=sin(2*pi*(Fo(i)/Fs)*n) stem(xn) end

Comment on the following words for the result figure in (c):

(a) Aliasing: : .

(b) The period: .

(c) The rate of oscillation: .

(d) Fill in the table below with appropriate values:

Page 9: (1) Sampling - site.iugaza.edu.pssite.iugaza.edu.ps/ymmatar/files/2016/02/DSP-Lab2-Sampling-Quantization.pdf · process will give you the ability to vary the sampling rate of a discrete

Fo=300 Hz Fo=700 Hz Fo=1100 Hz Fo=1500 Hz

Faliased

T=1/F

Fbase

faliased

fbase

N

d) Repeat (b) and (c) for 𝐹𝑜=8500 Hz, 8900 Hz, 9300 Hz and 9700 Hz.

e) Repeat (b) and (c) for 𝐹𝑜=10300 Hz, 10700 Hz, 11100 Hz and 11500 Hz.

Consider an analog signal x(t) consisting of three sinusoids

x(t)= cos(2πt)+cos(8πt)+cos(12πt) Using Matlab,

(a) Show that if this signal is sampled at a rate of Fs = 5 Hz, it will be aliased with the following

signal, in the sense that their sample values will be the same:

xa(t)= 3cos(2πt)

(b) Repeat part (a) with Fs = 10 Hz. In this case, determine the signal x(t) with which xa(t) is

aliased. Plot both x(t) and xa(t) on the same graph over the range 0 ≤ t ≤ 1 sec. Verify again that

the signals intersect at the sampling instants.

Exercise 1

Page 10: (1) Sampling - site.iugaza.edu.pssite.iugaza.edu.ps/ymmatar/files/2016/02/DSP-Lab2-Sampling-Quantization.pdf · process will give you the ability to vary the sampling rate of a discrete

Part 2: Aliasing in Frequency Domain:

a) Construct the simulink model shown in Figure 4.6.

b) Input a sine wave of Fo=5 Hz frequency from the signal generator. Choose a sampling time of 0.01 sec for the pulse generator with pulse duration of 50 % of the sampling

period. Choose the cut-off frequency of 120π for the Butterworth low-pass filter.

c) Start the simulation for 1sec and notice all visualizers(included them in your report).

d) Repeat steps 2 and 3 for a sine wave with Fo = 95 Hz. Comment.

e) Repeat steps 2 and 3 for a sine wave with Fo = 105 Hz. Comment.

Figure 2.6: Simulink model to implement aliasing in frequency domain

Part 3: Downsampling:

a) Using MATLAB, generate a sine wave with frequency Fo of 1300 Hz, and sampling frequency Fs of

8000 Hz. b) Save the data of the sine wave as a sound file, named as 8000.wav. c) Listen to the tone of the 1300 Hz sine wave. d) Downsample the data of the sine wave by 2. This will result in a sine wave with a sampling rate of

4000 Hz. Repeat steps b, c and compare the sounds. e) Generate a sine wave with frequency Fo of 1300 Hz, and sampling frequency Fs of 4000Hz. f) Repeat steps b and c and compare the sounds.

Page 11: (1) Sampling - site.iugaza.edu.pssite.iugaza.edu.ps/ymmatar/files/2016/02/DSP-Lab2-Sampling-Quantization.pdf · process will give you the ability to vary the sampling rate of a discrete

clc clear all n=0:1:5000; Fo=1300; Fs=8000; x=sin(2*pi*Fo*n/Fs); sound (x);

pause clear all n=0:2:5000; Fo=1300; Fs=8000; x=sin(2*pi*Fo*n/Fs); sound (x);

pause clear all n=0:1:5000; Fo=1300; Fs=4000; x=sin(2*pi*Fo*n/Fs); sound(x(1:2500));

Part 4: Quantization:

a) Write a Matlab function Y = uquant(X,L) which will uniformly quantize an input array X (either a

vector or a matrix) to L discrete levels.

function y=uquant(x,n) del=((max(max(x))-(min(min(x)))))/(n-1); r=(x-min(min(x)))/del; r=round(r); y=r*del+min(min(x));

matrix
Highlight
matrix
Sticky Note
هنا funtion يعمل على كل من vector و matrix و الهدف من ذلك ان يكون هذا function قادر على التعامل مع الصوت و صورة ابيض و اسود
matrix
Highlight
matrix
Sticky Note
عدد levels
matrix
Sticky Note
قلنا max(max()) بسبب ان x قد تكون صورة و الصورة لها بعدان لذلك يلزم استخدام امر max مرتين
matrix
Highlight
matrix
Sticky Note
لاحظ ان هذا السطر عكس لكل العمليات الي فوقه
Page 12: (1) Sampling - site.iugaza.edu.pssite.iugaza.edu.ps/ymmatar/files/2016/02/DSP-Lab2-Sampling-Quantization.pdf · process will give you the ability to vary the sampling rate of a discrete

Example: Quantized x=2sin (2pi*t) using 16 levels.

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-2

-1.5

-1

-0.5

0

0.5

1

1.5

2

0 20 40 60 80 100 1200

5

10

15

0 20 40 60 80 100 1200

5

10

15

0 20 40 60 80 100 120-2

-1.5

-1

-0.5

0

0.5

1

1.5

2

0 20 40 60 80 100 1200

0.5

1

1.5

2

2.5

3

3.5

4

0 20 40 60 80 100 1200

0.5

1

1.5

2

2.5

3

3.5

4

15

0

Mapping to

[ 0 to 15 ]

Round to the

nearest level.

Re-mapping to

[ -2 to 2 ]

Shift to

+ve region

[ o to 4]

x-min(min(x))

Divide by del

matrix
Highlight
matrix
Sticky Note
هنا del = 4/15
Page 13: (1) Sampling - site.iugaza.edu.pssite.iugaza.edu.ps/ymmatar/files/2016/02/DSP-Lab2-Sampling-Quantization.pdf · process will give you the ability to vary the sampling rate of a discrete

b) Use this function to quantize an analog sinusoidal signal with L=4 and 32 levels. Compute the SQR

for each level.

t=0:.001:1; y=2*sin(2*pi*t) figure(1) subplot(311) plot(y)

q1=uquant(y,4) subplot(312) plot(q1)

q2=uquant(y,32) subplot(313) plot(q2)

Ps=mean(y.^2); Pq1=mean(q1.^2); Pq2=mean(q2.^2); SQR1=Ps/Pq1; SQR2=Ps/Pq2;

c) Audio quantization, use uquant function to quntize an audio signal at different levels and compare

the result quantized signals by hearing them.

clc clear all [y,fs]=wavread('speech_dft.wav'); sound(y,fs)

for b=1:7; L=2.^b; yQ=uquant(y,L); pause b sound(yQ,fs) end

f) Construct the simulink model shown in Figure 4.6.

Input a sine wave of Fo=1 Hz frequency from the signal generator. Choose a sampling time of 0.1 sec for the pulse generator with pulse duration of 50 % of the sampling

period. Choose the quantization interval of 0.5 for the Quantizer.

Start the simulation and notice all visualizers(included them in your report).

matrix
Highlight
matrix
Sticky Note
طريقة حساب power الخاص بالاشارة
matrix
Sticky Note
ملاحظة هامة : عند زيادة quantization level فان جودة الاشارة تتحسن سواء كانت صورة او صوت لذلك تتحسن SQNR و تحسن SQNR يتمثل في زيادة قيمتها
matrix
Highlight
matrix
Sticky Note
يجوز استخدام امر subplot بدون فواصل في الاقواس
matrix
Sticky Note
فائدة هذا الامر انا الماتلاب لايكمل تنفيز الكود الا عند النقر على زر في الكيبورد ( اي زر )
matrix
Highlight
matrix
Sticky Note
لاحظ تحسن جودة الصوت بزيادة b و ذلك لان زيادة b تعني زيادة quantization levels زيادة levels يعني زيادة الجودة
Page 14: (1) Sampling - site.iugaza.edu.pssite.iugaza.edu.ps/ymmatar/files/2016/02/DSP-Lab2-Sampling-Quantization.pdf · process will give you the ability to vary the sampling rate of a discrete

Figure 2.7: Simulink model for sampling and quantization

(1) Image Quantization Use uquant function to quantize the office_4.jpg image (you can found it in the direction

c:\Program Files\matlab\toolbox\images\imdemosimage\office_4.jpg)

to 7, 4, 2 and 1 b/pel. Observe and print the output images for each level.

Note you must first convert the image from RGB to gray image.

(2) Audio Quantization Form results in part 4(c) answer the following questions:

(a) Describe the change in quality as the number of b/sample is reduced? (b) Do you think 4 b/sample is acceptable for telephone systems? (c) Plot the SQNR versus number of bits .Generate this curve by computing the SQNR for 7,

6, 5,..., 1 bits/sample. Also display this curve in semi-log(dB). (d) Plot the distortion versus number of bits in linear and semi-log scales.

Exercise 2

Page 15: (1) Sampling - site.iugaza.edu.pssite.iugaza.edu.ps/ymmatar/files/2016/02/DSP-Lab2-Sampling-Quantization.pdf · process will give you the ability to vary the sampling rate of a discrete

Given a sinusoidal waveform with a frequency of 100 Hz,

(a) Write a MATLAB program to quantize the x(t) using 4-bit quantizers to obtain the

quantized signal xq, assuming that the signal range is from -5 to 5 volts.

(b) Plot the original signal, quantized signal, and quantization error, respectively.

(c) Calculate the SQNR due to quantization using the MATLAB program.

Check for your answer with equation (1.4.32) in Proakis's Book.

Note:

Your report should include the following:

1- All Matlab program and its results with a short comment on each result. 2- Answer any internal questions in practical parts. 3- Solve all lab exercises.

Exercise 3