MATLAB 中的实时麦克风音频处理

问题描述

美好的一天!嗨,我正在 MATLAB 中测试我的频谱减法降噪算法。我想实时尝试一下。我搜索一个解决方here 并且我试图在该解决方案中插入我的 MATLAB 代码,但它似乎不起作用。

Microphone = dsp.AudioRecorder('SampleRate',44100,'NumChannels',1,'OutputNumOverrunSamples',true);
Speaker = dsp.AudioPlayer;
SpecAnalyzer = dsp.SpectrumAnalyzer;
fs=44100;
tic;
while(toc<30)

audio = step(Microphone);
%%% Spectral Subtraction Algorithm%%%%

%recObj= audiorecorder(44100,16,1); 
%disp('Start speaking.')
%recordblocking(recObj,10);
%disp('End of Recording.');
%audio = getaudiodata(recObj);
%fs=44100;

    W=fix(0.02*fs);                  % window length in 20 ms
    SP=.5;                          % overlapp factor      
    Noise_frames=5;                 % number of initial noise transms
    
    len_x=length(audio);
    len_20=0.02*fs;
                                    % Window generation
    wnd=hanning(W,'periodic');    

% Increasing length of x to match an integer
% of blocks

    genzeros=len_20*(floor(len_x/len_20)+1)-len_x;
    len_x=len_x+genzeros;
    audio=[audio;zeros(genzeros,1)];

% Windowed,FFT,and Three-Frame Averaging
P=1;
Speech_Margin=-12;

numsamples=fix(W.*SP);
N=fix((len_x-W)/numsamples +1);              % number of frames / segments


Index=(repmat(1:W,N,1)+repmat((0:(N-1))'*numsamples,W))';
hw=repmat(wnd,N);
Seg=audio(Index).*hw;
Y_orig=fft(Seg,W,1);

Yfase=angle(Y_orig);
Ymag=abs(Y_orig).^P;



Y(:,1)=Ymag(:,1);
for i=2:(N-1)
    Y(:,i)=(Ymag(:,i-1)+Ymag(:,i)+Ymag(:,i+1))/3;
end
Y(:,N)=Ymag(:,N);


S=zeros(size(Y));

% Using the first five frames to perform a
% initial estimate of the noise spectrum (check that 
% the number of frames is greater than 5,obvIoUsly)


Noise=mean(Y(:,1:Noise_frames).').'; %mean% of noise spectrum 
% the first 5 frames

NoiseCont=5;                    % Initialization of maximum value of residual noise

Noise_max=zeros(size(Noise));       % Processing of the following blocks

for ii=6:N
                                                                        % Elimination of bias and rectification of half wave
     S(:,ii)=(Y(:,ii))-(Noise);
 
     S((find(S(:,ii)<0)),ii)=0;
          
     T=20*log10(mean(S(:,ii)./Noise));
                                                                          % If there is no vocal activity 
    if (T <= Speech_Margin)
                                                                                % Update noise
        NoiseCont=NoiseCont+1;
        Noise=(Noise*(NoiseCont-1)+Y(:,ii))/(NoiseCont);
                                                                            % Update residual noise value
        Noise_max=max(Noise_max,Noise);
    
                                                                       % Additional noise attenuation
        S(:,ii)=Y(:,ii)/1000;
    
        
   % otherwise      
    else
        Est=S(:,ii);
       
        if ii>1 && ii<N           
            for j=1:length(Est)
                if Est(j)<Noise_max(j)
                    Est(j)=min([Est(j) Y(j,ii-1)-Noise(j) Y(j,ii+1)-Noise(j)]);
                  
                end
            end
        end
        S(:,ii)=Est;  
        S((find(Est<0)),ii)=0;
        %plot(S(:,ii));
        
    end
end    
S(:,1:5)=Y(:,1:5);
S=S.^(1/P);

S_est=S.*exp(1j*Yfase);

S_est=real(ifft(S_est,W));
     
% Synthesis using overlap-add
s=zeros(size(audio));

for jj=1:N
    startwrite=(jj-1)*W/2+1;
    s(startwrite:startwrite+W-1)=s(startwrite:startwrite+W-1)+S_est(:,jj);
    
end
                                                                                % Trim sest to original length of x
s=s(1:end-genzeros);
toc

%%% Spectral Subtraction Algorithm%%%%

%step(SpecAnalyzer,s);
step(Speaker,s);
end

我的目标是实时测试我的算法,我找到了解决方案,但我似乎无法将它与算法相匹配。请帮忙。谢谢。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)