How to remove DC component in FFT?
古いコメントを表示
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)');

採用された回答
その他の回答 (1 件)
Sateesh Kandukuri
2022 年 12 月 20 日
0 投票

Is it possible to modify this behaviour from asymmetrical to symmetrical? And then performing FFT may resolve my issue.
11 件のコメント
Image Analyst
2022 年 12 月 20 日
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
2022 年 12 月 20 日
@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
2022 年 12 月 20 日
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
2022 年 12 月 20 日
@Image Analyst, Could you please send the snippet of the code?
Image Analyst
2022 年 12 月 20 日
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
2022 年 12 月 21 日
@Image Analyst, I failed to use movmean() function correctly. I attached the input file for verification.
Image Analyst
2022 年 12 月 21 日
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
2022 年 12 月 21 日
@Image Analyst, It's working. You are a true lifesaver! Million thanks Sir.
Sateesh Kandukuri
2022 年 12 月 23 日
編集済み: Sateesh Kandukuri
2022 年 12 月 23 日
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
2022 年 12 月 23 日
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
2022 年 12 月 26 日
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?
カテゴリ
ヘルプ センター および File Exchange で Univariate Discrete Distributions についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

