Time scaling changes how fast or slow a signal plays. It helps us listen to sounds faster or slower without changing the pitch.
Time scaling (compression and expansion) in Signal Processing
y[n] = x[round(n / a)] where: - x is the original signal - y is the time-scaled signal - a is the scaling factor (>1 compresses, <1 expands) - n is the sample index
The scaling factor 'a' controls speed: greater than 1 means faster (compression), less than 1 means slower (expansion).
Rounding is used to pick the closest sample from the original signal.
a = 2 # Compress signal by 2 times (speed up) y[n] = x[round(n / 2)]
a = 0.5 # Expand signal by 2 times (slow down) y[n] = x[round(n / 0.5)] = x[round(2 * n)]
This code creates a sine wave and then compresses it by a factor of 2, making it play twice as fast. The plot shows both the original and the compressed signals.
import numpy as np import matplotlib.pyplot as plt # Original signal: simple sine wave fs = 1000 # samples per second f = 5 # frequency in Hz t = np.linspace(0, 1, fs, endpoint=False) x = np.sin(2 * np.pi * f * t) # Time scaling factor a = 2 # compress by 2 (speed up) # Calculate new length new_length = int(len(x) / a) # Create new time-scaled signal indices = np.round(np.arange(new_length) / a).astype(int) indices = np.clip(indices, 0, len(x) - 1) # avoid out of bounds y = x[indices] # Plot original and scaled signals plt.figure(figsize=(10, 4)) plt.plot(t, x, label='Original Signal') plt.plot(np.linspace(0, 1, new_length, endpoint=False), y, label='Time-Scaled Signal (compressed)') plt.legend() plt.title('Time Scaling: Compression by factor 2') plt.xlabel('Time [seconds]') plt.ylabel('Amplitude') plt.tight_layout() plt.show()
Time scaling by simple indexing can cause distortion or aliasing; more advanced methods use interpolation.
When expanding, the signal length increases; when compressing, it decreases.
Time scaling changes signal speed without changing pitch.
Compression speeds up the signal; expansion slows it down.
Use the scaling factor to control how much to speed up or slow down.
Practice
a > 1?Solution
Step 1: Understand time scaling factor meaning
A factora > 1means the time axis is divided by a number greater than 1, making the signal shorter in time.Step 2: Effect on signal playback speed
Shorter time means the signal plays faster, which is called compression.Final Answer:
The signal is compressed and plays faster. -> Option CQuick Check:
Compression (a > 1) = Faster playback [OK]
- Confusing compression with expansion
- Thinking amplitude changes with time scaling
- Mixing frequency effects with time scaling
a to a signal array x using interpolation?Solution
Step 1: Understand time scaling formula
Time scaling by factorameans new time points aret_new = t / a.Step 2: Use interpolation for non-integer indices
Sincet_newmay be fractional, interpolation functionfis used to getx_new.Final Answer:
Code snippet A correctly applies time scaling with interpolation. -> Option DQuick Check:
t_new = t / a with interp1d = Correct scaling [OK]
- Multiplying time by a instead of dividing
- Indexing array directly with fractional indices
- Forgetting to import interp1d
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)
Solution
Step 1: Check length of t_new
Variablet_newis computed ast / a, butthas length 5, sot_newalso has length 5.Step 2: Interpolation output length
Interpolating at 5 points returns an arrayx_scaledof length 5.Final Answer:
5 -> Option AQuick Check:
Length of t_new = length of x_scaled = 5 [OK]
- Assuming output length changes with scaling factor
- Confusing scaling factor with output size
- Ignoring that t_new length equals original length
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)
Solution
Step 1: Recall time scaling formula
To expand (slow down) a signal by factor 2, new time points should bet_new = t / a, nott * a.Step 2: Effect of incorrect scaling
Usingt * acompresses the signal instead of expanding it, causing wrong output.Final Answer:
Using t * a instead of t / a for time scaling. -> Option BQuick Check:
Expansion requires t_new = t / a [OK]
- Multiplying time by a instead of dividing
- Ignoring interpolation domain limits
- Not handling extrapolation in interp1d
x_expanded with proper interpolation and new sampling points?Solution
Step 1: Understand expansion by factor 2
Playing twice as slow means the signal duration doubles, so new time axis goes from 0 tot[-1]*2.Step 2: Create new time points at original sampling rate
New time points should be spaced by1/fsto keep sampling rate consistent.Step 3: Use interpolation with extrapolation
Interpolation function with cubic method andfill_value='extrapolate'handles points beyond original range.Final Answer:
Code snippet A correctly computes the expanded signal. -> Option AQuick Check:
Expansion doubles duration with proper interpolation [OK]
- Reducing time axis length instead of expanding
- Changing sampling interval incorrectly
- Not handling extrapolation in interpolation
Ready to prove it?
Pass the test and this pattern moves unknown
