something is wrong with the X_AXIS!
Show older comments
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));
Answers (1)
Wayne King
on 2 Nov 2013
Edited: Wayne King
on 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');
Categories
Find more on Filter Analysis in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
