Apply frequency domain filter on PSD
16 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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)')
0 Kommentare
Antworten (1)
Star Strider
am 15 Feb. 2016
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 Kommentare
Star Strider
am 17 Feb. 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.
Siehe auch
Kategorien
Mehr zu Multirate Signal Processing finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!