⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 snr.m

📁 matlab仿真通过的降噪程序
💻 M
字号:
% ----------------------------------------------------------------------%%   Segmental Signal-to-Noise Ratio Objective Speech Quality Measure%%		    Robust Speech Processing Laboratory	%			  Duke University, USA%			   Copyright (c) 1998%			  All Rights Reserved.%%  Description:%%     This function implements the segmental signal-to-noise ratio%     defined on page 45 of [1] (see Equation 2.12).%%  Input/Output:%%     The input is a reference 8kHz sampled speech, and processed %     speech (could be noisy or enhanced).  %%     This function returns 2 parameters.  The first item is the%     overall SNR for the two speech signals.  The second value%     is the segmental signal-to-noise ratio (1 seg-snr per %     frame of input).  The segmental SNR is clamped to range %     between 35dB and -10dB see suggestions in [2].%%  References:%%     [1] S. R. Quackenbush, T. P. Barnwell, and M. A. Clements,%	    Objective Measures of Speech Quality.  Prentice Hall%	    Advanced Reference Series, Englewood Cliffs, NJ, 1988,%	    ISBN: 0-13-629056-6.%%     [2] P. E. Papamichalis, Practical Approaches to Speech %	    Coding, Prentice-Hall, Englewood Cliffs, NJ, 1987.%	    ISBN: 0-13-689019-9. (see pages 179-181).%%  Authors:%%     Bryan L. Pellom and John H. L. Hansen%     Robust Speech Processing Laboratory, Duke University%     Department of Electrical Engineeering%%  Last Modified:%%     July 22, 1998%% ----------------------------------------------------------------------function [overall_snr, segmental_snr] = snr(clean_speech, processed_speech)% ----------------------------------------------------------------------% Check the length of the clean and processed speech.  Must be the same.% ----------------------------------------------------------------------clean_length      = length(clean_speech);processed_length  = length(processed_speech);if (clean_length ~= processed_length)  disp('Error: Both Speech Files must be same length.');  returnend% ----------------------------------------------------------------------% Scale both clean speech and processed speech to have same dynamic% range.  Also remove DC component from each signal% ----------------------------------------------------------------------%clean_speech     = clean_speech     - mean(clean_speech);%processed_speech = processed_speech - mean(processed_speech);%processed_speech = processed_speech.*(max(abs(clean_speech))/...%				      max(abs(processed_speech)));overall_snr = 10*log10(sum(clean_speech.^2)/sum((clean_speech-processed_speech).^2));% ----------------------------------------------------------------------% Global Variables% ----------------------------------------------------------------------sample_rate =  8000;		   % default sample ratewinlength   =  240;		   % window length in samplesskiprate    =  60;		   % window skip in samplesMIN_SNR     = -10;		   % minimum SNR in dBMAX_SNR     =  35;		   % maximum SNR in dB% ----------------------------------------------------------------------% For each frame of input speech, calculate the Segmental SNR% ----------------------------------------------------------------------num_frames = clean_length/skiprate-(winlength/skiprate); % number of framesstart      = 1;					% starting samplewindow     = 0.5*(1 - cos(2*pi*(1:winlength)'/(winlength+1)));for frame_count = 1:num_frames   % ----------------------------------------------------------   % (1) Get the Frames for the test and reference speech.    %     Multiply by Hanning Window.   % ----------------------------------------------------------   clean_frame = clean_speech(start:start+winlength-1);   processed_frame = processed_speech(start:start+winlength-1);   clean_frame = clean_frame.*window;   processed_frame = processed_frame.*window;   % ----------------------------------------------------------   % (2) Compute the Segmental SNR   % ----------------------------------------------------------   signal_energy = sum(clean_frame.^2);   noise_energy  = sum((clean_frame-processed_frame).^2);   segmental_snr(frame_count) = 10*log10(signal_energy/noise_energy);   segmental_snr(frame_count) = max(segmental_snr(frame_count),MIN_SNR);   segmental_snr(frame_count) = min(segmental_snr(frame_count),MAX_SNR);   start = start + skiprate;end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -