over-lapping & adding [FFT] - Error - Index exceeds matrix dimensions
Mostrar comentarios más antiguos
Hello,
I am trying to process a signal using the overlap and add method, however I get an error, when running the loop, I am not sure what matrix is exceeding the dimensions or how to solve it, i tried adding counters to trace the issue but I still can't understand where i went wrong, here's the code:
clc;
clear all;
x = [3 9 1 2 3 4 5 6 3 4 5 6 7 8 9 8 7 8];
h = [1 2 1 1];
% Code to perform Convolution using Overlap Add Method
n1 = length(x);
% M-1
n2 = length(h);
% length of the output
N = n1+n2-1;
% intializing the output vector
y = zeros(1,N);
% zero padded impulse response
h1 = [h zeros(1,n2-1)]
% block size
n3 = length(h1);
% new size of output function
% now that we know the block size
y = zeros(1,N+n3-n2);
% FFT of the impulse response
%fft_size =
H = fft(h1); %, fft_size);
count_1 = 0;
count_2 = 0;
count_3 = 0;
count_4=0;
count_5=0;
for i = 1:n2:n1
if i<=(n1+n2-1)
x1 = [x(i:i+n3-n2) zeros(1,n3-n2)];
count_1 = count_1+1;
else
x1 = [x(i:n1) zeros(1,n3-n2)];
count_2 = count_2 +1;
end
x2 = fft(x1);
x3 = x2.*H;
x4 = round(ifft(x3));
if (i==1)
y(1:n3) = x4(1:n3);
count_3 = count_3+1;
else
y(i:i+n3-1) = y(i:i+n3-1)+x4(1:n3);
count_4 = count_4+1;
end
count_5 = count_5+1;
end
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Signal Operations en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!