Challenge - 5 Problems
Filtering Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediateOutput of a simple moving average filter
What is the output of the following MATLAB code that applies a moving average filter to a signal?
MATLAB
x = [1 2 3 4 5]; windowSize = 3; b = (1/windowSize)*ones(1,windowSize); a = 1; y = filter(b,a,x); disp(y);
Attempts:
2 left
💡 Hint
Think about how the filter function computes each output as a weighted sum of current and previous inputs.
✗ Incorrect
The moving average filter with window size 3 uses b = [1/3 1/3 1/3], padding previous inputs with zeros. The first output is (1)/3 = 0.3333, the second (1 + 2)/3 = 1, the third (1 + 2 + 3)/3 = 2, and so on.
❓ Predict Output
intermediateEffect of filter coefficients on output
What is the output of this MATLAB code that applies a filter with coefficients b and a to the input vector x?
MATLAB
x = [0 1 0 0 0]; b = [1 1]; a = 1; y = filter(b,a,x); disp(y);
Attempts:
2 left
💡 Hint
The filter output at each step depends on current and previous inputs weighted by b coefficients.
✗ Incorrect
The filter output y[n] = b(1)*x[n] + b(2)*x[n-1]. For input x = [0 1 0 0 0], y = [0, 1, 1, 0, 0].
🔧 Debug
advancedIdentify the error in filter usage
What error does this MATLAB code produce when run?
MATLAB
x = [1 2 3 4]; b = [1 2 3]; a = [1 0]; y = filter(b,a,x);
Attempts:
2 left
💡 Hint
Check the denominator coefficients 'a' for invalid values.
✗ Incorrect
No error is produced. MATLAB's filter function requires only that a(1) ~= 0; zeros in other positions of 'a' are allowed and the code runs successfully, producing a filtered vector.
🧠 Conceptual
advancedUnderstanding filter initial conditions
What is the effect of specifying initial conditions in the MATLAB filter function?
Attempts:
2 left
💡 Hint
Think about how filters remember past inputs or outputs.
✗ Incorrect
Initial conditions set the filter's internal state at the start, which helps avoid transient effects caused by assuming zero past inputs or outputs.
❓ Predict Output
expertOutput length after filtering with different coefficient lengths
What is the length of the output vector y after running this MATLAB code?
MATLAB
x = 1:5; b = [1 -1 1]; a = 1; y = filter(b,a,x);
Attempts:
2 left
💡 Hint
The filter function output length matches the input length.
✗ Incorrect
The filter function returns an output vector y with the same length as the input vector x, regardless of the length of coefficients b and a.
