diff options
Diffstat (limited to '737')
-rw-r--r-- | 737/CH2/EX2.1/Example2_01.sce | 35 | ||||
-rw-r--r-- | 737/CH2/EX2.10/Example2_10.sce | 19 | ||||
-rw-r--r-- | 737/CH2/EX2.2/Example2_02.sce | 39 | ||||
-rw-r--r-- | 737/CH2/EX2.3/Example2_03.sce | 30 | ||||
-rw-r--r-- | 737/CH2/EX2.4/Example2_04.sce | 19 | ||||
-rw-r--r-- | 737/CH2/EX2.5/Example2_05.sce | 12 | ||||
-rw-r--r-- | 737/CH2/EX2.6/Example2_06.sce | 18 | ||||
-rw-r--r-- | 737/CH2/EX2.7/Example2_07.sce | 19 | ||||
-rw-r--r-- | 737/CH2/EX2.8/Example2_08.sce | 33 | ||||
-rw-r--r-- | 737/CH2/EX2.9/Example2_09.sce | 23 |
10 files changed, 247 insertions, 0 deletions
diff --git a/737/CH2/EX2.1/Example2_01.sce b/737/CH2/EX2.1/Example2_01.sce new file mode 100644 index 000000000..9c849e45a --- /dev/null +++ b/737/CH2/EX2.1/Example2_01.sce @@ -0,0 +1,35 @@ +//Example 2.1 page 19
+//Suppose that an analog signal is given as
+//x(t) = 5*cos(2*pi*1000t), for t >= 0
+//and is sampled at the rate of 8,000 Hz.
+//a. Sketch the spectrum for the original signal.
+//b. Sketch the spectrum for the sampled signal from 0 to 20 kHz.
+
+clc;
+clear;
+close;
+fs = 8000;//Hz
+t = 1:(1/fs):10;
+x = 5*cos(2*%pi*1000*t);
+
+//c1 and f1 are derived using the euler's identity which gives
+// 5cos(2pi*1000t) = 2.5 * %e^(%i*2*%pi*1000t)+ 2.5 * %e^(-%i*2*%pi*1000t)
+c1 = [2.5 2.5];
+f1 = [-1 1];//kHz
+
+ax=gda();
+ax.thickness = 2;
+ax.y_location = "origin";
+ax.x_location = "origin";
+
+subplot(2,1,1)
+plot2d3(f1,c1)
+xtitle('Spectrum of the analog signal in Example 2.1(a)','f(kHz)','X(f)');
+
+//c2 = [2.5 2.5 2.5 2.5 2.5 2.5 2.5 2.5 2.5 2.5]
+//f2 = [-17 -15 -9 -7 -1 1 7 9 15 17]
+c2 = repmat([2.5],1,10);//amplitude is same for each
+f2 = [f1-16 f1-8 f1 f1+8 f1+16];//after sampling, spectrum is replicated cyclically with centered at +-n8000Hz
+subplot(2,1,2);
+plot2d3(f2,c2)
+xtitle('Spectrum of the sampled signal in Example 2.1(b)','f(kHz)','Xs(f)');
\ No newline at end of file diff --git a/737/CH2/EX2.10/Example2_10.sce b/737/CH2/EX2.10/Example2_10.sce new file mode 100644 index 000000000..38bfd3493 --- /dev/null +++ b/737/CH2/EX2.10/Example2_10.sce @@ -0,0 +1,19 @@ +//Example 2.10 page 42
+//Using Example 2.9, determine the quantization error when the analog
+//input is 3.2 volts.
+
+
+clc,clear,close;
+xmin = 0, xmax = 5;//volts
+m = 3;//bits
+
+L = 2^m;
+
+delta = (xmax-xmin)/L;
+
+x = 3.2;
+
+xq = xmin+5*delta;
+
+eq = xq-x;
+disp("eq = "+string(eq));
\ No newline at end of file diff --git a/737/CH2/EX2.2/Example2_02.sce b/737/CH2/EX2.2/Example2_02.sce new file mode 100644 index 000000000..1aeef260d --- /dev/null +++ b/737/CH2/EX2.2/Example2_02.sce @@ -0,0 +1,39 @@ +//Example 2.2 page 23
+//
+//Assuming that an analog signal is given by
+//x(t) = 5 cos (2*%pi*2000*t) + 3*cos(2*%pi*3000*t),for t>=0
+//and it is sampled at the rate of 8,000 Hz,
+//a. Sketch the spectrum of the sampled signal up to 20 kHz.
+//b. Sketch the recovered analog signal spectrum if an ideal lowpass filter with
+//a cutoff frequency of 4 kHz is used to filter the sampled signal
+//(y(n) = x(n)in this case) to recover the original signal.
+
+clc;
+clear;
+close;
+fs = 8000;//Hz
+t = 1:(1/fs):10;
+x = 5*cos(2*%pi*2000*t)+ 3*cos(2*%pi*3000*t);
+//before sampling
+
+//c1 and f1 are derived using the euler's identity which gives
+// x(t) = 1.5 * %e^(-%i*2*%pi*3000t)+ 2.5 * %e^(-%i*2*%pi*2000t)+ 2.5 * %e^(%i*2*%pi*2000t) + 1.5 * %e^(%i*2*%pi*3000t)
+
+c1 = [1.5 2.5 2.5 1.5];
+f1 = [-3 -2 2 3];//kHz
+
+//after sampling
+c2 = repmat(c1,1,5);
+f2 = [f1-16 f1-8 f1 f1+8 f1+16];
+ax=gda();
+ax.thickness = 2;
+ax.y_location = "origin";
+ax.x_location = "origin";
+
+subplot(2,1,1)
+plot2d3(f2,c2)
+xtitle('Spectrum of the sampled signal in Example 2.2(a)','f(kHz)','X(f)');
+//Since Sampling theorem is satisfied, we can recover the original spectrum using reconstruction low pass filter.
+subplot(2,1,2)
+plot2d3(f1,c1)
+xtitle('Spectrum of the recovered signal in Example 2.2(b)','f(kHz)','X(f)');
diff --git a/737/CH2/EX2.3/Example2_03.sce b/737/CH2/EX2.3/Example2_03.sce new file mode 100644 index 000000000..71f04770e --- /dev/null +++ b/737/CH2/EX2.3/Example2_03.sce @@ -0,0 +1,30 @@ +//Example 2.3 page 24
+//Given an analog signal
+//x(t) = 5 cos (2 pi 2000t)+ 1 cos( 2pi 5000t), for t>=0
+//which is sampled at a rate of 8,000 Hz,
+//a. Sketch the spectrum of the sampled signal up to 20 kHz.
+//b. Sketch the recovered analog signal spectrum if an ideal lowpass filter with
+//a cutoff frequency of 4 kHz is used to recover the original signal
+//(y(n)= x(n) this case).
+
+clc,clear,close;
+
+c1 = [0.5 2.5 2.5 0.5];
+//sampling theorem is violated
+f1 = [-3 -2 2 3];//kHz
+
+//after sampling
+c2 = repmat(c1,1,5);
+f2 = [f1-16 f1-8 f1 f1+8 f1+16];
+ax=gda();
+ax.thickness = 2;
+ax.y_location = "origin";
+ax.x_location = "origin";
+
+subplot(2,1,1)
+plot2d3(f2,c2)
+xtitle('Spectrum of the sampled signal in Example 2.3(a)','f(kHz)','X(f)');
+//Since Sampling theorem is not satisfied, we can not recover the original spectrum using reconstruction low pass filter.
+subplot(2,1,2)
+plot2d3(f1,c1)
+xtitle('Spectrum of the recovered signal in Example 2.3(b)','f(kHz)','X(f)');
diff --git a/737/CH2/EX2.4/Example2_04.sce b/737/CH2/EX2.4/Example2_04.sce new file mode 100644 index 000000000..cbf4ee3a1 --- /dev/null +++ b/737/CH2/EX2.4/Example2_04.sce @@ -0,0 +1,19 @@ +//Example 2.4 page 27
+//Given the DSP system shown in Figures 2.16 to 2.18, where a sampling rate of 8,000 Hz is used and the anti-aliasing filter is a second-order Butterworth lowpass filter with a cutoff frequency of 3.4 kHz,
+//a. Determine the percentage of aliasing level at the cutoff frequency.
+//b. Determine the percentage of aliasing level at the frequency of 1,000 Hz.
+
+clc,clear,close;
+fs=8000,fc = 3400;//Hz
+n =2;
+
+//part a
+fa = 3400;//Hz, aliasing frequency
+aliasing_noise = (1+(fa/fc)^(2*n))^(.5) / (1+((fs-fa)/fc)^(2*n))^(.5) * 100;
+disp("(a) Aliasing Noise Level = "+string(aliasing_noise)+"%" )
+
+//part b
+fa = 1000;//Hz, aliasing frequency
+aliasing_noise = (1+(fa/fc)^(2*n))^(.5) / (1+((fa-fs)/fc)^(2*n))^(.5) * 100;
+disp("(b) Aliasing Noise Level = "+string(aliasing_noise)+"%" )
+
diff --git a/737/CH2/EX2.5/Example2_05.sce b/737/CH2/EX2.5/Example2_05.sce new file mode 100644 index 000000000..5230aa258 --- /dev/null +++ b/737/CH2/EX2.5/Example2_05.sce @@ -0,0 +1,12 @@ +//Example 2.5 page 28
+//Given the DSP system shown in Figures 2.16 to 2.18, where a sampling
+//rate of 16,000 Hz is used and the anti-aliasing filter is a second-order
+//Butterworth lowpass filter with a cutoff frequency of 3.4 kHz, determine
+//the percentage of aliasing level at the cutoff frequency.
+clc,clear,close;
+fs=16000,fc = 3400;//Hz
+n =2;
+
+fa = 3400;//Hz, aliasing frequency
+aliasing_noise = (1+(fa/fc)^(2*n))^(.5) / (1+((fs-fa)/fc)^(2*n))^(.5) * 100;
+disp("Aliasing Noise Level = "+string(aliasing_noise)+"%" )
\ No newline at end of file diff --git a/737/CH2/EX2.6/Example2_06.sce b/737/CH2/EX2.6/Example2_06.sce new file mode 100644 index 000000000..5c0298d92 --- /dev/null +++ b/737/CH2/EX2.6/Example2_06.sce @@ -0,0 +1,18 @@ +//Example 2.6 page 29 +//Given the DSP system shown in Figure 2.16, where a sampling rate of +//40,000 Hz is used, the anti-aliasing filter is a Butterworth lowpass filter +//with a cutoff frequency of 8 kHz, and the percentage of aliasing level at the +//cutoff frequency is required to be less than 1%, determine the order of +//the anti-aliasing lowpass filter. + +clc,clear,close; +fs=40000,fc = 8000,fa=8000;//Hz +aliasing_noise = 100; +n = 0; +while(aliasing_noise > 1) + n = n+1; + aliasing_noise = (1+(fa/fc)^(2*n))^(.5) / (1+((fs-fa)/fc)^(2*n))^(.5) * 100; + disp("n = "+string(n)+", Aliasing Noise Level = "+string(aliasing_noise)+"%" ) +end + +disp("To satisfy 1% aliasing noise level, we choose n = " +string(n));
\ No newline at end of file diff --git a/737/CH2/EX2.7/Example2_07.sce b/737/CH2/EX2.7/Example2_07.sce new file mode 100644 index 000000000..384f58fb3 --- /dev/null +++ b/737/CH2/EX2.7/Example2_07.sce @@ -0,0 +1,19 @@ +//Example 2.7 page 31
+//Given a DSP system with a sampling rate of 8,000 Hz and a hold circuit used
+//after DAC,
+//a. Determine the percentage of distortion at the frequency of 3,400 Hz.
+//b. Determine the percentage of distortion at the frequency of 1,000 Hz.
+clc,clear,close;
+fs = 8000;
+T = 1/fs;
+//part a
+fa = 3400;
+x = fa*T;
+distortion = (1 - sin(x*%pi)/(x*%pi)) * 100;
+disp("(a) distortion % = " + string(distortion) + "%");
+
+//part b
+fb = 1000;
+x = fb*T;
+distortion = (1 - sin(x*%pi)/(x*%pi)) * 100;
+disp("(b) distortion % = " + string(distortion) + "%");
\ No newline at end of file diff --git a/737/CH2/EX2.8/Example2_08.sce b/737/CH2/EX2.8/Example2_08.sce new file mode 100644 index 000000000..93cc41aad --- /dev/null +++ b/737/CH2/EX2.8/Example2_08.sce @@ -0,0 +1,33 @@ +//Example 2.8 page 33
+//Determine the cutoff frequency and the order for the anti-image filter
+//given a DSP system with a sampling rate of 16,000 Hz and specifications
+//for the anti-image filter as shown in Figure 2.24.
+//
+//Design requirements:
+//& Maximum allowable gain variation from 0 to 3,000 Hz ΒΌ 2dB
+//& 33 dB rejection at the frequency of 13,000 Hz
+//& Butterworth filter assumed for the anti-image filter
+clc,clear,close;
+
+fs = 16000;
+T = 1/fs;
+f1 = 3000,f2 = 13000;//Hz
+x1 = f1*T;
+gain1 = sin(x1*%pi)/(x1*%pi);
+gaindb1 = 10*log(gain1);
+disp("For f = 3000Hz, gain = "+string(gain1)+" = "+string(gaindb1));
+
+x2 = f2*T;
+gain2 = sin(x2*%pi)/(x2*%pi);
+gaindb2 = 10*log(gain2);
+disp("For f = 13000Hz, gain = "+string(gain2)+" = "+string(gaindb2));
+
+n = .5*log((10^2-1)/(10^0.154 - 1))/log(f2/f1)
+disp("n = "+string(n));
+n = round(n);
+
+fc2 = f2/(10^2-1)^(1/(2*n));
+fc1 = f1/(10^0.154-1)^(1/2/n);
+
+disp("fc1 = "+string(fc1)+" fc2 = "+string(fc2));
+disp("we choose the smaller one, that is " + string(min(fc1,fc2)));
\ No newline at end of file diff --git a/737/CH2/EX2.9/Example2_09.sce b/737/CH2/EX2.9/Example2_09.sce new file mode 100644 index 000000000..41ebc3c03 --- /dev/null +++ b/737/CH2/EX2.9/Example2_09.sce @@ -0,0 +1,23 @@ +//Example 2.9 Page 39
+//Assuming that a 3-bit ADC channel accepts analog input ranging from 0 to 5
+//volts, determine the following:
+//a. number of quantization levels
+//b. step size of the quantizer or resolution
+//c. quantization level when the analog voltage is 3.2 volts
+
+clc,clear,close;
+xmin = 0, xmax = 5;//volts
+m = 3;//bits
+
+L = 2^m;
+disp("L = "+string(L)+" bits");
+
+delta = (xmax-xmin)/L;
+disp("delta = "+string(delta)+" volts");
+
+x = 3.2*delta/6.25
+i = round((x-xmin)/delta);
+disp("i= "+string(i)+" volts");
+
+xq = xmin+5*delta;
+disp("xq= "+string(xq)+" volts");
|