フィルターのクリア

USE fft(x) as a highpass filter

27 ビュー (過去 30 日間)
fcarl
fcarl 2011 年 6 月 16 日
コメント済み: Travis Morrison 2017 年 6 月 26 日
Hi,
I want to use the fft(x) function to create an highpass filter. I want to ask if the following procedure is correct:
1) take the signal x and make an fft(x).
2) Set frequencies up to 0.5 Hz to zero.
3) Make ifft(spectrum).
Is it right to set the first data points to zero or is there anything to pay attention to (e.g.: symmetry of the fft...). So if I set the first data points to zero, is this enough?
Thanks for your efforts!

採用された回答

Rick Rosson
Rick Rosson 2011 年 6 月 21 日
Here are some suggestions for improving the code.
I have inserted several new lines of code indented from the original code, and eliminated some lines of the original code by making them into comments:
signal=load(files{i});
dt = 0.008;
Fs = 1/dt;
N = size(signal,1);
dF = Fs/N;
f = (-Fs/2:dF:Fs/2-dF)';
% Band-Pass Filter:
BPF = ((lower_freq < abs(f)) & (abs(f) < upper_freq));
figure;
plot(f,BPF);
% time=0.008:0.008:size(signal,1)*0.008;
time = dt*(0:N-1)';
figure;
plot(time,signal);
% NFFT=2^nextpow2(size(signal,1));
signal=signal-mean(signal);
% spektrum = fft(signal,NFFT)/(size(signal,1));
spektrum = fftshift(fft(signal))/N;
figure;
subplot(2,1,1);
plot(f,abs(spektrum));
% spektrum(lower_freq:upper_freq,1)=0;
% spektrum(size(spektrum,1)- upper_freq+1:size(spektrum,1)-lower_freq+1,1)=0;
spektrum = BPF.*spektrum;
subplot(2,1,2);
plot(f,abs(spektrum));
% signal=ifft(spektrum); %inverse ifft
signal=ifft(ifftshift(spektrum)); %inverse ifft
HTH.
Rick
  4 件のコメント
syed aizaz
syed aizaz 2015 年 12 月 18 日
sallam sir... where is file i
Travis Morrison
Travis Morrison 2017 年 6 月 26 日
When converting back to real space you have to multiply by N. Other than that, thanks for the help!

サインインしてコメントする。

その他の回答 (5 件)

Rick Rosson
Rick Rosson 2011 年 8 月 4 日
You are welcome. If you don't mind, could you please "Accept" the answer that helped resolve this issue?
Thanks!
Rick

Rick Rosson
Rick Rosson 2011 年 6 月 16 日
Before you can solve this problem, you need to know the sampling rate (in samples per second) of the signal x. Otherwise, you will not be able to figure out how many samples of the spectrum correspond to 0.5 hertz (the cut-off frequency).
For convenience, you may want to create the variable Fs to represent the sampling rate and Fc to repreesent the cut-off frequency. For example:
Fs = 200; % samples per second
Fc = 0.5; % hertz
Also, the spectrum returned by the fft function is double-sided. By default, it corresponds to the frequencies from 0 hertz up to Fs hertz. It will be easier to implement your filter if you swap the two halves of the spectrum, so that it will correspond to -Fs/2 up to +Fs/2. You can do so using the fftshift function:
X = fftshift(fft(x));
HTH.
Rick

David Young
David Young 2011 年 6 月 17 日
You might find this demo helpful.

fcarl
fcarl 2011 年 6 月 17 日
Hi Rick,
thanks for your answer. I want to show you the case in detail:
signal=load(files{i});
time=0.008:0.008:size(signal,1)*0.008;
NFFT=2^nextpow2(size(signal,1));
signal=signal-mean(signal);
spektrum = fft(signal,NFFT)/(size(signal,1));
spektrum(lower_freq:upper_freq,1)=0;
spektrum(size(spektrum,1)-upper_freq+1:size(spektrum,1)-lower_freq+1,1)=0;
signal=ifft(spektrum); %inverse ifft
In Lines 6 & 7 I try to eliminate special frequencies. I do this at the beginning of the spectrum and the end because of the symmetry. Is this right? upper_freq and lower_freq are the upper and lower bounds of frequencies i want to set to zero!
Thanks for your efforts! fcarl
  1 件のコメント
Jiahao Luo
Jiahao Luo 2015 年 9 月 18 日
I have the same issue now, did you make it work?

サインインしてコメントする。


fcarl
fcarl 2011 年 6 月 22 日
Thanks very much! This helped me!

カテゴリ

Help Center および File ExchangeFrequency Transformations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by