Sumbul
Sumbul

Reputation: 167

Trying to eliminate delay of filter command to match the results with conv command

Blue coloured curve in the diagram is the result of using conv command in MATLAB for generating a Gaussian modulated signal. But I need to use filter command for the same purpose, resulting in magenta coloured curve. It is shifted towards right by almost 15 points which I have taken care of by discarding first 15 points, which has resulted in red coloured curve. It perfectly follows the curve of convolution command until the point pointed out in the given diagram.

I have added 15 zeros at the end of red curve to match the resultant rector length with that of conv command.

My question is that how can I make the red curve follow the blue cure?

My code lines are:

     phase = conv (integrated_signal,gaussFilter,'same'); 
     phase_1 = filter (gaussFilter,1,integrated_signal);
     delay=16;
     phase_1=phase_1(delay:end);
     phase_1(1,length(phase_2)+delay)=0;

enter image description here

Upvotes: 1

Views: 130

Answers (1)

SleuthEye
SleuthEye

Reputation: 14577

In general conv(u,v) produces the same result as filter(u,1,padded_v) where padded_v is v zero padded to a length of length(u)+length(v)-1. Assuming that integrated_signal is a row vector, this can be done with the following:

padded_signal = [integrated_signal zeros(1,length(gaussFilter)-1)];
% or following for column vectors:
% padded_signal = transpose([transpose(integrated_signal) zeros(1,length(gaussFilter)-1)]);
phase_1 = filter (gaussFilter,1,padded_signal);

Now, according to the documentation, conv(u,v,'same') with the 'same' argument produces the

Central part of the convolution of the same size as u.

It then only suffices to extract the same central part:

delay = floor(length(gaussFilter)/2);
phase_1=phase_1(delay + [1:length(integrated_signal)]);

Upvotes: 1

Related Questions