How to remove DC component in FFT?
Ältere Kommentare anzeigen
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)');

Akzeptierte Antwort
Weitere Antworten (1)
Sateesh Kandukuri
am 20 Dez. 2022
0 Stimmen

Is it possible to modify this behaviour from asymmetrical to symmetrical? And then performing FFT may resolve my issue.
11 Kommentare
Image Analyst
am 20 Dez. 2022
What would you hope the final signal would look like? And, perhaps more importantly, WHY do you need the signal to look like that?
Sateesh Kandukuri
am 20 Dez. 2022
@Image Analyst, The behaviour of my system without the excitation field in the relaxation process is like below

And the corrsponding fft is

But when I excite the system, the response follows the path of relaxation. That you can see clearly in the previous attached image. When I do the fft calculation of the excited system, the peak close to zero frequency is dominating clearly due to this issue. I can't make the initial and final points of fft to zero due to other peaks appearing close to those points.
Image Analyst
am 20 Dez. 2022
Why not juse use movmean() on the original signal with a window width that is the length of one of the small wave periods?
Sateesh Kandukuri
am 20 Dez. 2022
@Image Analyst, Could you please send the snippet of the code?
Image Analyst
am 20 Dez. 2022
Not sure how to get your signal. Attach x and y in a .mat file. It would be something like
windowWidth = 41; % Whatever
ySmooth = movmean(y, windowWidth);
Sateesh Kandukuri
am 21 Dez. 2022
@Image Analyst, I failed to use movmean() function correctly. I attached the input file for verification.
Image Analyst
am 21 Dez. 2022
Try this:
s = load('t_my.mat')
x = s.A(:, 1);
y = s.A(:, 2);
plot(x, y, 'b-')
grid on;
[peakValues, indexesOfPeaks] = findpeaks(y)
hold on;
plot(x(indexesOfPeaks), peakValues, 'rv')
windowWidth = 2 * mean(diff(indexesOfPeaks))
ySmooth = movmean(y, windowWidth);
plot(x, ySmooth, 'r-', 'LineWidth', 2)

Sateesh Kandukuri
am 21 Dez. 2022
@Image Analyst, It's working. You are a true lifesaver! Million thanks Sir.
Sateesh Kandukuri
am 23 Dez. 2022
Bearbeitet: Sateesh Kandukuri
am 23 Dez. 2022
Dear @Image Analyst, this logic is working for smoothly varying magnetization components(Mx and My). But in the case of Mz componet I got the following result.

I attached the input file for you to look over.
Image Analyst
am 23 Dez. 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
am 26 Dez. 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

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?
Kategorien
Mehr zu Parametric Spectral Estimation finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

