About output signal digital band pass filter I try to use the butter worth pandpass filter to retrive the OSC from signal y showing in Fig3.

The output signal is as in Fig4. We can see from Fig4 that I have retrived the OSC successfully. 

But in the output signal(Fig4), there is noise signal from sample number 0 to sample number 100. I want to know which caused the problem? How can I remove the noise signal or where can I start?



The Octave code is as following:

%###################################################

% freq:the sample rate

% sinNum:Ignore it, not used.

%###################################################

function [y] = DigitalFilterAppliedProb(freq, sinNum)
    close all;

    x1 = (0:1/freq:1);
    x1 = x1(1:end-1);
    i = 0;

    lenOfX1 = length(x1); 
    y1 = zeros(1, lenOfX1);

    %for i=1:sinNum
    %   y1 = y1 + sin(i*2*pi*x1);
    %endfor

    y1 = y1 + sin(20*2*pi*x1);

    y2 = [zeros(1, freq) y1 zeros(1, freq)];

    lengthOfY2 = length(y2);

    x0 = (0:1/freq:lengthOfY2/freq);
    x0 = x0(1:end-1);
    %y0 = 2*ones(1, lengthOfY2);
    y0 = -10*x0+10;

    y = y0 + y2;

    %Plot   
    figure 1
    subplot(2, 2, 1)
    plot(y0);
    title("Fig1.Source signal(y0 = -10*x + 10)")    

    %figure 2;
    subplot(2, 2, 2)
    plot(y2);
    title("Fig2.Source Signal(y2=sin(20*2*pi*x))")

    %figure 3;
    subplot(2, 2, 3)
    plot(y);
    title("Fig3.Source Signal(y=y0+y2)")

    %Low pass filter
    [b, a] = butter(8, [5/(freq/2) 45/(freq/2)]);
    yf = filter(b, a, y);

    %figure 4
    subplot(2, 2, 4)
    plot(yf);
    title("Fig4.Filtered Signal")

    figure 2
    freqz(b, a);

endfunction
What you are seeing is not "noise", but the step response of your filter.

Note that the filter is started with a null state (unless you explicitly call filter with state variables).

Your signal starts at value 10, so you will get something very similar to 10 times the filter's step response.

If you want to eliminate this transient, then you can either:


Subtract 10 from your input signal, so that it starts at 0.
Prepend your signal with enough samples so that the transient does not overlap with your signal of interest. These samples can be all 10 in value, for example.
Multiply your whole signal by a window function; something like yw = 
y .* hann(length(y))'. This way the whole signal is smoothed at the edges and you minimize the transient.