0
votes

I'm trying to understand the difference between linear and circular convolution by adapting the Matlab methodologies here. I'm comparing the results of linear convolution with use of the inbuilt conv and cconv function, Bruno Luong's convnfft, and NAG's c06pk.

This is related to the math.stackexchange post.

My code is

% complex vectors
x = rand(2^5,1) + 1j*rand(2^5,1);
y = rand(2^5,1) - 1j*rand(2^5,1);

clin = conv(x,y); % Matlab convolution function
cfun = convnfft(x,y); % Bruno Luong function

N = length(x)+length(y)-1;
xpad = [x' zeros(1,N-length(x))]; % pad vectors
ypad = [y' zeros(1,N-length(y))];
ccirc = cconv(xpad,ypad); % do linear convolution with circular convolution function
cnag = c06pk(int64(1),xpad,ypad); % do linear convolution with NAG function

figure()
plot(clin,'o'); hold on; plot(cfun,'+')
figure()
plot(ccirc,'.'); hold on; plot(cnag,'x')

When I plot the results of linear convolution using the various methods outlined in the code, not all of them agree with the clin result. The cfun agrees, but ccirc and cnag don't because they are designed for finding circular convolutions.

Have I done something wrong with the zero-padding?

Edit: If I plot the results of these linear convolutions I get:

enter image description here enter image description here

Is there some scaling issue in cconv and c06pk?

1

1 Answers

1
votes

You wrote:

xpad = [x' zeros(1,N-length(x))]; 
ypad = [y' zeros(1,N-length(x))]; 

However, the ' operator, does not only transpose but also conjugate. Replace it by

xpad = [x.' zeros(1,N-length(x))]; 
ypad = [y.' zeros(1,N-length(x))]; 

This should fix the problem. I could only test conv and cconv which after this fix agreed perfectly.