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)')

Respuestas (1)

Star Strider
Star Strider el 15 de Feb. de 2016

0 votos

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 comentarios

Maxence
Maxence el 16 de Feb. de 2016
I'm applying the same filter with fftfilt and the result is the same. No action...
Star Strider
Star Strider el 16 de Feb. de 2016
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
Maxence el 17 de Feb. de 2016
I just want to cut off all the frequencies on my the PSD under 0.1 Hz. Indeed, on some samples, the 0.05Hz peaks is a bit higher than the 1Hz peak and the fundamental detected is 0.05Hz which is actually noise.
Star Strider
Star Strider el 17 de Feb. de 2016
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.

Iniciar sesión para comentar.

Preguntada:

el 15 de Feb. de 2016

Comentada:

el 17 de Feb. de 2016

Community Treasure Hunt

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

Start Hunting!

Translated by