필터 지우기
필터 지우기

Real time FFT & IFFT with low pass filter

조회 수: 5 (최근 30일)
Ans Hafeez
Ans Hafeez 2019년 7월 22일
댓글: Ans Hafeez 2019년 7월 22일
I am processing the signal from MPU6050. Applying FIR filter in the frequency domain and then taking IFFT to get filtered signal but getting some spikes in the output signal. Searched a lot about it and found here exit spectral leakage. Found some solutions like zero paddings and windowing but nothing is working. Can some one take a look and let me know what I am doing wrong here.
Here is what I am getting recontructed.PNG
Zoom in graph
Zoom.PNG
More Zoom
zoom2.PNG
Complete Code
close all; clear all ;clc; delete(instrfindall);
arduino=serial('COM6','BAUD', 115200);
fopen(arduino);
java.lang.Thread.sleep(0.01); % in mysec!
samples = pow2(nextpow2(5000))
sig = []; out_sig =[0]; tic; G=0; trying=0; pingpong = 0;
while 1
idn = fscanf(arduino);
xx = str2double(idn);
if isnan(xx)
fclose(arduino);
java.lang.Thread.sleep(1); % in mysec!
fopen(arduino);
java.lang.Thread.sleep(1); % in mysec!
trying = trying + 1
continue
else
sig = [sig xx];
end
if length(sig)>samples - 1
break
end
end
fclose(arduino);
plot(sig,'g'); %---------------------------->Orginal signal <---------------------------
hold on
PG = plot(out_sig,'k'); %---------------------------->Output signal <---------------------------
PG.YDataSource = 'out_sig';
SegmentLength = pow2(nextpow2(1000)) % Transform length to next pow of 2
Fs = SegmentLength;
wiin = hann(64,'symmetric');
filtcoeff = fir1(63, 20/Fs, 'low', wiin, 'scale');
firfilterimpresp = impz(filtcoeff);
filterffte = fft(firfilterimpresp,SegmentLength); % FFT of impulse response of filter/system
ChunkStart = 1;
ChunkEnd = SegmentLength;
sigblock = [];
for t = 1:samples/SegmentLength
sigblock = sig(ChunkStart:ChunkEnd);
blockfft = fft(sigblock,SegmentLength);
out_sigg = real(ifft(blockfft.*filterffte'));
out_sig = [out_sig out_sigg];
refreshdata
drawnow
ChunkStart = ChunkEnd;
ChunkEnd = ChunkEnd + SegmentLength -1 ;
end
  댓글 수: 2
Star Strider
Star Strider 2019년 7월 22일
If you want to filter in the frequency domain, the Signal Processing Toolbox has the fftfilt function.
Ans Hafeez
Ans Hafeez 2019년 7월 22일
Added following lines of code but getting same prooblem
DesignedFilt = designfilt('lowpassfir', 'FilterOrder', 32,'CutoffFrequency', 20, 'SampleRate', Fs);
out_sigg = fftfilt(DesignedFilt,sigblock,SegmentLength);
Capture.PNG

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Digital Filter Analysis에 대해 자세히 알아보기

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by