如何在谱减法(MATLAB)后将每个帧重新相加?
为了执行光谱减法,我遵循指南,到目前为止,我有以下代码,但我无法确定如何在最后成功地将每个重叠帧连接在一起。谢谢你的帮助如何在谱减法(MATLAB)后将每个帧重新相加?,matlab,concatenation,overlap,subtraction,spectral,Matlab,Concatenation,Overlap,Subtraction,Spectral,为了执行光谱减法,我遵循指南,到目前为止,我有以下代码,但我无法确定如何在最后成功地将每个重叠帧连接在一起。谢谢你的帮助 function [ cleanFile ] = spectralSubtraction( noisyFile ) SamplingFrequency = 44100; frameLengthMs = 20; frameLength = (frameLengthMs/1000)*SamplingFrequency; numSamples = length(noisyFile
function [ cleanFile ] = spectralSubtraction( noisyFile )
SamplingFrequency = 44100;
frameLengthMs = 20;
frameLength = (frameLengthMs/1000)*SamplingFrequency;
numSamples = length(noisyFile);
noiseMagEstimate=0;
cleanFrame=0;
%imaginary number
j=sqrt(-1);
%spectrally flatten the speech
noisyFile = preEmphasis(noisyFile);
%frames overlap by 50% so number of frames is double.
numFrames = floor( numSamples / frameLength )*2;
for frame = 1:numFrames-2,
%get the first and last samples for this frame
first = (frame-1)*(frameLength/2)+1;
last = first+frameLength;
%get the samples for this frame
shortTimeFrame = noisyFile(first:last);
%apply a hamming window to this frame
shortTimeFrame = hann(frameLength+1).*shortTimeFrame;
%do the fft for the frame
shortTimeFrame = fft(shortTimeFrame);
%get the absolute value for the magnitude part
mag = abs(shortTimeFrame);
%calculate the phase
phase=angle(shortTimeFrame);
if frame<6
%average spectra of first 5 frames to get noise estimate
noiseMagEstimate=noiseMagEstimate+mag;
elseif frame==6
noiseMagEstimate=noiseMagEstimate/6;
else
%perform spectral subtraction on the rest of the file using
%the noise estimate from the first 5 frames
mag=mag-noiseMagEstimate;
%Flooring
if mag<0
mag=0;
end
%Merge clean mag and phase
cleanFrame=mag.*exp(j*phase);
%Inverse fourier transform of cleaned frame
cleanFrame=ifft(cleanFrame);
%Overlap and add clean frame to clean file
end
end
end
函数[cleanFile]=频谱子牵引(噪声文件)
采样频率=44100;
帧长=20;
帧长=(帧长/1000)*采样频率;
numSamples=长度(NoiseyFile);
noiseMagEstimate=0;
cleanFrame=0;
%虚数
j=sqrt(-1);
%用光谱法使讲话变得平淡
噪声文件=预相位(噪声文件);
%帧重叠50%,因此帧数是原来的两倍。
numFrames=地板(numSamples/框架长度)*2;
对于帧=1:numFrames-2,
%获取此帧的第一个和最后一个样本
第一个=(帧-1)*(帧长/2)+1;
最后一个=第一个+帧长;
%获取此框架的样本
shortTimeFrame=NoiseyFile(第一个:最后一个);
%将汉明窗口应用于此帧
shortTimeFrame=hann(frameLength+1)。*shortTimeFrame;
%对帧进行fft
短时帧=fft(短时帧);
%获取幅值部分的绝对值
mag=abs(短时间段);
%计算相位
相位=角度(短时间段);
如果帧
这不太好,但这是我后来补充的
cleanFrame=ifft(cleanFrame);
cleanFrame=ifft(cleanFrame);