Sunteți pe pagina 1din 11

Lab 05

Sampling, A/D Conversion, D/A Conversion


Question 01
x [ n ]=sin(2

f0
n+ )
fs

a) Use a value of f s = 8 kHz. By varying the value of f0, it is


possible to illustrate the aliasing. For an interval of 10 ms, plot the
sampled sine wave if f0 = 300 Hz, using stem. The phase can be
arbitrary. You should see a sinusoidal pattern. If not, use the plot
function which creates the impression of a continuous function from
discrete time values.
f=8000;
f0=300;
n= [0.01:0.001:0.10]
a=f./f0;
x=sin(2*3.14*a*n);
plot(n,x)
1
0.8
0.6
0.4
0.2
0
-0.2
-0.4
-0.6
-0.8
-1
0.01

0.02

0.03

0.04

0.05

0.06

0.07

0.08

0.09

0.1

0.11

f=8000;
f0=300;
n= [0.01:0.001:0.10]
a=f./f0;
x=sin(2*3.14*a*n);
stem(n,x)

12-EE-109

1
0.8
0.6
0.4
0.2
0
-0.2
-0.4
-0.6
-0.8
-1
0.01

0.02

0.03

0.04

0.05

0.06

0.07

0.08

0.09

0.1

0.11

b) Vary the frequency f0 from 100 Hz to 475 Hz, in steps of 125 Hz.
The apparent frequency of the sinusoid should be increasing, as
expected. Use subplot to put four plots on one screen.
f=8000;
f0=100;
n= [0.01:0.001:0.10]
a=f./f0;
x=sin(2*3.14*a*n);
subplot(2,2,1);
stem(n,x)
f=8000;
f0=225;
n= [0.01:0.001:0.10]
a=f./f0;
x=sin(2*3.14*a*n);
subplot(2,2,2);
stem(n,x)
f=8000;
f0=350;
n= [0.01:0.001:0.10]
a=f./f0;
x=sin(2*3.14*a*n);
subplot(2,2,3);
stem(n,x)
f=8000;
f0=475;
n= [0.01:0.001:0.10]
a=f./f0;
x=sin(2*3.14*a*n);
subplot(2,2,4);
stem(n,x)

12-EE-109

0.5

0.5

-0.5

-0.5

-1

0.05

0.1

-1

0.5

0.5

-0.5

-0.5

-1

0.05

0.1

-1

0.05

0.1

0.05

0.1

c) Vary the frequency f0 from 7525 Hz to 7900 Hz, in steps of 125


Hz. Note that the apparent frequency of the sinusoid is now
decreasing. Explain why.
f=8000;
f0=7525;
n= [0.01:0.001:0.10]
a=f./f0;
x=sin(2*3.14*a*n);
subplot(2,2,1);
stem(n,x)
f=8000;
f0=7650;
n= [0.01:0.001:0.10]
a=f./f0;
x=sin(2*3.14*a*n);
subplot(2,2,2);
stem(n,x)
f=8000;
f0=7775;
n= [0.01:0.001:0.10]
a=f./f0;
x=sin(2*3.14*a*n);
subplot(2,2,3);
stem(n,x)
f=8000;
f0=7900;
n= [0.01:0.001:0.10]
a=f./f0;
x=sin(2*3.14*a*n);
subplot(2,2,4);
stem(n,x)

12-EE-109

0.8

0.8

0.6

0.6

0.4

0.4

0.2

0.2

0.05

0.1

0.8

0.8

0.6

0.6

0.4

0.4

0.2

0.2

0.05

0.1

0.05

0.1

0.05

0.1

d) Vary the frequency f0 from 32100 Hz to 32475 Hz, in steps of 125


Hz. Can you predict in advance if the frequency will increase or
decrease? Why/How?
f=8000;
f0=32100;
n= [0.01:0.001:0.10]
a=f./f0;
x=sin(2*3.14*a*n);
subplot(2,2,1);
stem(n,x)
f=8000;
f0=32225;
n= [0.01:0.001:0.10]
a=f./f0;
x=sin(2*3.14*a*n);
subplot(2,2,2);
stem(n,x)
f=8000;
f0=32350;
n= [0.01:0.001:0.10]
a=f./f0;
x=sin(2*3.14*a*n);
subplot(2,2,3);
stem(n,x)
f=8000;
f0=32475;
n= [0.01:0.001:0.10]
a=f./f0;
x=sin(2*3.14*a*n);

12-EE-109

subplot(2,2,4);
stem(n,x)
0.2

0.2

0.15

0.15

0.1

0.1

0.05

0.05

0.05

0.1

0.2

0.2

0.15

0.15

0.1

0.1

0.05

0.05

0.05

0.1

0.05

0.1

0.05

0.1

Question 02
a) Simulate a continuous sinusoid signal by generating samples
separated by a small
interval of t = 1/80000 second (time resolution):
x(t) = cos(2f0t) cos(2f0 n t) , n=0,1,2,...
Plot as a continuous function 1000 samples of the resulting signal
when the frequency f0 is 2 kHz.
f=2000;
n= [0.01:0.0000125:0.015]
a=f*n;
x=cos(6.28*a);
stem(n,x)

12-EE-109

1
0.8
0.6
0.4
0.2
0
-0.2
-0.4
-0.6
-0.8
-1
0.01

0.0105 0.011 0.0115 0.012 0.0125 0.013 0.0135 0.014 0.0145 0.015

b) Plot the continuous time Fourier transform (amplitude) of the


signal using the following function, where dt is the time resolution:
function freqmagplot(x,dt)
f=2000;
n= [0.01:0.0000125:0.1]
a=f*n;
x=cos(6.28*a);
dt=0.0000125;
L=length(x);
Nfft=round(2.^round(log2(5*L)));
X=fft(x,Nfft);
f=((1/dt)/Nfft)*(0:1:Nfft/2-1);
plot(f,abs(X(1:Nfft/2)));
title('Magnitude of Fourier Transform');
xlabel('Frequency'),grid;

12-EE-109

Magnitude of Fourier Transform

4000
3500
3000
2500
2000
1500
1000
500
0

0.5

1.5

2
Frequency

2.5

3.5

4
4

x 10

c. To simulate the A/D conversion at a rate of f s = 8000 Hz


(sampling period of 1/8000 second), we need to keep one sample in
every 10 samples from the signal in (a). Plot the resulting discrete
time signal and its discrete time Fourier transform
function freqmagplot(x,dt)
f=2000;
n= [0.01:0.000125:0.1]
a=f*n;
x=cos(6.28*a);
dt=0.000125;
L=length(x);
Nfft=round(2.^round(log2(5*L)));
X=fft(x,Nfft);
f=((1/dt)/Nfft)*(0:1:Nfft/2-1);
plot(f,abs(X(1:Nfft/2)));
title('Magnitude of Fourier Transform');
xlabel('Frequency'),grid;

12-EE-109

Magnitude of Fourier Transform

400
350
300
250
200
150
100
50
0

500

1000

1500

2000
Frequency

2500

3000

3500

4000

d) To simulate the D/A conversion, we need to follow two steps. To


simulate the analog pulse signal, 9 zeros are added between each
sample of the discrete time signal from (c), so that the resulting
simulated continuous signal has the original resolution of 1/80000
sec. Plot the resulting signal and its continuous time Fourier
transform.
f=2000;
n= [10000000:12500:15000000]
a=f*n;
x=cos(6.28*a);
plot(n,x)

1
0.8
0.6
0.4
0.2
0
-0.2
-0.4
-0.6
-0.8
-1

1.05

1.1

1.15

1.2

1.25

1.3

1.35

1.4

1.45

1.5
7

x 10

function freqmagplot(x,dt)
f=2000;
n= [10000000:12500:15000000]
a=f*n;
x=cos(6.28*a);

12-EE-109

plot(n,x)
dt=12500;
L=length(x);
Nfft=round(2.^round(log2(5*L)));
X=fft(x,Nfft);
f=((1/dt)/Nfft)*(0:1:Nfft/2-1);
plot(f,abs(X(1:Nfft/2)));
title('Magnitude of Fourier Transform');
xlabel('Frequency'),grid;
Magnitude of Fourier Transform

250

200

150

100

50

0.5

1.5

2
Frequency

2.5

3.5

4
-5

x 10

e) Plot the signal at the output if the filter, discard the first 200
samples (transient response) and plot the continuous time Fourier
transform of the resulting signal. Compare with (b).
f=2000;
n= [10000000:12500:15000000]
a=f*n;
x=cos(6.28*a);
fs=8000;
[b,a]=cheby2(9,60, fs *1/80000)
y = filter(b,a,x);
plot(n,y)

12-EE-109

1
0.8
0.6
0.4
0.2
0
-0.2
-0.4
-0.6
-0.8
-1
0.01

0.0105 0.011 0.0115 0.012 0.0125 0.013 0.0135 0.014 0.0145 0.015

function freqmagplot(x,dt)
f=2000;
n= [10000000:12500:15000000]
a=f*n;
x=cos(6.28*a);
fs=8000;
[b,a]=cheby2(9,60, fs *1/80000)
y = filter(b,a,x);
plot(n,y)
dt=12500;
L=length(y);
Nfft=round(2.^round(log2(5*L)));
X=fft(y,Nfft);
f=((1/dt)/Nfft)*(0:1:Nfft/2-1);
plot(f,abs(X(1:Nfft/2)));
title('Magnitude of Fourier Transform');
xlabel('Frequency'),grid;

12-EE-109

Magnitude of Fourier Transform

4000
3500
3000
2500
2000
1500
1000
500
0

0.5

1.5

2
Frequency

2.5

3.5

4
4

x 10

f) Repeat the steps in a) b) c) d) e) with f0 = 2500 Hz, 3500 Hz, 4500


Hz, 5500 Hz (plots not required here). When does aliasing occurs?
What is the effect of aliasing on the output signal of the D/A
converter (found in (e) )
Aliasing occurs when fs is smaller than 2f0. Aliasing causes signals to overlap
hence resulting in loss of part of signal. Due to which the original signal
cannot be reconstructed or obtained back perfectly/completely hence there
is loss of data.

12-EE-109

S-ar putea să vă placă și