Bird
Raised Fist0
MATLABdata~20 mins

Audio signal processing in MATLAB - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Audio Signal Processing Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
What is the output of this MATLAB code for audio normalization?
Consider the following MATLAB code that normalizes an audio signal to the range [-1, 1]. What will be the maximum absolute value of the output signal y?
MATLAB
x = [-0.5, 0.2, 0.8, -0.9, 0.4];
max_val = max(abs(x));
y = x / max_val;
max_abs_y = max(abs(y));
disp(max_abs_y);
A0.5
B1
C0.8
D0.9
Attempts:
2 left
💡 Hint
Normalization divides all values by the maximum absolute value in the signal.
🧠 Conceptual
intermediate
1:30remaining
What does the MATLAB function audioread return?
When you use [y, Fs] = audioread('sound.wav'); in MATLAB, what do the variables y and Fs represent?
A<code>y</code> is the audio data array, <code>Fs</code> is the sampling frequency in Hz
B<code>y</code> is the audio file size in bytes, <code>Fs</code> is the number of channels
C<code>y</code> is the audio duration in seconds, <code>Fs</code> is the bit depth
D<code>y</code> is the sampling frequency, <code>Fs</code> is the audio data array
Attempts:
2 left
💡 Hint
Think about what you need to play or process audio: the sound data and how fast it was recorded.
🔧 Debug
advanced
2:00remaining
Why does this MATLAB code produce an error when playing audio?
The following code attempts to play an audio signal but causes an error. What is the cause?
MATLAB
y = rand(1000, 2); % stereo noise
sound(y, 44100);
sound(y(:,1), 44100);
AError because <code>sound</code> cannot play stereo signals
BError because <code>sound</code> expects a column vector for mono, but <code>y(:,1)</code> is a row vector
CError because the sampling rate 44100 is not defined
DNo error occurs; both lines play sound correctly
Attempts:
2 left
💡 Hint
Check the shape of the input to sound and what it accepts for stereo and mono.
📝 Syntax
advanced
2:30remaining
Which MATLAB code snippet correctly applies a low-pass filter to an audio signal?
Given an audio signal x sampled at 44100 Hz, which code correctly applies a low-pass FIR filter with cutoff 5000 Hz?
A
fc = 5000; fs = 44100;
N = 50;
b = fir1(N, fc/(fs/2));
y = filter(b, 1, x);
B
fc = 5000; fs = 44100;
N = 50;
b = fir1(N, fc/fs);
y = filter(b, 1, x);
C
fc = 5000; fs = 44100;
N = 50;
b = fir1(N, fc*2/fs);
y = filter(1, b, x);
D
fc = 5000; fs = 44100;
N = 50;
b = fir1(N, fc/(fs*2));
y = filter(b, 1, x);
Attempts:
2 left
💡 Hint
The cutoff frequency must be normalized by half the sampling rate (Nyquist frequency).
🚀 Application
expert
2:00remaining
How many samples are in the output after downsampling this audio signal?
An audio signal x has 88200 samples sampled at 44100 Hz. You downsample it by a factor of 4 using y = downsample(x, 4);. How many samples does y contain?
A44100
B88200
C22050
D11025
Attempts:
2 left
💡 Hint
Downsampling by 4 keeps every 4th sample, reducing the total number of samples by 4.

Practice

(1/5)
1. What does the MATLAB function audioread do in audio signal processing?
easy
A. It saves audio data to a file.
B. It plays the audio sound through speakers.
C. It reads an audio file and loads the sound data into MATLAB.
D. It filters the audio signal to remove noise.

Solution

  1. Step 1: Understand the purpose of audioread

    The function audioread is used to load audio data from a file into MATLAB as a vector or matrix.
  2. Step 2: Differentiate from other audio functions

    Functions like sound play audio, audiowrite saves audio, and filter processes signals. audioread only reads data.
  3. Final Answer:

    It reads an audio file and loads the sound data into MATLAB. -> Option C
  4. Quick Check:

    audioread = read audio data [OK]
Hint: Remember: 'read' means load data, not play or save [OK]
Common Mistakes:
  • Confusing audioread with sound
  • Thinking it saves audio instead of loading
  • Assuming it filters or changes the audio
2. Which of the following is the correct syntax to apply a simple low-pass filter b, a to an audio signal x in MATLAB?
easy
A. y = filter(b, a, x);
B. y = filter(x, b, a);
C. y = filter(a, b, x);
D. y = filter(x, a, b);

Solution

  1. Step 1: Recall the filter function syntax

    The MATLAB filter function syntax is y = filter(b, a, x); where b and a are filter coefficients and x is the input signal.
  2. Step 2: Identify correct argument order

    Options A, C, and D have the arguments in wrong order, which will cause errors or wrong output.
  3. Final Answer:

    y = filter(b, a, x); -> Option A
  4. Quick Check:

    filter(b, a, x) = correct syntax [OK]
Hint: Filter syntax is always filter(b, a, x) [OK]
Common Mistakes:
  • Swapping filter coefficients order
  • Putting signal before coefficients
  • Using wrong variable names
3. What will be the output size of y after running this MATLAB code?
x = randn(44100,1); % 1 second noise at 44.1kHz
b = [1 0 0.5]; a = 1;
y = filter(b, a, x);
medium
A. An error due to filter coefficients
B. A vector of size 44102x1
C. A scalar value
D. A vector of size 44100x1

Solution

  1. Step 1: Understand input and filter output length

    The input x is a 44100x1 vector. The filter function outputs a vector of the same length as input.
  2. Step 2: Check filter coefficients validity

    Coefficients b and a are valid. No error occurs. Output y matches input size.
  3. Final Answer:

    A vector of size 44100x1 -> Option D
  4. Quick Check:

    filter output length = input length [OK]
Hint: Filter output length equals input length [OK]
Common Mistakes:
  • Assuming output length changes with filter order
  • Expecting error from coefficients
  • Confusing vector with scalar output
4. Identify the error in this MATLAB code that tries to add an echo effect to an audio signal x:
delay = 5000;
echoGain = 0.6;
y = x;
y(delay:end) = y(delay:end) + echoGain * x(1:end-delay);
medium
A. The length of y(delay:end) and x(1:end-delay) do not match.
B. The variable echoGain should be greater than 1.
C. The indexing delay:end is invalid for vector y.
D. The echo effect requires a filter function, not direct addition.

Solution

  1. Step 1: Check vector lengths in addition

    The segment y(delay:end) has length length(y) - delay + 1. The segment x(1:end-delay) has length length(x) - delay. They differ by 1, causing a dimension mismatch error.
  2. Step 2: Eliminate other options

    A: Indexing is valid. B: echoGain=0.6 <1 is appropriate for decaying echo. D: Direct indexing addition works for simple echo.
  3. Final Answer:

    The length of y(delay:end) and x(1:end-delay) do not match. -> Option A
  4. Quick Check:

    len(y(delay:end))=N-d+1 vs len(x(1:end-d))=N-d [OK]
Hint: Check lengths of vectors before adding [OK]
Common Mistakes:
  • Assuming echoGain must be >1
  • Thinking filter is required for echo
  • Ignoring vector length mismatch
5. You want to create a MATLAB function that adds an echo effect to an audio signal x sampled at Fs. The echo delay is 0.3 seconds and echo gain is 0.5. Which code correctly implements this?
hard
A. function y = addEcho(x, Fs) delaySamples = round(0.3 * Fs); y = x; y(delaySamples+1:end) = y(delaySamples+1:end) + 0.5*x(1:end-delaySamples); end
B. function y = addEcho(x, Fs) delaySamples = round(0.3 * Fs); y = filter([1 zeros(1,delaySamples-1) 0.5], 1, x); end
C. function y = addEcho(x, Fs) delaySamples = round(0.3 * Fs); y = x + 0.5 * [zeros(delaySamples,1); x]; end
D. function y = addEcho(x, Fs) delaySamples = round(0.3 * Fs); y = zeros(length(x)+delaySamples,1); y(1:length(x)) = x; y(delaySamples+1:end) = y(delaySamples+1:end) + 0.5*x; end

Solution

  1. Step 1: Understand echo effect implementation

    Echo is created by adding a delayed and scaled copy of the signal to itself. Using filter with coefficients [1 zeros(1,delaySamples-1) 0.5] adds original plus delayed echo.
  2. Step 2: Evaluate each option

    function y = addEcho(x, Fs) delaySamples = round(0.3 * Fs); y = zeros(length(x)+delaySamples,1); y(1:length(x)) = x; y(delaySamples+1:end) = y(delaySamples+1:end) + 0.5*x; end extends length but adds full x without delay in echo part. function y = addEcho(x, Fs) delaySamples = round(0.3 * Fs); y = x; y(delaySamples+1:end) = y(delaySamples+1:end) + 0.5*x(1:end-delaySamples); end correctly indexes x to match lengths. function y = addEcho(x, Fs) delaySamples = round(0.3 * Fs); y = x + 0.5 * [zeros(delaySamples,1); x]; end adds vectors of different lengths causing error. function y = addEcho(x, Fs) delaySamples = round(0.3 * Fs); y = filter([1 zeros(1,delaySamples-1) 0.5], 1, x); end correctly uses filter with proper coefficients.
  3. Final Answer:

    function y = addEcho(x, Fs) delaySamples = round(0.3 * Fs); y = filter([1 zeros(1,delaySamples-1) 0.5], 1, x); end -> Option B
  4. Quick Check:

    Use filter with delayed coefficients for echo [OK]
Hint: Use filter with delayed coefficients for echo [OK]
Common Mistakes:
  • Adding vectors of different lengths directly
  • Forgetting to delay the echo signal
  • Incorrect indexing causing errors
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