Bird
Raised Fist0
Signal Processingdata~30 mins

Sample rate conversion basics in Signal Processing - Mini Project: Build & Apply

Choose your learning style10 modes available
Sample Rate Conversion Basics
📖 Scenario: Imagine you have a simple audio signal recorded at a certain speed (sample rate). You want to change this speed to a different one to match another device or software. This process is called sample rate conversion.In this project, you will work with a small list of audio samples and learn how to convert the sample rate by picking samples at a new rate.
🎯 Goal: You will create a list of audio samples, set a new sample rate factor, apply simple sample rate conversion by selecting samples at intervals, and finally print the converted samples.
📋 What You'll Learn
Create a list called audio_samples with exact values: 0.0, 0.5, 1.0, 0.5, 0.0, -0.5, -1.0, -0.5
Create a variable called conversion_factor and set it to 2
Use a list comprehension to create a new list called converted_samples by selecting every conversion_factor-th sample from audio_samples
Print the converted_samples list
💡 Why This Matters
🌍 Real World
Sample rate conversion is used when audio or sensor data recorded at one speed needs to be played or processed at another speed, such as matching audio devices or preparing data for analysis.
💼 Career
Understanding sample rate conversion basics is important for roles in audio engineering, signal processing, and data science involving time series or sensor data.
Progress0 / 4 steps
1
Create the audio samples list
Create a list called audio_samples with these exact values in order: 0.0, 0.5, 1.0, 0.5, 0.0, -0.5, -1.0, -0.5
Signal Processing
Hint

Use square brackets [] to create a list and separate values with commas.

2
Set the sample rate conversion factor
Create a variable called conversion_factor and set it to the integer 2
Signal Processing
Hint

Use the equals sign = to assign the value 2 to conversion_factor.

3
Apply sample rate conversion using list comprehension
Use a list comprehension to create a new list called converted_samples by selecting every conversion_factor-th sample from audio_samples. Use range() with a step of conversion_factor to pick indexes.
Signal Processing
Hint

Use range(0, len(audio_samples), conversion_factor) to get indexes stepping by conversion_factor.

4
Print the converted samples
Print the list converted_samples to see the result of the sample rate conversion.
Signal Processing
Hint

Use print(converted_samples) to display the new list.

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