61 views (last 30 days)

Hi,

I have a signal that shows a very distinctive peaks in the FFT.

Those high amplitudes are the 'noise' of the signal. I would like to remove that values from the original signal and to plot the filtered signal.

Fs = 4500; % Sampling frequency (fps)

T = 1/Fs; % Sampling period (s)

L = 900; % Length of signal (how many frames)

tt = (0:L-1)*T; % Time vector

thickness = detrend(thickness);

Y = fft(thickness);

P2 = abs(Y/L);

P1 = P2(1:L/2+1);

P1(2:end-1) = 2*P1(2:end-1);

f = Fs*(0:(L/2))/L;

figure(1111)

h1=plot(f(1:end),P1(1:end)) ;

title('Amplitude Spectrum')

xlabel('f [Hz]')

ylabel('Power [mm]')

ylim auto

[B,IX] = sort(P1); %order the amplitudes

A1=B(end); %amplitude of the first peak

A2=B(end-1); %amplitude of second peak

f1=f(IX(end)); %frequency of first peak

f2=f(IX(end-1)); %frequency of second peak

AmpTab=[A1 A2];

FreTab=[f1 f2];

Bjorn Gustavsson
on 12 Nov 2020

Those high amplitudes are a noise in the signal. Not the noise in the signal. To remove such interference-components you will be better off doing it this way (remember the Fourier-transform of a real signal has symmetric real components and an anti-symmetric imaginary components, and also that the DC-component is real.):

fD = fft(data_t_tichkness(:,2)); % Discrete Fourier-transform of your data

subplot(2,1,1)

plot(abs(fD)) % Plot of its absolute values

hold on

[safD,idx] = sort(abs(fD),'descend'); % Sort in descending order, this makes indexing simpler

plot(idx(2:5),abs(fD(idx(2:5))),'r.') % DC-component will be the first, then

% the positive and negative components will

% have equal magnitudes and appear consecutively in idx

fD(idx(2:5)) = 0; % Set the Fourier-components of the first and second spike to zero.

plot(abs(fD)) % Yup, they're gone.

subplot(2,1,2)

ifD = ifft(fD); % inverse-Fourier-transform

plot(data_t_tichkness(:,2))

hold on

plot(ifD)

HTH

Bjorn Gustavsson
on 6 Dec 2020

When it comes to "semi-manually" setting the fft-coefficient to zero one has to keep in mind that the DC-component is the first in the array, then the first non-zero frequency-fourier-coefficient is the second and the last component in the array. When I do these tasks I typically get the indexing wrong in that I dont index matching pairs that have the same frequency, but miss with one or the other. This I embarrassingly still have to count up/down by listing: 2 and end, 3 and end-1, 4 and end-2, etc. Doing that you should be able to figure out if you are zeroing the conjugate pairs or if you're off by one. That typically shows up as strange results where one of the +f_i or -f_i fourier-coefficient pair are set to zero and the other not - this makes for confusing signals...

I come from image-processing, and when I need that type of low-pass filtering I typically use a simple call to conv2:

I_filtered = conv2(I_raw,conv2(ones(3)/3^3,conv2(ones(2)/2^2,ones(2)/2^2,'full'),'full'),'same');

But you can use all the more clever filter-window-utilities of matlab.

HTH

Bjorn Gustavsson
on 7 Dec 2020

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

Start Hunting!
## 0 Comments

Sign in to comment.