overlap_save.m

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

M
50
字号
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% overlap_save.m - Program for spectrum estimation
%                  using overlap-save approach
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

close all, clear all;

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


non_overlap = Nxb-Nh+1;
No_section = floor(length(x)/non_overlap);

x_prev = zeros(1,Nh-1);

for k = 0:1:No_section-1
    x_section(k+1,:)=[x_prev x(k*non_overlap+1:k*non_overlap+non_overlap)];    
    x_prev = x((k*non_overlap)+(non_overlap-Nh+2):(k*non_overlap)+non_overlap);    
end

% Note this part take into consideration of the remaining data

total_length = length(x)
no_remain = total_length-No_section*non_overlap;
no_zeros = non_overlap-no_remain;
x_section(No_section+1,:) = [x_prev x(total_length-no_remain+2:total_length) zeros(1,no_zeros+1)];

y_final = [];
for k = 0:1:No_section
    X_section(k+1,:) = fft(x_section(k+1,:));
    H = fft(h_zp);
    y_section=real(ifft(X_section(k+1,:).*H));   
    y_final = [y_final y_section(Nh:Nxb)];
end    

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

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




⌨️ 快捷键说明

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