Complete the code to compress the signal by a factor of 2 using slicing.
compressed_signal = original_signal[::[1]]Using a step of 2 in slicing selects every second sample, effectively compressing the signal by 2.
Complete the code to expand the signal by inserting zeros between samples.
expanded_signal = np.zeros(len(original_signal) * [1]) expanded_signal[::[1]] = original_signal
Expanding by a factor of 2 means the new signal length doubles and original samples are placed every 2 positions.
Fix the error in the code to correctly compress the signal by a factor of 3.
compressed_signal = original_signal[::[1]]Slicing step must be an integer greater than zero. Using 3 selects every third sample, compressing the signal by 3.
Fill both blanks to create a dictionary of signal lengths after compression and expansion.
lengths = {'compressed': len(signal) [1] factor, 'expanded': len(signal) [2] factor}Compression reduces length by dividing by factor, expansion increases length by multiplying by factor.
Fill all three blanks to create a time-scaled signal using interpolation for expansion.
from scipy.interpolate import interp1d x_original = np.arange(len(signal)) new_length = int(len(signal) * [1]) x_new = np.linspace(0, len(signal) - 1, [2]) interpolator = interp1d(x_original, signal, kind='linear') scaled_signal = interpolator([3])
New length is original length times scaling factor. x_new is linspace with new_length points. Interpolator uses x_new to create scaled signal.
