フィルターのクリア

Fixed signal averaging?

2 ビュー (過去 30 日間)
Ghufran Abdul Qayum
Ghufran Abdul Qayum 2022 年 2 月 1 日
回答済み: William Rose 2022 年 2 月 1 日
Hello,
I have a signal sampled at 2048hz, I want to apply fixed signal averaging filter with the filter window of 0.5secs.
how would that be done? I know for the fact that I would subtract the mean of values of the signal at 0.5secs from the original signal. But how to apply it throught the whole signal? facing some trouble with loop making.
Thanks,

回答 (4 件)

Image Analyst
Image Analyst 2022 年 2 月 1 日
So how many elements are in 0.5 seconds when the time between samples is 1/2048?
deltaTime = 1/2048
numElements = 0.5 / deltaTime % Its 1024
% Now do movmean with that window width to get the mean signal
meanSignal = movmean(signal, numElements); % This is a filtered, smoothed signal.
% Subtract the mean from the signal. This will give a high pass filter and
% show up edges and other high frequency components only.
highPass = signal - meanSignal;
% Plot everything
subplot(1, 3, 1);
plot(signal, 'b-');
grid on;
subplot(1, 3, 2);
plot(meanSignal, 'b-');
grid on;
subplot(1, 3, 3);
plot(highPass, 'b-');
grid on;

Benjamin Thompson
Benjamin Thompson 2022 年 2 月 1 日
Here is a link talking about implementing digital filtering via convolution:
In MATLAB this is the conv function.

William Rose
William Rose 2022 年 2 月 1 日
You said "I want to apply fixed signal averaging filter with the filter window of 0.5secs."
This could mean various things. Do you want a flat moving average window with a width of 0.5 seconds? This is a kind of low-pass filter. See code below.
fs=2048; %sampling rate
N=10*fs; %10 seconds of data
t=(0:N-1)/fs; %time values
f1=0.1; %slow frequency
f2=1.0; %fast frequency
sigma=0.2; %amplitude of noise
x=sin(2*pi*f1*t)+cos(2*pi*f2*t)+sigma*randn(1,N);
Now we filter the data and display results.
Nw=0.5*fs; %window length for 0.5 seconds
w1=ones(1,Nw)/Nw; %0.5 second-long flat window
t1=t(Nw/2:end-Nw/2); %time range for filtered signal
x1=zeros(size(t1)); %allocate vector for filtered signal
for i=1:length(t1)
x1(i)=sum(w1.*x(i:i+Nw-1)); %compute the moving average
end
figure; plot(t,x,'-b');
hold on; grid on; xlabel('Time (s)');
plot(t1,x1,'-r','Linewidth',3);
legend('Raw','Filtered')
You also say "I know for the fact that I would subtract the mean of values of the signal at 0.5secs from the original signal". This suggests to me that you are doing a high-pass filter. I will also demonstrate this below.

William Rose
William Rose 2022 年 2 月 1 日
Now I show the highpass filter version. In this case, the output equals the input signal minus the mean of the signal for 0.5 seconds around that point.
fs=2048; %sampling rate
N=10*fs; %10 seconds of data
t=(0:N-1)/fs; %time values
f1=0.1; %slow frequency
f2=1.0; %fast frequency
sigma=0.2; %amplitude of noise
x=sin(2*pi*f1*t)+cos(2*pi*f2*t)+sigma*randn(1,N);
Now we filter the data and display results.
Nw=0.5*fs; %window length for 0.5 seconds
%w1=ones(1,Nw)/Nw; %0.5 second-long flat window
t1=t(Nw/2:end-Nw/2); %time range for filtered signal
x1=zeros(size(t1)); %allocate vector for filtered signal
for i=1:length(t1)
x1(i)=x(i+Nw/2)-mean(x(i:i+Nw-1)); %high-pass filter
end
figure; plot(t,x,'-b');
hold on; grid on; xlabel('Time (s)');
plot(t1,x1,'-r');
legend('Raw','Filtered')
Try it.

カテゴリ

Help Center および File ExchangeMultirate Signal Processing についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by