I am trying to filter for a frequency of e.g. ~3.1Hz in a time-based signal which contains various frequency components (including the ~3.1Hz).
I tried to build a bandpass filter with a lowpass and a highpass filter. After plotting the results the filter does not seem to work regarding the amplitude and phase. Especially at the beginning as you can see in this photo.
filter does not seem to work mainly at the beginning
Therefore I also tried to enhance to signal with itself, then filter the enhanced signal for ~3.1Hz and afterward cut off the enhanced parts.
Where is my mistake?
x= linspace(0,1.6,4096);
funct=5*sin(20*x+0.9); %~3,1 Hz
plot(x,funct); %frequency I want to filter for
hold on;
funct=funct+ 3*sin(210*x); %inject other frequency components
plot(x,funct); %Time based Signal
%%% Enhence the length of the signal:
R=0.5; % 50% of signal
N=size(funct,2);
NR=round(N*R); % At most 2048 points
x1(1,:)=2*funct(1,1)-flipud(funct(1, 2:NR+1)); % maintain continuity in level and slope
x2(1,:)=2*funct(1, end)-flipud(funct(1, end-NR:end-1));
x_appd=[x1, funct ,x2];
%%%
%%% Do filtering
[b,a]=butter(3, 1/1000, "high");
x1_filt=filter(b,a,x_appd);
[c,d]=butter(3, 5/1000, "low");
x2_filt=filter(c,d,x1_filt);
%%%
x_ergb=x2_filt(:,NR+1:end-NR); %Cut of the enhenced parts of the signal
plot(x,x_ergb); %Plot the filtered function
hold off;
Thanks for your help!
I tried different filter settings and filters but nothing seems to work. Is there a solution to exactly filter for the desired frequency?
Laurin76 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.