0
$\begingroup$

Using Matlab's FFT function, I am getting different Amplitude values in a particular frequeny, when I use different range of Bandpass filters centering around that particular frequency. What's wrong here? How can a particular Amplitude scale be selected?

In the following code, I calculated two FFTs of the same signal over the frequency range of (59Hz to 61Hz) and (59.98Hz to 60.02Hz) after bandpassing them in the said range.

[x_noise,fs] = audioread(h);
x_noise = x_noise(1:length(x_noise)/360); 
xlen = length(x_noise);
x_main=x_noise;

i=1;
%%
%Noise
f1=59;
f2=61;
fn=fs/2;
w1=f1/fn; 
w2=f2/fn;

[b,a]=butter(5,[w1 w2],'bandpass');
xn_har = filter(b,a,x_noise);

%FFT of Noise
X_Noise = abs(fft(xn_har));
 p = linspace(0,1000,length(X_Noise));
 figure(1)
 plot(p,X_Noise)

%% 
%Signal
f1_sig=59.98; 
f2_sig=60.02;
w1_sig=f1_sig/fn;
w2_sig =f2_sig/fn;

[b,a]=butter(5,[w1_sig w2_sig],'bandpass');
x_sig_har = filter(b,a,x_main);

%FFT of Signal
X_sig = abs(fft(x_sig_har));
q = linspace(0,1000,length(X_sig));
figure(2)
plot(q,X_sig)

But after doing FFT, the Amplitude in 60Hz seems to vary a lot. As seen in the image, one has a value of around 1600, while the other has around 1.2. Why is this happening, they are at the same frequency?

enter image description hereenter image description here

$\endgroup$
1
$\begingroup$

The problem is likely to be your filter. Designing a very narrow filter is very hard; a very large order is required and even then, some responses may simply be unrealizable. Note that "narrow" here is relative to the Nyquist frequency. I don't know what your sampling frequency is, but let's assume 8000 Hz. Run this code:

fn=4000;f1=59;f2=61;w1=f1/fn;w2=f2/fn;
b=butter(5,[w1 w2],'bandpass');
freqz(b);

The command freqz plots the actual frequency response of the filter that was returned by butter. It is very important always to verify that your filters' response resemble what you had in mind -- that is, that they meet your requirements.

I got slightly better results using fir1 instead of butter. However, in your case, what I would try to do is to downsample the signal so that, relative to the Nyquist frequency, the filter is not too narrow. To see the effect, run this code:

fn=120;
f1=59;f2=61;w1=f1/fn;w2=f2/fn;
b=fir1(200,[w1 w2],'bandpass');
freqz(b)

You'll see a nice, narrow response with 0 dB gain at the center frequency and around -70 dB rejection out of band.

$\endgroup$
  • $\begingroup$ Thanks, it helped, but I cannot upvote yet(low rep). The Sampling frequency here is 1000Hz. I still need to desing a Band Stop filter in range 59.98Hz to 60.02 Hz. But when I design it simply doesn't work. What should I do? Downsample the Data? $\endgroup$ – Rio1210 Dec 18 '15 at 10:25
  • $\begingroup$ As I said earlier, what I would try first is to downsample, and then play with fir1 until I got a filter that meets my requirements. $\endgroup$ – MBaz Dec 18 '15 at 14:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.