Which statement correctly describes the main difference between fixed-point and floating-point number representations in embedded DSP?
Think about how the decimal point is handled in fixed-point versus floating-point formats.
Fixed-point numbers have a fixed position for the decimal point, meaning the number of digits after it is constant. Floating-point numbers can shift the decimal point, allowing a wider dynamic range.
What is the output of the following fixed-point multiplication simulation code?
def fixed_point_multiply(a, b, fractional_bits=8): product = (a * b) >> fractional_bits return product # Inputs are fixed-point numbers with 8 fractional bits x = 300 # represents 1.171875 (300/256) y = 512 # represents 2.0 (512/256) result = fixed_point_multiply(x, y) print(result)
Remember to shift right by the number of fractional bits after multiplication.
Multiplying 300 by 512 gives 153600. Shifting right by 8 bits (dividing by 256) results in 600.
Given 16-bit signed fixed-point numbers with 12 fractional bits, what is the output of the following code that adds two numbers and detects overflow?
def fixed_point_add(a, b, total_bits=16, fractional_bits=12): max_val = (1 << (total_bits - 1)) - 1 min_val = -(1 << (total_bits - 1)) result = a + b overflow = False if result > max_val or result < min_val: overflow = True # Saturate result result = max_val if result > max_val else min_val return result, overflow # Inputs num1 = 2048 # 0.5 in Q4.12 format (2048/4096) num2 = 4096 # 1.0 in Q4.12 format (4096/4096) res, ovf = fixed_point_add(num1, num2) print(res, ovf)
Check if the sum exceeds the 16-bit signed integer range.
The sum is 2048 + 4096 = 6144, which is within the 16-bit signed range (-32768 to 32767), so no overflow occurs.
Which plot best represents the quantization error when converting a sine wave from floating-point to 8-bit fixed-point representation?
import numpy as np import matplotlib.pyplot as plt # Generate sine wave x = np.linspace(0, 2 * np.pi, 100) sine_wave = np.sin(x) # Convert to 8-bit fixed-point (Q0.7 format) fixed_point = np.round(sine_wave * 127) / 127 # Calculate quantization error error = sine_wave - fixed_point plt.figure(figsize=(8,4)) plt.plot(x, error, label='Quantization Error') plt.axhline(0, color='black', linewidth=0.5) plt.title('Quantization Error of Sine Wave in 8-bit Fixed-Point') plt.xlabel('Angle (radians)') plt.ylabel('Error') plt.legend() plt.grid(True) plt.show()
Think about how rounding affects the error values in fixed-point conversion.
The quantization error shows discrete jumps because fixed-point rounding maps continuous values to discrete levels, creating a stair-step error pattern.
Given the following fixed-point DSP filter code, which option correctly identifies the cause of overflow during execution?
def fixed_point_filter(input_signal, coeff, fractional_bits=15): acc = 0 for x, c in zip(input_signal, coeff): acc += (x * c) >> fractional_bits # Saturate to 16-bit signed if acc > 32767: acc = 32767 elif acc < -32768: acc = -32768 return acc input_signal = [30000, 30000, 30000] coeff = [16384, 16384, 16384] # 0.5 in Q1.15 format output = fixed_point_filter(input_signal, coeff) print(output)
Consider the size of 'acc' and the range of intermediate multiplication results.
The accumulator 'acc' is a standard integer and can overflow because the sum of multiple large intermediate products exceeds 16-bit range before saturation.
