Chapter 7 Over-Sampling and Multi-Rate DSP Systems Objectives • • • • • • • • • Describe the anti-aliasing problem and its solution with over-sampling. Demonstrate the details of digital anti-aliasing and anti-imaging. Demonstrate the processes of down-sampling (decimation) and upsampling (interpolation) to change the effective sampling rate of a digital signal. Show that interpolation is accomplished by up-sampling and a gain-adjusted low-pass filter. Demonstrate the process of rational rate conversion by cascaded interpolation and decimation. Derive the relationship between sampling rate and the spectral density of random noise. Demonstrate the de-noising of signals with over-sampling. Describe the process of delta-sigma quantization and derive the transfer functions for a first-order noise-shaping quantizer. Demonstrate the process of delta-sigma quantization and the recovery of a quantized signal by low-pass filtering The Anti-Aliasing Problem • If a signal contains a band-width of interest, W, then the minimum sampling frequency is 2W (Nyquist requirement) • However, to prevent aliasing, the signal must be analog pre-filtered to a band-width of fs/2 prior to sampling • If the signal contains frequency components or noise beyond W, the analog low-pass filter (“anti-aliasing” filter) must be impractically sharp if sampling is done at 2W • Solution: Multi-rate processing – Over-sample the signal at a rate considerably higher than 2W and band-width limit the signal with a sharp digital low-pass filter – “Down-sample” the signal digitally to an effective rate 2W after digital filtering – This allows the use of a simple analog anti-aliasing filter Why Does Over-Sampling Help Anti-Aliasing? Over-sampled W W 0fs 1fs 2fs Nyquist-sampled W W Magnitude Responses of Required AntiAliasing Analog Filters Digital Anti-Aliasing and Anti-Imaging Simple Analog LP Filter High Rate Sampling (ADC) Digital LP Filter Down-sample to Nyquist Rate Decimation Anti-Aliasing Step Up-sample to high rate Digital LP Filter DAC at High Rate Interpolation Anti-Imaging Step Simple Analog LP Filter Down-Sampling and Decimation • Removal of samples is called “down-sampling” • Down-sampling by a factor N reduces the effective sampling frequency by the same factor. That is, the new sampling frequency is fs/N • To prevent aliasing, the down-sampled signal should be band-width limited to fs/2N by lowpass filtering prior to sample removal • Low-pass filtering followed by down-sampling is called “decimation” Down-Sampling a Sinusoid >> [ysin,tsin]=analog(100,1,30,8000); >> stem(ysin),title('100 Hz Sinusoid Sampled at 8 kHz') >> xlabel('Sample') >> dysin=downsample(ysin,4); >> figure,stem(dysin); >> title('100 Hz Sinusoid Sampled at 8 kHz, Down-Sampled by 4x') >> xlabel('Sample') Down-Sampling a Sinusoid 100 Hz Sinusoid Sampled at 8 kHz 1 0.8 0.6 0.4 0.2 0 -0.2 -0.4 -0.6 -0.8 -1 0 50 100 150 Sample 200 250 Down-Sampling a Sinusoid 100 Hz Sinusoid Sampled at 8 kHz, Down-Sampled by 4x 1 0.8 0.6 0.4 0.2 0 -0.2 -0.4 -0.6 -0.8 -1 0 10 20 30 40 Sample 50 60 70 Decimation • With decimation, low-pass filtering precedes down-sampling to prevent aliasing. • Example: Decimating a 100 & 1200 Hz signal by a factor of 4 with the MATLAB “decimate” command >> x=analog([100,1200],[1,1],1000,8000); >> xd4=downsample(x,4); % Effective sampling frequency is now 2000 Hz >> xdecim4=decimate(x,4); % The LP filter will have a cut-off of 0.8*(8000/8) = 800 Hz and will remove the 1200 Hz component >> subplot(3,1,1),dtft_demof(x,0,1500,2024,8000); >> title('Original Signal') >> subplot(3,1,2),dtft_demof(xd4,0,1500,2024,2000); >> title('Down-Sampled (Aliasing)') >> subplot(3,1,3),dtft_demof(xdecim4,0,1500,2024,2000); >> title('Decimated (No 1200 Hz Aliasing)') Decimation Example Original Signal 4000 2000 0 0 500 1000 1500 Hz Down-Sampled (Aliasing) 1000 500 0 0 500 1000 Hz Decimated (No 1200 Hz Aliasing) 1500 1000 500 0 0 500 1000 Hz 1500 Up-Sampling and Interpolation • The process of adding zero-valued samples between existing samples is called “upsampling” • Up-sampling by a factor N effectively increases the sampling frequency to Nfs • Estimating the values between existing samples is called “interpolation” • Interpolation is accomplished by low-pass filtering an up-sampled signal followed by an amplitude correction to restore the signal power. Down-Sampling and Up-Sampling 100 Hz + 200 Hz Signal >> [x,ts]=analog([100,200],[1,1],20,2000); % Construct a short version of the signal >> xd4=downsample(x,4); >> xu4=upsample(xd4,4); >> subplot(3,1,1),stem(x),title('Original Signal') >> subplot(3,1,2),stem(xd4),title('Down-Sampled by 4') >> subplot(3,1,3),stem(xu4),title('Down-Sampled Signal Up-Sampled by 4x') >> xlabel('Sample') Down-Sampling and Up-Sampling Original Signal 2 0 -2 0 5 10 15 20 25 30 35 40 45 Down-Sampled by 4 2 0 -2 1 2 3 4 5 6 7 8 9 10 11 Down-Sampled Signal Up-Sampled by 4x 2 0 -2 0 5 10 15 20 25 Sample 30 35 40 45 Spectra of the Down-Sampled and Up-Sampled Signals Spectrum of Initial Signal 1 0.5 0 0 100 200 300 400 500 600 700 Hz Spectrum of Down-Sampled Signal 800 900 1000 1 0.5 0 0 50 100 150 200 Hz Spectrum of 4X Zero Insertion of Down-Sampled Signal 250 0.4 0.2 0 0 100 200 300 400 500 Hz 600 700 800 900 1000 Interpolation Process • The spectrum of the up-sampled signal gives the clue for the process – Low-pass filter the up-sampled signal to remove all frequency components beyond fs/2N, where fs = effective sampling frequency after up-sampling and N is the up-sampling factor. – Multiply the result by N to restore the correct the power of the up-sampled signal • Typical filter order for the low-pass filter is 8N • This process is implemented in the MATLAB interp command, using a special symmetric FIR filter to compensate for group delay Recovery of a Down-Sampled Signal by Interpolation Filtering >> x=analog([100,200],[1,1],1000,2000); %Construct the signal >> xd4=downsample(x,4); >> xu4=upsample(xd4,4); >> n=0:32; % Begin the design of an order 8N filter LP filter >> fs=2000; >> N=4; >> cutoff=fs/(2*N); >> omega=2*pi*cutoff/fs; >> h=(omega/pi)*sinc(omega*(n-16)/pi).*hamming(33)'; % LP filter >> x_recovered=4*filter(h,1,xu4); % LP filter and multiply by N=4 >> subplot(3,1,1);stem(x(1:100)),title('Original Signal') >> subplot(3,1,2);stem(xu4(1:100)),title('Zero Insertion of DownSampled Signal') >> subplot(3,1,3);stem(x_recovered(1:100)),title('Recovered (LP Filtered) Signal') Interpolation Recovery Results Original Signal 2 0 -2 0 10 20 30 40 50 60 70 80 90 100 80 90 100 80 90 100 Zero Insertion of Down-Sampled Signal 2 0 -2 0 10 20 30 40 50 60 70 Recovered (LP Filtered) Signal 2 0 -2 0 10 20 30 40 50 60 70 Note that the group delay of the LP filter is 16 in this example Interpolation with “interp” >> x=analog([100,200],[1,1],1000,2000); %Construct the signal >> xd4=downsample(x,4); >> xu4=upsample(xd4,4); >> x_interp=interp(xd4,4); >> subplot(3,1,1),stem(x(1:100)),title('Original Signal') >> subplot(3,1,2),stem(xd4(1:25)),title('Down-Sampled Signal') >> subplot(3,1,3),stem(x_interp(1:100)),title('Recovered Signal Using "interp"') “Interp” Results Original Signal 2 0 -2 0 10 20 30 40 50 60 70 80 90 100 Down-Sampled Signal 2 0 -2 0 5 10 15 20 25 Recovered Signal Using "interp" 2 0 -2 0 10 20 30 40 50 60 70 80 90 100 Sampling Rate Conversion by Rational Factors • The sampling frequency can be changed by rational factors L/M where L is the interpolation factor and M is the decimation factor. • Rate changes (to higher or lower rates) is always done with interpolation (L) and decimation (M) in that order to prevent loss of frequency components of interest in the signal. • Example: Changing a music signal from the CD rate (44.1 kHz) to the digital tape rate (48 kHz) is accomplished by interpolation by a factor of 160 followed by decimation by a factor of 147 L M 48 44.1 480 441 160 147 Rate Conversion Example • Convert a 100 Hz sinusoidal signal sampled at 1200 Hz to a signal sampled at 1000 Hz • L/M=1000/1200 = 5/6 >> x=analog(100,1,40,1200); >> xL=interp(x,5); % The “interp” command carries out interpolation >> xLM=decimate(xL,6); % “decimate” carries out decimation >> subplot(2,1,1),stem(x),title(' Signal, fs = 1.2 kHz') >> subplot(2,1,2),stem(xLM),title('Rate Conversion 1.2 kHz to 1 kHz') >> axis([0,50,-1,1]) Rate Conversion Example Results Signal, fs = 1.2 kHz 1 0.5 0 -0.5 -1 0 5 10 15 20 25 30 35 40 45 50 40 45 50 Rate Conversion 1.2 kHz to 1 kHz 1 0.5 0 -0.5 -1 0 5 10 15 20 25 30 35 Note in both cases the signal is about 40 ms long. Over-Sampling and Random Noise • Gaussian noise power is uniformly distributed in the frequency domain • As a consequence, noise power density is reduced by a factor of 2 (3 dB) for each doubling of the sampling frequency. Power Density in the Frequency Domain P 1 2 N d 2 | X N ( ) | d 2 df fs and f fs / 2 fo r so f /2 s 1 2 2 P | X N ( f ) | df 2 N f s f s / 2 or fs / 2 P | X(f)| fs / 2 p( f ) Nfs | X(f)| Nfs 2 2 df Calculating Mean Noise Power Density for Different Sampling Frequencies >> [zero_sig,tt]=analog(1,0,1000,50000); >> analog_noise=zero_sig+randn(size(zero_sig)); >> n1000=sample(tt,analog_noise,1000); >> n2000=sample(tt,analog_noise,2000); >> n4000=sample(tt,analog_noise,4000); >> [N1,f1]=dtft_demof(n1000,0,500,512,1000); >> [N2,f2]=dtft_demof(n2000,0,1000,512,2000); >> [N4,f4]=dtft_demof(n4000,0,2000,512,4000); >> pd1=(abs(N1)).^2/(length(n1000)*1000); >> pd2=(abs(N2)).^2/(length(n2000)*2000); >> pd4=(abs(N4)).^2/(length(n4000)*4000); >> mean(pd1) >> mean(pd2) >> mean(pd4) ans = 9.9750e-004 ans = 4.8431e-004 ans = 2.5061e-004 %Construct a psuedo-analog “zero” signal % Construct a psuedo-analog noise signal % Sample the noise signal at 1 kHz, 2 kHz, and 4 kHz % Compute the DTFT for each digital noise signal % Compute the spectral power density % Compute the mean value of the spectral power density Notice than the average power density is reduced by a factor of 2 for each doubling of the sampling frequency De-Noising a Signal by Over-Sampling and Low-Pass Filtering • Over-sample a signal at a rate many times higher than the band-width of interest W • Over-sampling reduces the noise power in W by 3 dB for each doubling of the sampling frequency • Low-pass filter with a cut-off frequency near W. This eliminates the noise power at frequencies beyond W. De-Noising Example >> [asig,tt]=analog(100,1,40,40000); >> asign=asig+randn(size(asig)); >> [d8,t8]=sample(tt,asig,8000); >> [d8n,t8]=sample(tt,asign,8000); >> n=0:100; >> omega=2*pi*125/8000; >> hw=(omega/pi)*sinc(omega*(n-50)/pi).*blackman(101)'; >> d8nf=filter(hw,1,d8n); >> subplot(3,1,1),plot(t8,d8),title('Clean Signal') >> subplot(3,1,2),plot(t8,d8n),title('Noisy Signal') >> subplot(3,1,3),plot(t8,d8nf),title('Filtered Noisy Signal') >> subplot(2,1,1),fft_plot(d8n,8000);title('Noisy Signal Spectrum') >> subplot(2,1,2),fft_plot(d8nf,8000);title('Filtered Noisy Signal Spectrum') De-Noising Example Results Clean Signal 1 0 -1 0 5 10 15 20 25 30 35 40 25 30 35 40 30 35 40 Noisy Signal 5 0 -5 0 5 10 15 20 Filtered Noisy Signal 1 0 -1 0 5 10 15 20 25 De-Noising Example Results Noisy Signal Spectrum 1 Noise Power Uniformly Distributed 0.5 0 0 500 1000 1500 2000 2500 3000 Hz Filtered Noisy Signal Spectrum 3500 4000 3500 4000 0.8 0.6 Noise Power Eliminated by LP Filter 0.4 0.2 0 0 500 1000 1500 2000 Hz 2500 3000 Delta-Sigma (ΔΣ) Quantization • The processing speed of a DSP system could be measured by bits/sec in which case the speed is Nfs, where N is the number of quantization bits (ADC) and fs is the sampling frequency. • For a given system speed, the maximum fs requires quantization with one bit, which appears impossible because quantization with two levels implies impractically high quantization noise. • ΔΣ Quantization can do just that: quantize with 1 bit and still control the quantization noise. Delta-Sigma Quantizer Functional Diagram A c cu m u la to r / In te g ra to r In p u t X Q u a n tize r / C o m p a ra to r 1 -b it O u tp u t + - B (1 ,-1 ) C - +V W 1 -b it D A C -V D Delta-Sigma Quantizer Discrete-Time Model e [n ] A c c u m u la to r, H (z ) x [n ] - v [n ] y[n ]= -1 ,1 w [n ] + + Z -1 Q u an tize r Y (z) z 1 X ( z ) (1 z 1 )E (z) Output = input x delay + noise x high-pass filter (e.g, “Noise-shaping” one-bit quantization) Delta-Sigma Quantization of a Sinusoid >> [x,ts]=analog(100,2,500,10000); >> stem(ts(1:100),x(1:100)) >> title('High-Rate Sampled 100 Hz Sinusoid') >> xlabel('milliseconds') >> [x,ts]=analog(100,2,500,10000); >> stem(ts(1:100),x(1:100)) >> title('High-Rate Sampled 100 Hz Sinusoid') >> xlabel('milliseconds') >> y=deltasigma(x); % This is the delta-sigma quantizer algorithm >> figure,stem(y(1:100)); >> hold >> plot(x(1:100),'k') >> title('Delta-Sigma Quantizer Output for 100 Hz Sinusoid') >> xlabel('Output Sample') >> hold off Delta-Sigma Quantization of a Sinusoid High-Rate Sampled 100 Hz Sinusoid Delta-Sigma Quantizer Output for 100 Hz Sinusoid 2 2 1.5 1.5 1 1 0.5 0.5 0 0 -0.5 -0.5 -1 -1 -1.5 -1.5 -2 0 1 2 3 4 5 6 milliseconds 7 8 9 10 -2 0 10 20 30 40 50 60 Output Sample 70 80 90 100 Delta-Sigma Quantization of a Sinusoid – Quantization Noise Shaping Spectrum of Delta-Sigma Output Signal 2 1.8 1.6 1.4 1.2 1 0.8 0.6 0.4 0.2 0 0 500 1000 1500 2000 2500 Hz 3000 3500 4000 4500 5000 Low-pass filtering would eliminate the quantization noise Low-Pass Filtering Δ-Σ Sinusoid >> n=0:500; >> omega=2*pi*200/10000; >> h=(omega/pi)*sinc(omega*(n-250)/pi); >> hb200=h.*blackman(501)'; >> [x,ts]=analog(100,2,500,10000); >> y=deltasigma(x); % This is the delta-sigma quantizer algorithm >> y_lpf=filter(hb200,1,y); >> fft_plot(y_lpf,10000); >> title('Spectrum of Low-Pass Filtered Delta-Sigma Quantizer Output') >> figure,plot(ts(1:500),y_lpf(1:500)) >> title('Time-Domain of the Filtered Quantizer Output') >> xlabel('Milliseconds') Low-Pass Filtering Δ-Σ Sinusoids Spectrum of Low-Pass Filtered Delta-Sigma Quantizer Output Time-Domain of the Filtered Quantizer Output 2 2 1.8 1.5 1.6 1 1.4 0.5 1.2 0 1 -0.5 0.8 -1 0.6 0.4 -1.5 0.2 -2 0 0 500 1000 1500 2000 2500 Hz 3000 3500 4000 4500 5000 -2.5 Filter group delay 0 5 10 15 20 25 30 Milliseconds 35 40 45 50 Processing a Δ-Σ Signal Serial-to-N-bit Parallel Converter Delta-Sigma Quantizer Binary stream (fs) Low-Pass Filter N-bit numbers (fs/N) Decimation to Nyquist Rate Recovered Signal Continue Processing Processing a Δ-Σ Signal • The high-rate sampling frequency of the Δ-Σ quantizer is fs. • Over N samples, the bit-stream of the Δ-Σ quantizer output is the average signal value. • Serial-to-N-bit parallel conversion creates N-bit numbers equal to the average value. The effective sampling frequency is fs/N. • The N-bit numbers carry the quantization noise which is eliminated by digital LP filtering. The filtered signal represents the recovered signal. • After filtering the signal can be decimated to the Nyquist rate for further processing. Processing a Δ-Σ Signal MATLAB Simulation % Create and Delta-Sigma Quantize a Signal with 100, 200, and 300 Hz Components >> x=analog([100,200,300],[1,1,1],1000,24000); % Sampled signal >> y=deltasigma(x); % Delta-sigma quantization of the signal % % Simulate the 8-Bit Serial to Parallel Conversion of the Quantizer Stream >> y8bits=decimate_and_average(y,8); % M-file to block process the signal y in blocks of 8 % % Low-Pass Filter the 8-Bit Signal with Cutoff of 350 Hz >> n=0:100; % Start low-pass filter design >> fs=24000/8; % The signal has been effectively decimated by a factor of 8 >> omega=2*pi*350/fs; >> h=(omega/pi)*sinc(omega*(n-50)/pi).*hamming(101)'; % Windowed LP filter >> yfilt=filter(h,1,y8bits); % Low-pass filter the 8-bit re-quantized signal % % Decimate the filtered signal to the Nyquist Rate >> ydec=decimate(yfilt,4); % Decimate the filtered signal by a factor of 4 (fs = 750 Hz) Processing a Δ-Σ Signal MATLAB Simulation Signals (10 ms period) 2.5 2.5 Quanitzer output and sampled signal 8-bit samples and sampled signal 2 2 1.5 1.5 1 1 0.5 0.5 0 0 -0.5 -0.5 -1 -1 -1.5 -1.5 -2 -2 -2.5 0 1 2 3 4 5 6 7 >> t24=0:1000/24000:10; >> stem(t24(1:240),y(1:240)) >> hold %Current plot held >> plot(t24(1:240),x(1:240),'k') >> legend('Quanitzer output and sampled signal') >> hold off 8 9 10 -2.5 0 1 2 3 4 5 6 7 8 >> t3k=0:(1/3):10; >> stem(t3k(1:30),y8bits(1:30)) >> hold %Current plot held >> plot(t24(1:240),x(1:240),'k') >> legend('8-bit samples and sampled signal') >> hold off 9 10 Processing a Δ-Σ Signal MATLAB Simulation Signals (10 ms period) 2.5 2.5 Decimated final signal and sampled signal LP filtered 8-bit samples and sampled signal 2 2 1.5 1.5 1 1 0.5 0.5 0 0 -0.5 -0.5 -1 -1 -1.5 -1.5 -2 -2 -2.5 -2.5 0 1 2 3 4 5 6 7 >> stem(t3k(1:30),yfilt(81:110)) >> hold %Current plot held >> plot(t24(1:240),x(245:484),'k') >> legend('LP filtered 8-bit samples and sampled signal') >> hold off 8 9 10 0 1 2 3 4 5 6 7 8 >> tf=downsample(t3k(1:30),4); >> yfiltf=downsample(yfilt(81:110),4); >> stem(tf,yfiltf) >> hold %Current plot held >> plot(t24(1:240),x(245:484),'k') >> legend('Decimated final signal and sampled signal') >> hold off 9 10 Processing a Δ-Σ Signal MATLAB Simulation Sampled Signal Spectrum Discrete Time Fourier Transform 12000 Spectrum of the sampled signal 10000 8000 6000 4000 2000 0 0 500 1000 Hz >> dtft_demof(x,0,1500,4000,24000); % Begin generating signal spectra >> legend('Spectrum of the sampled signal') 1500 Processing a Δ-Σ Signal MATLAB Simulation Quantizer and 8-Bit Signal Spectra (Showing Quantization Noise) Discrete Time Fourier Transform Discrete Time Fourier Transform 12000 1500 Spectrum of the delta-sigma quantizer output Spectrum of the 8-bit serial-to-parallel signal 10000 8000 1000 6000 4000 500 2000 0 0 500 1000 Hz >> figure,dtft_demof(y,0,1500,4000,24000); >> legend('Spectrum of the delta-sigma quantizer output') 1500 0 0 500 1000 Hz >> figure, dtft_demof(y8bits,0,1500,4000,3000); >> legend('Spectrum of the 8-bit serial-to-parallel signal') 1500 Processing a Δ-Σ Signal MATLAB Simulation 8-Bit Signal LP Filtered and Decimated (Quantization Noise Minimized) Discrete Time Fourier Transform Discrete Time Fourier Transform 1500 400 Spectrum of the low-pass filtered 8-bit signal (recovered signal) Final signal decimated by 4 (fs = 750 Hz) 350 300 1000 250 200 150 500 100 50 0 0 500 1000 Hz >> figure, dtft_demof(yfilt,0,1500,4000,3000); >> legend('Spectrum of the low-pass filtered 8-bit signal (recovered signal)') 1500 0 0 500 1000 Hz >> figure,dtft_demof(ydec,0,1500,4000,750); >> legend('Final signal decimated by 4 (fs = 750 Hz)') 1500 Reduction in Noise due to Over-sampling and Noise Shaping a.) Quantization fs 2 Low Pass Digital Filter b.) Reduced Noise due to M-times Oversampling fs M 2 fs 2 c.) Further Reduced Noise due Noise Shaping fs 2 M fs 2 Summary • • • • • • • • The spectral content of a digital signal is replicated at integer multiples of the sampling frequency. Oversampling (sampling well beyond the Nyquist rate) spreads the frequency content over a wider frequency range. The requirements on the analog anti-aliasing filter can be relaxed by oversampling followed by digital low-pass filtering. The extra samples in an oversampled and bandwidth-limited signal can be removed by downsampling or decimation, thereby reducing the effective sampling frequency. A signal can be restored to a higher sampling frequency by the processes of upsampling and interpolation. Since Gaussian noise is uniformly distributed in the frequency domain, the combination of oversampling and filtering can effectively de-noise a signal in a bandwidth of interest. Oversampling can be maximized by delta-sigma quantization, which is quantization with one bit. Delta-sigma quantizers have the property of noise-shaping, which allows the elimination of quantization noise by low-pass filtering.