Created
December 1, 2014 12:10
-
-
Save jameslyons/554325efb2c05da15b31 to your computer and use it in GitHub Desktop.
spectral subtraction demo in matlab
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[sig fs] = read_NIST_file(filename); % read the input file, assume filename is supplied | |
NFFT = 1024; | |
WINLEN = 0.025; %frame length in ms | |
WINSTEP = 0.01; | |
frames = frame_sig(sig, WINLEN*fs, WINSTEP*fs, @hamming); | |
cspec = fft(frames,NFFT,2); % complex spectrum | |
pspec = abs(cspec).^2; % power spectrum of noisy signal | |
phase = angle(cspec); | |
% do spectral subtraction, produce modified_pspec | |
noise_est = mean(pspec(1:3,:)); % noise_est is estimated from first three frames | |
clean_spec = pspec - repmat(noise_est,size(pspec,1),1); % subtract noise_est from pspec | |
clean_spec(clean_spec < 0) = 0; % negative power spectrum is not allowed | |
reconstructed_frames = ifft(sqrt(clean_spec).*exp(phase),NFFT,2); | |
reconstructed_frames = real(reconstructed_frames(:,1:WINLEN*fs)); % sometimes small complex residuals stay behind | |
enhanced_signal = deframe_sig(reconstructed_frames,length(sig),WINLEN*fs,WINSTEP*fs,@hamming); | |
soundsc(enhanced_signal,fs); % listen to our enhanced signal |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hi,
can you please share the function, you used for "frame_sig" and "deframe_sig"..
It will be very helpful for my project to proceed further.
Thanks In advance