Bird
Raised Fist0
Signal Processingdata~10 mins

Time scaling (compression and expansion) in Signal Processing - Step-by-Step Execution

Choose your learning style10 modes available
Concept Flow - Time scaling (compression and expansion)
Original Signal x(t)
↓
Choose scaling factor a
↓
Apply time scaling: y(t) = x(t/a)
↓
Output scaled signal y(t)
Start with an original signal, pick a scaling factor, then create a new signal by changing the time axis. If the factor is greater than 1, the signal stretches (expands). If less than 1, it shrinks (compresses).
Execution Sample
Signal Processing
import numpy as np
import matplotlib.pyplot as plt

t = np.linspace(0, 1, 500)
x = np.sin(2 * np.pi * 5 * t)
a = 0.5

y = np.interp(t / a, t, x)
plt.plot(t, x, label='Original')
plt.plot(t, y, label='Compressed')
plt.legend()
plt.show()
This code creates a sine wave and compresses it by a factor of 0.5, then plots both original and compressed signals.
Execution Table
Stept (time)a (scale)t/a (scaled time)x(t/a) (signal value)Action
10.00.50.0 / 0.5 = 0.0sin(2π5*0.0) = 0.0Calculate scaled time and signal value
20.0020.50.002 / 0.5 = 0.004sin(2π5*0.004) ≈ 0.125Calculate scaled time and signal value
30.0040.50.004 / 0.5 = 0.008sin(2π5*0.008) ≈ 0.248Calculate scaled time and signal value
40.0060.50.006 / 0.5 = 0.012sin(2π5*0.012) ≈ 0.368Calculate scaled time and signal value
..................
5001.00.51.0 / 0.5 = 2.0sin(2π5*2.0) = sin(20π) = 0.0Calculate scaled time and signal value
ExitEnd of t arrayAll time points processed
💡 Reached end of time vector t, all scaled signal values computed.
Variable Tracker
VariableStartAfter Step 1After Step 2After Step 3...After Step 500Final
tarray from 0 to 10.00.0020.004...1.01.0
a0.50.50.50.5...0.50.5
t/aempty0.00.0040.008...2.02.0
x(t/a)empty0.00.1250.248...0.00.0
y(t)empty0.00.1250.248...0.00.0
Key Moments - 3 Insights
Why do we divide time t by the scaling factor a instead of multiplying?
Because y(t) = x(t/a), dividing t by a compresses or expands the time axis correctly. Multiplying would invert the effect. See execution_table rows where t/a is calculated.
What happens if the scaling factor a is greater than 1?
The signal stretches in time (expands). This means the signal plays slower. This is shown in the concept_flow where a > 1 leads to expansion.
Why do we use interpolation (np.interp) when computing y(t)?
Because t/a may not align exactly with original time points t, interpolation estimates signal values at these new points. This ensures smooth scaling.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table at Step 2, what is the value of t/a?
A0.008
B0.002
C0.004
D0.001
💡 Hint
Check the 't/a (scaled time)' column in execution_table row Step 2.
At which step does the scaled time t/a reach 2.0?
AStep 250
BStep 500
CStep 1000
DStep 1
💡 Hint
Look at the last row before Exit in execution_table for t/a values.
If the scaling factor a changes from 0.5 to 2, how does the signal change?
ASignal expands (plays slower)
BSignal compresses (plays faster)
CSignal amplitude doubles
DSignal frequency doubles
💡 Hint
Refer to concept_flow where a > 1 means expansion (signal stretches).
Concept Snapshot
Time scaling changes signal speed by modifying time axis.
Use y(t) = x(t/a) where a is scaling factor.
If a > 1, signal expands (slower).
If 0 < a < 1, signal compresses (faster).
Interpolation helps get values at new time points.
Simple but powerful for signal speed control.
Full Transcript
Time scaling means changing how fast or slow a signal plays by changing its time axis. We pick a scaling factor a. Then we create a new signal y(t) by looking at the original signal x at time t divided by a. If a is bigger than 1, the signal stretches and plays slower. If a is less than 1, the signal compresses and plays faster. We often use interpolation to find signal values at new time points because they may not match original points exactly. This process helps us control signal speed easily.

Practice

(1/5)
1. What happens to a signal when it is time-scaled with a factor a > 1?
easy
A. The signal is expanded and plays slower.
B. The signal amplitude increases.
C. The signal is compressed and plays faster.
D. The signal frequency decreases.

Solution

  1. Step 1: Understand time scaling factor meaning

    A factor a > 1 means the time axis is divided by a number greater than 1, making the signal shorter in time.
  2. Step 2: Effect on signal playback speed

    Shorter time means the signal plays faster, which is called compression.
  3. Final Answer:

    The signal is compressed and plays faster. -> Option C
  4. Quick Check:

    Compression (a > 1) = Faster playback [OK]
Hint: If a > 1, signal speeds up (compresses) [OK]
Common Mistakes:
  • Confusing compression with expansion
  • Thinking amplitude changes with time scaling
  • Mixing frequency effects with time scaling
2. Which of the following Python code snippets correctly applies time scaling by a factor a to a signal array x using interpolation?
easy
A. import numpy as np n = len(x) t = np.arange(n) t_new = t / a x_new = x[t_new]
B. import numpy as np n = len(x) t = np.arange(n) t_new = t * a x_new = x[t_new]
C. import numpy as np from scipy.interpolate import interp1d n = len(x) t = np.arange(n) f = interp1d(t, x) t_new = t * a x_new = f(t_new)
D. import numpy as np from scipy.interpolate import interp1d n = len(x) t = np.arange(n) f = interp1d(t, x) t_new = t / a x_new = f(t_new)

Solution

  1. Step 1: Understand time scaling formula

    Time scaling by factor a means new time points are t_new = t / a.
  2. Step 2: Use interpolation for non-integer indices

    Since t_new may be fractional, interpolation function f is used to get x_new.
  3. Final Answer:

    Code snippet A correctly applies time scaling with interpolation. -> Option D
  4. Quick Check:

    t_new = t / a with interp1d = Correct scaling [OK]
Hint: Use t_new = t / a with interpolation function [OK]
Common Mistakes:
  • Multiplying time by a instead of dividing
  • Indexing array directly with fractional indices
  • Forgetting to import interp1d
3. Given the code below, what is the length of the output signal x_scaled?
import numpy as np
from scipy.interpolate import interp1d
x = np.array([1, 2, 3, 4, 5])
a = 0.5
n = len(x)
t = np.arange(n)
f = interp1d(t, x, kind='linear', fill_value='extrapolate')
t_new = t / a
x_scaled = f(t_new)
medium
A. 5
B. 10
C. 3
D. 7

Solution

  1. Step 1: Check length of t_new

    Variable t_new is computed as t / a, but t has length 5, so t_new also has length 5.
  2. Step 2: Interpolation output length

    Interpolating at 5 points returns an array x_scaled of length 5.
  3. Final Answer:

    5 -> Option A
  4. Quick Check:

    Length of t_new = length of x_scaled = 5 [OK]
Hint: Output length matches length of t_new array [OK]
Common Mistakes:
  • Assuming output length changes with scaling factor
  • Confusing scaling factor with output size
  • Ignoring that t_new length equals original length
4. Identify the error in the following code that attempts to expand a signal by a factor of 2:
import numpy as np
from scipy.interpolate import interp1d
x = np.array([10, 20, 30, 40])
a = 2
n = len(x)
t = np.arange(n)
f = interp1d(t, x)
t_new = t * a
x_expanded = f(t_new)
medium
A. Using integer array t instead of float array.
B. Using t * a instead of t / a for time scaling.
C. Using interp1d without sorting t.
D. Not specifying fill_value in interp1d causes error.

Solution

  1. Step 1: Recall time scaling formula

    To expand (slow down) a signal by factor 2, new time points should be t_new = t / a, not t * a.
  2. Step 2: Effect of incorrect scaling

    Using t * a compresses the signal instead of expanding it, causing wrong output.
  3. Final Answer:

    Using t * a instead of t / a for time scaling. -> Option B
  4. Quick Check:

    Expansion requires t_new = t / a [OK]
Hint: Use t_new = t / a for expansion, not t * a [OK]
Common Mistakes:
  • Multiplying time by a instead of dividing
  • Ignoring interpolation domain limits
  • Not handling extrapolation in interp1d
5. You have a signal sampled at 1000 Hz with 1000 samples. You want to create a time-scaled version that plays twice as slow (expansion). Which of the following code snippets correctly computes the new signal x_expanded with proper interpolation and new sampling points?
hard
A. import numpy as np from scipy.interpolate import interp1d x = original_signal fs = 1000 n = len(x) t = np.arange(n) / fs f = interp1d(t, x, kind='cubic', fill_value='extrapolate') t_new = np.arange(0, t[-1]*2, 1/fs) x_expanded = f(t_new)
B. import numpy as np from scipy.interpolate import interp1d x = original_signal fs = 1000 n = len(x) t = np.arange(n) / fs f = interp1d(t, x, kind='linear') t_new = np.arange(0, t[-1]/2, 1/fs) x_expanded = f(t_new)
C. import numpy as np from scipy.interpolate import interp1d x = original_signal fs = 1000 n = len(x) t = np.arange(n) / fs f = interp1d(t, x) t_new = np.arange(0, t[-1]*2, 2/fs) x_expanded = f(t_new)
D. import numpy as np from scipy.interpolate import interp1d x = original_signal fs = 1000 n = len(x) t = np.arange(n) / fs f = interp1d(t, x, kind='cubic') t_new = np.arange(0, t[-1]*0.5, 1/fs) x_expanded = f(t_new)

Solution

  1. Step 1: Understand expansion by factor 2

    Playing twice as slow means the signal duration doubles, so new time axis goes from 0 to t[-1]*2.
  2. Step 2: Create new time points at original sampling rate

    New time points should be spaced by 1/fs to keep sampling rate consistent.
  3. Step 3: Use interpolation with extrapolation

    Interpolation function with cubic method and fill_value='extrapolate' handles points beyond original range.
  4. Final Answer:

    Code snippet A correctly computes the expanded signal. -> Option A
  5. Quick Check:

    Expansion doubles duration with proper interpolation [OK]
Hint: Double time axis length, keep sampling interval, interpolate [OK]
Common Mistakes:
  • Reducing time axis length instead of expanding
  • Changing sampling interval incorrectly
  • Not handling extrapolation in interpolation
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