Bandpass filter from 3000 to 4000 Mhz
Show older comments
I was given an assignment to filter sounds from 3000-4000 Mhz using a bandpass filter, I completed it but I am not sure I am getting the correct results. The graph looks as if it is dropping from 1000 to 7000 instead of 3000-4000. As followed are my instructions and a modified version of the sample code given to us:
clear
close all
% Record your voice for 2 seconds.
% This is not mandatory. You can use any wave file
recObj = audiorecorder;
disp('Start speaking.')
recordblocking(recObj, 2);
disp('End of Recording.');
% Play back the recording.
play(recObj);
% Store data in double-precision array.
myRecording = getaudiodata(recObj);
% Plot the waveform.
figure,
plot(myRecording);
% save as wavefile
wavwrite(myRecording,'myName.wav');
%open the .wav file in matlab
[y, Fs, bits]=wavread('myName.wav'); % find out sampling rate,
% Fs = sample rate
% bits = number of bits per sample
N=length(y);
% N = number of samples
% Now generate a general plot of the frequency spectrum
f=Fs/N.*(0:N-1);
% calculate each frequency component
YY=fft(y,N);
Y=abs(YY(1:N))./(N/2);
figure,
subplot(1,2,1)
plot(f,20*log(Y))
ylabel('PSD');
xlabel('Frequency(Hz)');
title('original');
%The following code implements a tenth order (ten pole) low pass
%Butterworth filter with a cutoff frequency of 3400Hz.
%Cutoff frequencies are specified between 0.0 and 1.0 where
%1 corresponds to half the sampling frequency: fs / 2 (4000 in our example).
%For example, for a cutoff frequency of 3400Hz, we specify this as 1000/(fs/2).
%%%%%%%%this is what I changed%%%%%%%%%%%
fNq = 2*Fs;
Wn = [3000/fNq 4000/fNq];
[b,a]=butter(10,Wn);
filterBand_y=filtfilt(b,a,y);
subplot(1,2,2)
% calculate each frequency component for the altered file
YY=fft(filterBand_y,N);
Y1=abs(YY(1:N))./(N/2);
subplot(1,2,2)
plot(f,20*log(Y1))
ylabel('PSD');
xlabel('Frequency(Hz)');
title('altered');
%do playback
soundsc(filterBand_y);
%save and playback the file
wavwrite(filterBand_y,'myName_new')
Any help would be greatly appreciated
2 Comments
Stu
on 5 May 2012
Jan
on 6 May 2012
Please post the relevant code only. It needs some time to understand the relation between your question and the code, and this time is lost for answering.
Most of all it is confusing, that the comments do not match the code anymore. Therefore I cannot guess, if the code, the comments or your expectations are the problem. Of course a Butterworth filter has no sharp edges, but affects frequencies outside the band also.
Answers (1)
Wayne King
on 6 May 2012
I'm confused by your post, which talks about MHz (megahertz), but then you cite your sampling frequency as 8000 Hz.... At any rate, this is incorrect:
fNq = 2*Fs;
Wn = [3000/fNq 4000/fNq];
You should have specified
fNq = Fs/2;
Wn = [3000/fNq 4000/fNq];
Is your sampling frequency really 8000? If so then why not just do a highpass filter above 3 kHz since 4 kHz is your Nyquist.
Fs = 8000;
Wn = 3000/(Fs/2);
[b,a] = butter(10,Wn,'high');
% look at your filter
fvtool(b,a,'Fs',Fs)
Categories
Find more on Butterworth in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!