Upsampling and Downsampling
Total Page:16
File Type:pdf, Size:1020Kb
Multirate Signal Processing* Tutorial using MATLAB** By, Deborah Goshorn [email protected] I. Signal processing background II. Downsample Example III. Upsample Example * Multrate signal processing is used for the practical applications in signal processing to save costs, processing time, and many other practical reasons. ** MATLAB is an industry standard software which performed all computations and corresponding figures in this tutorial I. Signal processing background Receive an analog signal • Receive an analog signal at 5 Hz (as pictured below left, there are 5 wave cycles in one second.) • The highest frequency component (5 Hz) of the signal is called the signal’s bandwidth, BW, since in the examples in this presentation, the minimum frequency component is 0Hz. • This signal can be represented in two ways: 1 600 500 0.5 400 Peak signal 0 300 strength at 5 Hz SignalValue -0.5 200 SignalStrength 100 -1 0 0.2 0.4 0.6 0.8 1 0 Time (sec) 0 BW 5 10 15 20 25 Frequency (Hz) time representation (sec) frequency representation (Hz) Add high frequency components 1. Original 5 Hz signal BW = 5 Hz Adding high frequency 600 components 2 500 creates 2. Add a 1.5 400 jagged 10 Hz 1 300 edges in 0.5 component 200 0 SignalStrength the original SignalValue 600 1 100 BW = 10 Hz -0.5 5 Hz signal. 5000 -1 0 5 10 15 20 25 0.5 Frequency (Hz) 0 0.2 0.4 0.6 0.8 1 Time (sec) 400 600 0 3 300 500 3. ThenSignalValue add 2 200 -0.5 400 a 15 Hz SignalStrength 1 300100 component!-1 SignalValue 0 200 0 0 0.2 0.4 0.6 0.8 1 SignalStrength Time (sec) 0 5 10 15 20 25 100 Frequency (Hz) BW = 15 Hz -1 0 0 0.2 0.4 0.6 0.8 1 0 5 10 15 20 25 Time (sec) Frequency (Hz) Sampling the signal: Nyquist Rate • In order to sample the signal without losing information, use a sampling rate (SR) of at least the Nyquist Rate (NR), which is 2 x BW of the received analog signal. 600 500 400 300 SignalStrength 200 Signal Nyquist Rate NR bandwidth = 2 x 15Hz 100 BW = 15 Hz = 30 Hz 0 0 5 10 15 20 25 30 35 Frequency (Hz) RULE: Sampling Rate SR ≥ Nyquist Rate NR Sampling the signal: Nyquist Rate Since Bandwidth BW = 15 Hz, the Nyquist Rate NR = 2 x 15Hz = 30Hz. RULE #1: Sampling Rate SR ≥ Nyquist Rate NR 200 3 2 150 1 100 Signal SignalValue 0 SignalStrength bandwidth 50 BW = 15 Hz Sample Rate SR = 40 Hz -1 0 0 0.2 0.4 0.6 0.8 1 0 5 10 15 20 25 30 35 40 Time (sec) Frequency (Hz) Let Sample Rate S = 40 Hz, R Nyquist Rate so sample signal every 0.025 sec (25 milliseconds). NR = 30 Hz Sampling the signal: Nyquist Freq • The Nyquist Frequency (NF) is equal to half of the sampling rate (SR). The NF must be equal to or greater than the bandwidth BW of the desired signal to reconstruct. Rule #2: Nyquist Frequency200 NF ≥ Bandwidth BW 150 100 SignalStrength 50 Nyquist Freq NF Signal = 40/2 0 bandwidth0 5 10 = 2015 Hz20 25 30 35 40 BW = 15 Hz Frequency (Hz) Sample Rate SR = 40 Hz II. Downsample Example Recall, our original signal at 5Hz… 1. Original 5 Hz signal BW = 5 Hz 2. We added 10 & 15 Hz components! BW = 15 Hz 1 600 500 0.5 400 600 200 0 3 3 300 3. Then we 500 2 SignalValue 2 150 200 -0.5 400 sampled at SignalStrength 1 1 300100 100 SR1 = 40Hz-1 SignalValue 0 SignalValue 200 0 0 SignalStrength 0 0.2 0.4 0.6 0.8 1 SignalStrength 50 Time (sec) 0 5 10 15 20 25 -1 100 Frequency (Hz) BW = 15 Hz -1 0 0 0.2 0.4 0.6 0.8 1 0 0 5 10 15 20 25 0 0.2 0.4 Time0.6 (sec)0.8 1 0 5 10 15 20 25Frequency (Hz) Time (sec) Frequency (Hz) Resample the sampled signal: downsampling Downsample by 4 means to retain only every 4th sample 3 2 4 1 SignalValue 0 -1 0 0.2 0.4 0.6 0.8 1 3 Time (sec) Sample Rate 1 S = 40Hz2 R1 Sample Rate 2 SR2 = 10 Hz 1 N = 20Hz > 15HzSignalValue 0 = BW F1 NF2 = 5Hz < 15Hz = BW -1 0 0.2 0.4 0.6 0.8 1 GOOD! Time (sec) BAD! Nyquist Freq < Bandwidth Cannot recover original signal bandwidth, since new Nyquist Frequency (5Hz) is less than the desired signal bandwdidth BW (15Hz). NF2 < BW means we cannot recover 15Hz BW signal 200 150 100 Signal Nyquist Freq 1 Nyquist Freq 2 SignalStrength 50 bandwidth NF1 = 40/2 NF2 = 10/2 = 5 Hz BW = 15 Hz = 20 Hz 0 0 5 10 15 20 25 30 35 40 Frequency (Hz) Is the original 5Hz signal recoverable? It should be, since NF2 ≥ BW 5 Hz Why 5Hz signal not recoverable: High Frequency band causes aliasing when downsampled Will wrap down to 0Hz 200 150 Nyquist Freq 1 NF1 = 40/2 Nyquist Freq 2 Signal = 20 Hz bandwidth NF2 = 10/2 100 = 5 Hz BW = 15 Hz SignalStrength 50 High 0 0 5 10 15 20 25 30 35 40 frequency Frequency (Hz) band NF2 NF1 High frequency band will wrap down to 0Hz when downsampled Why 5Hz signal not recoverable: Aliasing Effects Due to the high frequency components at 10Hz and 15Hz that show up at 0Hz when the signal is downsampled, the 5Hz component is not recoverable. 180 3 160 140 Recovered 5Hz 2 component 120 1 100 80 SignalValue 0 SignalStrength 60 Aliasing effects: high -1 40 frequency components 20 wrapped around to 0Hz! 0 0.2 0.4 0.6 0.8 1 Time (sec) 0 0 5 10 15 20 25 30 35 40 Frequency (Hz) SR2 = 10 Hz … unless we remove the high frequency components before downsampling. How to Remove the High Frequency components before downsampling using a low-pass filter • A low-pass filter (LPF) removes high frequency components by only letting low frequency components pass through. 200 100 80 60 LPF 150 40 SignalStrength 20 0 100 0 5 10 15 20 25 30 35 40 Frequency (Hz) It removes the jagged edges that were due to high frequencies. SignalStrength 50 3 1 2 0 0 5 10 0.5 15 20 25 30 35 40 1 Frequency (Hz) LPF 0 SignalValue 0 SignalValue -0.5 -1 -1 4 4.2 4.4 4.6 4.8 5 0 0.2 0.4 0.6 0.8 1 Time (sec) Time (sec) Proof in the pudding: No more aliasing effects when using low pass filter! 5 200 4 3 LPF 150 4 2 SignalStrength 1 100 0 0 5 10 15 20 25 30 35 40 Frequency (Hz) S = 40 Hz SignalStrength 50 R1 SR2 = 10 Hz 0 0 5 10 15 20 25 30 35 40 Frequency (Hz) The original 5Hz signal is successfully recovered! Proof in the pudding: LPF+downsampling <==> multirate polyphase filter resampling Sample Rate 2 S = 10 Hz 5 R2 4 LPF 4 3 200 2 SignalStrength 1 150 0 0 5 10 15 20 25 30 35 40 Frequency (Hz) 100 MATLAB’S* Sample Rate 2 SR2 = 10 Hz PolyphaseSignalStrength 50-filter Implemented Sample Rate 1 Resample (0by 1/4) SR1 = 40 Hz 0 5 10 15 20 25 30 35 40 Function Frequency (Hz) * MATLAB is an industry standard software which performed all computations and corresponding figures in this presentation III. Upsampling example Assume our original signal at 5Hz… 1. Original 5 Hz signal BW = 5 Hz Nyquist Rate NR = 2 x BW 5Hz = 10Hz, so sample at sampling rate SR = 15Hz 1 600 250 1 500 0.5 200 2. We sample 0.5 400 150 0 at S = 15Hz 0 300 R1 100 SignalValue SignalStrength SignalValue 200 -0.5 -0.5 SignalStrength 50 BW 100 = 5Hz -1 0 -1 0 5 10 15 20 25 0 0.2 0.4 0.6 0.8 1 Frequency (Hz) 0 0.2 0.4 0.6 0.8 Time1 (sec) 0 Time (sec) 0 5 10 15 20 25 Frequency (Hz) Resample the sampled signal: upsampling If you need to increase the number of samples in a given time by a factor of 5, you upsample by 5 (insert 5-1=4 zeros between each sample). 0.2 sec 0.2 sec 1 0.5 0 5 SignalValue 1 -0.5 0.5 -1 0 0 0.05 0.1 0.15 0.2 SignalValue -0.5 Time (sec) -1 Sample Rate 1 0 0.2 0.4 0.6 0.8 1 Sample Rate 2 Time (sec) SR1 = 15 Hz SR2 = 75 Hz Upsampled signal in frequency representation 0.2 sec 0.2 sec 1 0.5 Sample Rate 1 Sample Rate 2 S0R2 = 75 Hz SR1 = 15 Hz 5 120 Oops! 250 SignalValue 1 -0.5100 200 0.5 80 -1 150 0 60 0 0.05 0.1 0.15 0.2 SignalValue -0.5 Time (sec) 100 SignalStrength 40 -1 SignalStrength 0 0.2 0.4 0.6 0.8 1 50 Time (sec) 20 0 0 0 5 10 15 20 25 30 35 40 0 5 10 15 20 25 30 35 40 Frequency (Hz) Frequency (Hz) Upsampling causes aliasing in higher frequencies Upsampling causes copies of the original 5Hz component at multiples of original sampling rate, 15Hz, plus/minus 5Hz Mirror Images at: 15 – 5 = 10 Hz 15 + 5 = 20 Hz 2*15 - 5 = 25 Hz 2*15 + 15 = 35 Hz 5 … 120 250 100 Signal 200 bandwidth 80 BW = 5 Hz 150 60 100 SignalStrength Signal 40 SignalStrength Sample Rate 1 bandwidth 50 SR1 = 15 Hz BW = 5 Hz20 0 0 0 5 10 15 20 25 30 35 40 0 5 10 15 20 25 30 35 40 FrequencyHow (Hz)do we remove these extra high frequency components?Frequency (Hz) How to remove the extra high frequency components caused by upsampling using a low-pass filter 8 6 4 LPF SignalStrength 2 120 100 0 0 5 10 15 20 25 30 35 40 Frequency (Hz) 80 60 SignalStrength 40 Low pass filter removes these extra high frequency20 components 0 0 5 10 15 20 25 30 35 40 Frequency (Hz) Proof in the pudding: No more aliasing effects when using low pass filter! 8 6 5 LPF 4 SignalStrength 2 250 0 0 5 10 15 20 25 30 35 40 200S = 40 Hz R1 SFrequencyR2 = 10 (Hz) Hz 150 100 SignalStrength 50 All high frequency copies of the 5Hz signal are removed! 0 0 5 10 15 20 25 30 35 40 Frequency (Hz) Proof in the pudding: upsampling and lowpass filter <==> multirate polyphase filter resampling 8 Sample Rate 2 SR2 = 75 Hz 6 4 250 5 LPF SignalStrength 2 200 150 0 0 5 10 15 20 25 30 35 40 Frequency (Hz) 100 500 SignalStrength 50 Sample Rate 2 400 S = 75 Hz MATLAB’S* R2 0 0 5 10 15 20 25 30 35 40 300 Frequency (Hz) Polyphase-filter Implemented 200 Sample Rate 1 Resample (by 5) SignalStrength S = 15 Hz R1 Function 100 0 0 5 10 15 20 25 30 35 40 * MATLAB is an industry standard software which performed all Frequency (Hz) computations and corresponding figures in this presentation.