something is wrong with the X_AXIS!

i am trying to apply a high pass filter on wave. The filter do its job well enough but i am stuck in plotting the signal in frequency domain. It seems that something is wrong with X_AXIS. Can someone please help me in solving the error. Looking forward to your response! thankyou! :)
Fs = 24000;
disp('say something')
y = wavrecord(4*Fs,Fs);
figure
plot(y)
X =fftshift (fft(y)/length(y));
x_axis=-length (y)/2:1: length (y)/2-1;
figure
stem (x_axis, abs(X));
grid on
w = [0.16];
b= fir1(500,w,'high');
z =filter(b,1,y);
X =fftshift (fft(z)/length(z));
X_AXIS=-length (z)/2:1: length (z)/2-1;
figure
stem (X_AXIS, abs(X));

2 commentaires

sixwwwwww
sixwwwwww le 2 Nov 2013
What do you think is wrong with x-axis?
Alii
Alii le 2 Nov 2013
Thanks for the response! Well, it is not giving the proper frequency response. It is supposed to allow frequencies above 2kHz while it is allowing the frequencies of above 8kHz and is blocking frequencies from 2kHz to 8kHz.
here is FREQZ of filter

Connectez-vous pour commenter.

Réponses (1)

Wayne King
Wayne King le 2 Nov 2013
Modifié(e) : Wayne King le 2 Nov 2013
From the freqz() output, the filter has approximately the correct passband from about 2400 Hz to the Nyquist of 12 kHz. You know, you can use the sampling frequency in freq() by the way to obtain the output in Hz, which is more meaningful for you. See the documentation for freqz(), you just supply the sampling frequency, 24000, as an input argument.
The problem with your x axis is that you are just using the length of your data and not the sampling frequency. You need to use the sampling frequency in order to create a meaningful frequency vector in Hz.
I'll create and example just using simulated data.
Fs = 24000;
t = 0:1/Fs:1-1/Fs;
x = cos(2*pi*1000*t)+randn(size(t));
xdft = fftshift(fft(x)./length(x));
df = Fs/length(y);
freqvec = -Fs/2+df:df:Fs/2;
plot(freqvec,abs(xdft))
Obviously if you have a real-valued signal (here the length is even)
xdft = fft(x);
xdft = xdft(1:length(x)/2+1);
freqvec = 0:df:Fs/2;
plot(freqvec,abs(xdft))
xlabel('Hz');

Question posée :

le 2 Nov 2013

Modifié(e) :

le 2 Nov 2013

Community Treasure Hunt

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

Start Hunting!

Translated by