How to remove DC component in FFT?
259 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Wakeel Mohammed
il 9 Gen 2021
Commentato: Ajith Kumar
il 6 Gen 2025
I succesfully plotted my FFT with MATLAB discussion help. Now I could not remove the DC component at 0Hz. Which shows me a very high amplitude. Can any one suggest me an idea?
data1 = xlsread('Reading 1.xlsx') ; %Loading Sensor data from Excel file
t = data1 (1:512,2); %Selecting Time vector
s = data1 (1:512,3); %Selecting Z axis vibrations
L = numel(t); %Signal length
Ts = mean(diff(t)); %Sampling interval
Fs = 1/Ts; %Sampling frequency
Fn = Fs/2; %Nyquist frequency
FTs = fft(s)/L; %Fast fourier transform (s- data)
Fv = linspace(0,1, fix(L/2)+1)*Fn; %Frequency vector
Iv = 1:numel(Fv); %Index vector
subplot(2, 1, 1); %plotting top pane
plot(t,s); %Acceleration vs time
set(gca,'xlim',[1 50]); %Scale to fit
grid; %Grids on
title ('Acceleration vs time');
xlabel('time(s)');
ylabel('Acceleration');
subplot(2, 1, 2); %Plotting bottom pane
plot(Fv, abs(FTs(Iv))*2,'red'); %FFT - Amplitude vs Frequency
grid
title ('Fast fourier transform');
xlabel('Frequency (Hz)');
ylabel ('Amplitude (m)');
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/483193/image.jpeg)
0 Commenti
Risposta accettata
Image Analyst
il 9 Gen 2021
In the spatial domain, before fft, you can subtract the mean
Iv = Iv - mean(Iv);
In the frequency domain, you can zero out the DC component by setting it to zero
ft = fft(Iv);
ft(1) = 0;
12 Commenti
Image Analyst
il 29 Lug 2023
@AMOS, at the point where you run this line of code:
ft = fft(Iv);
Ajith Kumar
il 6 Gen 2025
Iv_new = (Iv / mean(Iv)) - 1
This removes the DC component by normalizing the signal with its mean and then centering it around zero.
Is this another possible solution?
Più risposte (1)
Sateesh Kandukuri
il 20 Dic 2022
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1236992/image.jpeg)
Is it possible to modify this behaviour from asymmetrical to symmetrical? And then performing FFT may resolve my issue.
11 Commenti
Image Analyst
il 23 Dic 2022
I had the window width be several wavelents long. How many indexes are between each of your peaks? Try having the window width be like 3 or 4 times that long.
Sateesh Kandukuri
il 26 Dic 2022
Using your suggestion, I used movmean() in the calculation of fft as
A = readmatrix('table.txt');
ts=1e-12;
My = A(:,3);
[peakValues, indexesOfPeaks] = findpeaks(My);
windowWidth = 2 * mean(diff(indexesOfPeaks));
MySmooth = movmean(My, windowWidth);
My = My - MySmooth;
N = 2^(nextpow2(length(My)));
freq = fft(My,N);
freq2 = abs(fftshift(freq));
freq3 = freq2/max(freq2);
I got the following result for My component
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1243987/image.jpeg)
Is this the right way to use movmean() function?
I've tried to understand the working of movmean() function using some arrays, but I still need clarification. Can you briefly explain with an example?
Vedere anche
Categorie
Scopri di più su Get Started with Signal Processing Toolbox in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!