overlap_add.m

来自「用dsp解压mp3程序的算法」· M 代码 · 共 45 行

M
45
字号
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% overlap_add.m - Program of spectrum estimation using
%                 overlap-add approach
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

close all, clear all;

x = randn(1,1024);
h = hanning(64)';
Nxb = 128;
No_section = length(x)/Nxb;
Nh = length(h);
total_point = Nxb+Nh-1;
h_zp = [h zeros(1,total_point-Nh)];


for k = 0:1:No_section-1
    x_section(k+1,:)=[x((k*Nxb)+1:(k*Nxb)+Nxb) zeros(1,total_point-Nxb)];
end

for k = 0:1:No_section-1
    X_section(k+1,:) = fft(x_section(k+1,:));
    H = fft(h_zp);
    y_section(k+1,:)=real(ifft(X_section(k+1,:).*H));   
end

y_final = [y_section(1,1:Nh-1)];
for k = 0:1:No_section-2
    y_final = [y_final y_section(k+1,Nh:total_point-Nh+1) (y_section(k+1,total_point-Nh+2:total_point)+y_section(k+2,1:Nh-1))];
end    
y_final = [y_final y_section(No_section,Nh:total_point)];

figure;
subplot(211),stem(y_final); title('Convolve in freq domain using overlap-add');

y1 = conv(x,h);
subplot(212),stem(y1), title('Convolve in time-domain');

% MATLAB also provides an overlap-add function (fftfilt.m)...
y_matlab = fftfilt(h,x,Nxb); figure; stem(y_matlab), title('Convolve in frequency domain using MATLAB overlap-add function, fftfilt');
%y_matlab = fftfilt(x,h,Nxb);


⌨️ 快捷键说明

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