noise reduction of voice sample
22 views (last 30 days)
Show older comments
I have a voice samples. i will try to reduce the noises but my code is not working.
% Load the audio file
[y, Fs] = audioread('voice_sample.wav');
% Perform spectral subtraction
y_clean = spectralSubtraction(y, Fs);
% Write the cleaned audio to a new file
audiowrite('voice_sample_cleaned.wav', y_clean, Fs);
% Function for spectral subtraction
function y_clean = spectralSubtraction(y, Fs)
% Compute the short-time Fourier transform (STFT) of the audio signal
win_size = round(0.03*Fs); % Window size of 30ms
hop_size = round(0.01*Fs); % Hop size of 10ms
nfft = 2^nextpow2(win_size); % Number of FFT points
[S, f, t] = spectrogram(y, win_size, hop_size, nfft, Fs);
% Compute the power spectrum of the noisy speech
Pyy = abs(S).^2;
% Compute the power spectrum of the noise
noise_start = 1; % Starting frequency bin of the noise
noise_end = round(2000 / (Fs/nfft)); % Ending frequency bin of the noise (assumed to be below 2 kHz)
Pnn = mean(Pyy(:,noise_start:noise_end), 2);
% Compute the power spectrum of the speech
Pyy_est = max(Pyy - Pnn, 0);
% Reconstruct the cleaned audio signal
y_clean = real(ifft(S .* sqrt(Pyy_est ./ Pyy), 'symmetric'));
end
0 Comments
Answers (1)
Drishti
on 11 Oct 2024
Hi Sanusha,
I understand that you are trying to reduce noise from the audio signal, but the provided code is not working.
On debugging the code, I found that ‘y_clean’ variable is of dimension ‘1024 x 1147’ which signifies that ‘1147’ audio channels are present in the provided audio signal.
After referring to the MathWorks Documentation of ‘audiowrite’ function, I discovered that ‘audiowrite’ function does not support large number of audio channels like ‘1147’, hence the provided code throws an error as ‘Unsupported number of channels.’
For more information, you can refer to the MATLAB Documentation of ‘audiowrite’ function.
This issue can be resolved by converting the ‘y_clean’ channel into mono channel form by averaging the channels to maintain the balance of all available channels.
You can refer to the implementation below for better understanding:
% Ensure y_clean is a column vector if the input is mono
if size(y_clean, 2) > 1
y_clean = mean(y_clean, 2);
end
I hope this resolves the issue.
0 Comments
See Also
Categories
Find more on Audio Processing Algorithm Design in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!