Apply frequency domain filter on PSD
이전 댓글 표시
Hi,
I'm trying to apply a High pass filter on a digital (from sensor capture) signal. I set my cutoff frequency to "cutoffFreq/(sampleFreq/2)" however, I still have low frequency under my cutoff Frequency and the filter seems to not work...
I'm wondering if the problem does not come from the fact that the HP filter act on the frequency in Hz and my PSD is not expressed in Hz but in number of points. Actually, to plot the PSD in frequency domain, we need to use :
plot(f, PSD);
If we plot only PSD, the X axis will be the number of point. I'm not sure but i suppose that my filter act on number of point and not on frequency. Could you confirm or not my thought ?
If i'm right, how can I proceed to filter my sample at 0.5Hz ?
Best.
My PSD with my fundamental frequency and high peaks on low frequency under 0.5Hz :

My code :
%import csv file
M = load("10.csv");
%select the gx column
gx = M(:,1);
%select the gy column
gy = M(:,2);
%select the gz column
gz = M(:,3);
t = M(:,4);
%size of M (same size for each column)
s = length(gz);
%because of loop, need s/2
s2 = fix(s/2);
%acquisition frequency
sampleFrequency = 30;
%calculate x axis (frequency)
f = sampleFrequency/s*(0:s2);
%compute the angle from angular velocity
angle = zeros(s, 1);
angle(1, 1) = 0;
for i = 2:s
dt = t(i,1) - t(i-1,1);
angle(i,1) = angle(i-1) + (gz(i,1)* dt);
end
%normalize the values to center on 0 and avoid first huge peak on 0 frequency
angle = angle - mean(angle(:));
%apply Hanning window of angle
angle = angle.*hanning(length(angle));
% figure
Yangle = fft(angle, s);
%order of the HP filter
n = 2;
%cutoff frequency (Hz)
cutoffFrequency = 0.5;
wc = cutoffFrequency/ (sampleFrequency/2);
%create the filter
b = fir1(n, wc, "high");
PSD = Yangle.*conj(Yangle)/s;
filteredPSD = filter(b, 1, PSD);
figure
plot(f, filteredPSD(1:s2+1));
title('Power Spcetral Density for gyroscope')
xlabel('Frequency (Hz)')
ylabel('Power (g²/Hz)')
답변 (1개)
Star Strider
2016년 2월 15일
0 개 추천
I would use the Signal Processing Toolbox function fftfilt for frequency domain filtering. (I have no experience with it since I don’t use frequency domain filtering. The documentation is extensive, so you should have no problems using it in your code.)
댓글 수: 4
Maxence
2016년 2월 16일
Star Strider
2016년 2월 16일
I’m not certain what you actually want to filter, or the characteristics of your signal. I always use time-domain filtering because it’s generally easier.
Your signals of interest have very low frequencies, so unless you have a relatively high sampling frequency (on the order of 100 Hz or higher), any filter design to filter one or more of your peaks may be difficult to realise.
Maxence
2016년 2월 17일
Star Strider
2016년 2월 17일
My filter design procedure is here: How to design a lowpass filter for ocean wave data in Matlab? If your sampling frequency is high enough, you should be able to realise your filter in the time domain. That’s much easier than trying to do frequency domain filtering.
카테고리
도움말 센터 및 File Exchange에서 Analog Filters에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!