I apply an FIR filter passing the band around 50/1000 and attenuating the other three frequency components 30/1000, 70/1000 and 110/1000.
Both filters are generated using the Remez algorithm. The first filter is of length 300 and the second is of length 100.
Why is the beginning of the filtered signal attenuated and why is this attenuation effect stronger for a longer filter?
library(signal)
par(mfrow=c(3,2))
ch <-
sin(2*pi*1:1000/floor(1000/30)) +
sin(2*pi*1:1000/floor(1000/50)) +
sin(2*pi*1:1000/floor(1000/70)) +
sin(2*pi*1:1000/floor(1000/110))
# FFT of signal
barplot(abs(fft(ch)[1:120]))
# unfiltered signal
plot(ch,type="l")
filter <- function(c0,d1,d2,n) {
fir <- remez(n=n,f=c(0,c0-d2,c0-d1,c0+d1,c0+d2,1),a=c(0,0,1,1,0,0))
freq <- freqz(fir,n=n)
y <- signal::filter(as.vector(fir), 1, x=ch)
# frequency response of filter
barplot(abs(fft(y))[1:120])
return(list(freq = freq, fir = fir, y = y))
}
f <- filter(2*50/1000,1/80,1/40,n=300)
# first filtered signal
plot(f$y, type="l")
f <- filter(2*50/1000,1/80,1/40,n=100)
# second filtered signal
plot(f$y, type="l")