Bird
Raised Fist0
Signal Processingdata~10 mins

Sample rate conversion basics in Signal Processing - Step-by-Step Execution

Choose your learning style10 modes available
Concept Flow - Sample rate conversion basics
Start with original signal
↓
Upsample: Insert zeros between samples
↓
Apply low-pass filter
↓
Downsample: Keep every M-th sample
↓
Output: Signal at new sample rate
Sample rate conversion changes how often we measure a signal by first increasing samples, filtering, then reducing samples.
Execution Sample
Signal Processing
import numpy as np
x = np.array([1, 2, 3, 4])
upsampled = np.zeros(8)
upsampled[::2] = x
filtered = np.convolve(upsampled, [0.5, 0.5], mode='same')
downsampled = filtered[::2]
This code upsamples a signal by 2, applies a simple filter, then downsamples by 2.
Execution Table
StepVariableValue/ActionExplanation
1x[1, 2, 3, 4]Original signal samples
2upsampled[1, 0, 2, 0, 3, 0, 4, 0]Inserted zeros between original samples
3filtered[0.5, 0.5, 1.0, 1.0, 1.5, 1.5, 2.0, 2.0]Applied low-pass filter (simple average)
4downsampled[0.5, 1.0, 1.5, 2.0]Kept every 2nd sample after filtering
💡 Downsampling done, output signal has new sample rate with filtered values.
Variable Tracker
VariableStartAfter Step 2After Step 3After Step 4
x[1, 2, 3, 4][1, 2, 3, 4][1, 2, 3, 4][1, 2, 3, 4]
upsampledN/A[1, 0, 2, 0, 3, 0, 4, 0][1, 0, 2, 0, 3, 0, 4, 0][1, 0, 2, 0, 3, 0, 4, 0]
filteredN/AN/A[0.5, 0.5, 1.0, 1.0, 1.5, 1.5, 2.0, 2.0][0.5, 0.5, 1.0, 1.0, 1.5, 1.5, 2.0, 2.0]
downsampledN/AN/AN/A[0.5, 1.0, 1.5, 2.0]
Key Moments - 3 Insights
Why do we insert zeros during upsampling instead of just repeating samples?
Inserting zeros increases the sample rate without changing the original data points. Repeating samples would distort the signal by creating artificial plateaus. See execution_table step 2 where zeros are inserted.
Why is filtering necessary after upsampling before downsampling?
Filtering removes unwanted high-frequency components (images) created by zero insertion. Without filtering, downsampling would cause distortion. This is shown in execution_table step 3 where filtering smooths the signal.
What happens if we downsample before filtering?
Downsampling before filtering causes aliasing, meaning high frequencies fold into lower ones, distorting the signal. The correct order is upsample -> filter -> downsample as shown in the flow and execution_table.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table at step 2. What is the value of the upsampled signal at index 3?
A0
B2
C3
D1
💡 Hint
Check the 'upsampled' row at step 2 in execution_table.
At which step does the signal get smoothed by the filter?
AStep 1
BStep 2
CStep 3
DStep 4
💡 Hint
Look for filtering action in execution_table step 3.
If we skip filtering, what would likely happen to the downsampled signal?
AIt would be unchanged
BIt would have aliasing distortion
CIt would have more samples
DIt would be zero
💡 Hint
Refer to key_moments about filtering importance.
Concept Snapshot
Sample rate conversion changes signal speed by:
1. Upsampling: insert zeros between samples
2. Filtering: smooth to remove artifacts
3. Downsampling: keep every M-th sample
Always filter after upsampling to avoid distortion.
Full Transcript
Sample rate conversion basics involve changing how often a signal is sampled. First, we insert zeros between original samples to increase the sample rate. Then, we apply a low-pass filter to smooth the signal and remove unwanted high-frequency artifacts caused by zero insertion. Finally, we downsample by keeping every M-th sample to reduce the sample rate to the desired level. This process prevents distortion and aliasing, ensuring the output signal maintains quality at the new sample rate.

Practice

(1/5)
1. What does sample rate conversion do in signal processing?
easy
A. Changes how often a signal is measured
B. Changes the signal's amplitude
C. Changes the signal's frequency content
D. Changes the signal's phase

Solution

  1. Step 1: Understand sample rate meaning

    Sample rate is how many times per second a signal is measured or sampled.
  2. Step 2: Define sample rate conversion

    Sample rate conversion changes this measurement rate, either increasing or decreasing it.
  3. Final Answer:

    Changes how often a signal is measured -> Option A
  4. Quick Check:

    Sample rate conversion = Changes measurement rate [OK]
Hint: Sample rate conversion changes measurement frequency [OK]
Common Mistakes:
  • Confusing sample rate with signal amplitude
  • Thinking it changes signal frequency content
  • Mixing phase changes with sample rate changes
2. Which of the following is the correct Python syntax to upsample a signal by a factor of 2 using scipy.signal.resample_poly?
easy
A. resample_poly(signal, up=1, down=2)
B. resample_poly(signal, up=2, down=1)
C. resample_poly(signal, rate=2)
D. resample_poly(signal, down=2)

Solution

  1. Step 1: Recall resample_poly parameters

    The function uses 'up' to increase sample rate and 'down' to decrease it.
  2. Step 2: Identify upsampling by 2

    To upsample by 2, set up=2 and down=1 to keep original rate multiplied by 2.
  3. Final Answer:

    resample_poly(signal, up=2, down=1) -> Option B
  4. Quick Check:

    Upsample factor = up=2, down=1 [OK]
Hint: Upsample means up>down, so up=2, down=1 [OK]
Common Mistakes:
  • Swapping up and down values
  • Omitting required parameters
  • Using only up or down without the other
3. Given a signal sampled at 1000 Hz, what will be the new sample rate after applying resample_poly(signal, up=3, down=2)?
medium
A. 1500 Hz
B. 2000 Hz
C. 500 Hz
D. 3000 Hz

Solution

  1. Step 1: Understand resample_poly rate change

    The new sample rate = original rate * (up / down).
  2. Step 2: Calculate new sample rate

    1000 Hz * (3 / 2) = 1500 Hz.
  3. Final Answer:

    1500 Hz -> Option A
  4. Quick Check:

    1000 * 3/2 = 1500 Hz [OK]
Hint: Multiply original rate by up/down ratio [OK]
Common Mistakes:
  • Multiplying by down/up instead of up/down
  • Forgetting to multiply by original rate
  • Confusing sample rate with signal length
4. What is wrong with this code snippet for downsampling a signal by 4?
from scipy.signal import resample_poly
new_signal = resample_poly(signal, up=1, down=4)
medium
A. It will cause a syntax error due to missing import
B. The up parameter should be 4, not 1
C. It may cause aliasing without proper filtering
D. The down parameter should be 1, not 4

Solution

  1. Step 1: Check code correctness

    The code syntax is correct and imports resample_poly properly.
  2. Step 2: Understand downsampling risks

    Downsampling by 4 reduces sample rate, which can cause aliasing if signal is not filtered.
  3. Final Answer:

    It may cause aliasing without proper filtering -> Option C
  4. Quick Check:

    Downsampling needs filtering to avoid aliasing [OK]
Hint: Downsampling needs filtering to prevent aliasing [OK]
Common Mistakes:
  • Assuming code syntax error
  • Confusing up and down parameters
  • Ignoring aliasing effects
5. You have a 44100 Hz audio signal and want to convert it to 16000 Hz for a speech recognition system. Which combination of up and down factors correctly resamples the signal using resample_poly?
hard
A. up=1600, down=441
B. up=44100, down=16000
C. up=160, down=4410
D. up=160, down=441

Solution

  1. Step 1: Calculate ratio for resampling

    The ratio is new_rate / old_rate = 16000 / 44100 ≈ 0.3628.
  2. Step 2: Find integer up/down factors

    Scaling both by 1000 gives up=160, down=441, which approximates the ratio well.
  3. Final Answer:

    up=160, down=441 -> Option D
  4. Quick Check:

    160/441 ≈ 0.3628 matches 16000/44100 [OK]
Hint: Simplify ratio new_rate/old_rate to small integers [OK]
Common Mistakes:
  • Using raw sample rates as up/down without simplification
  • Swapping up and down values
  • Choosing factors that don't approximate ratio
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard