# Low pass filtering using MATLAB; passing frequency in Hz

I want to implement a HPF which will pass all frequencies above 150hz.

Fs = 1000;                    % Sampling frequency
T = 1/Fs;                     % Sample time
L = 1000;                     % Length of signal
t = (0:L-1)*T;                % Time vector
% Sum of a 50 Hz sinusoid and a 120 Hz sinusoid
x = 0.7*sin(2*pi*50*t) + sin(2*pi*120*t);

plot(Fs*t(1:50),x(1:50))
title('Signal')
xlabel('time (milliseconds)')

pause;

NFFT = 2^nextpow2(L); % Next power of 2 from length of y
X = fft(x,NFFT)/L;
f = Fs/2*linspace(0,1,NFFT/2+1);

% Plot single-sided amplitude spectrum.
plot(f,2*abs(X(1:NFFT/2+1)))
title('Single-Sided Amplitude Spectrum of x(t)')
xlabel('Frequency (Hz)')
ylabel('|X(f)|')

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%       Now let us see HP Filtering of this signal
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

d = fdesign.highpass('Fst,Fp,Ast,Ap,Fs', 150, 170  ,60,1, Fs);

Hd = design(d,'equiripple');
%fvtool(Hd);
x = 0.7*sin(2*pi*50*t) + sin(2*pi*120*t);
HP_Filterd_Output = filter(Hd,x);

NFFT = 2^nextpow2(L); % Next power of 2 from length of x
HP_Filtered_Freq = fft(HP_Filterd_Output,NFFT)/L;
f = Fs/2*linspace(0,1,NFFT/2+1);

% Plot single-sided amplitude spectrum of HPF.
plot(f,2*abs(HP_Filtered_Freq(1:NFFT/2+1)))
title('Single-Sided Amplitude Spectrum of HP_Filtered_Output')
xlabel('Frequency (Hz)')
ylabel('|HP_Filtered_Freq_Amplitude|')


I am getting following errors:

The 'Fst,Fp,Ast,Ap,Fs' enumerated value is invalid.

Error in ==> C:\Program
Files\MATLAB\R2010a\toolbox\signal\signal\@fdesign\@abstracttypewspecs\schema.p>set_specificationtype
at 65

Error in ==> fdesign.abstracttypewspecs.abstract_setspecs at 25
set(this, 'SpecificationType', varargin{1});

Error in ==> fdesign.abstracttypewspecs.setspecs at 8
abstract_setspecs(this, varargin{:});

Error in ==> fdesign.highpass.highpass at 106
this.setspecs(varargin{:});

Error in ==> fftExample at 75
d = fdesign.highpass('Fst,Fp,Ast,Ap,Fs', 150, 170  ,60,1, Fs);


I guess I am making some mistake in

d = fdesign.highpass('Fst,Fp,Ast,Ap,Fs', 150, 170  ,60,1, Fs);
`

where I want to enter every thing in Hz.

• This is a MATLAB programming question and thus off-topic for dsp.SE – Dilip Sarwate Jun 9 '13 at 13:44
• Have you tried removing Fs from the string 'Fst,Fp,Ast,Ap'? – Matt L. Jun 9 '13 at 19:39
• I want to pass all the frequencies in Hz. And I must pass Sampling frequency. – gpuguy Jun 10 '13 at 5:03