www.gusucode.com > dsp 案例源码程序 matlab代码 > dsp/HighpassFilteringOfSinusoidsExample.m

    %% Highpass Filtering of Sinusoids
% Highpass filter a discrete-time signal consisting of two sine waves.
%
% Create a highpass filter specification object. Specify the passband
% frequency to be 0.25π rad/sample and the stopband frequency to be
% 0.15π rad/sample. Specify 1 dB of allowable passband ripple and a
% stopband attenuation of 60 dB.

%%

d = fdesign.highpass('Fst,Fp,Ast,Ap',0.15,0.25,60,1);

%%
% Query the valid design methods for your filter specification object.

designmethods(d)

%%
% Create an FIR equiripple filter and view the filter magnitude response
% with FVTool.

Hd = design(d,'equiripple');
fvtool(Hd)

%%
% Create a signal consisting of the sum of two discrete-time sinusoids with
% frequencies of π/8 and π/4 rad/sample and amplitudes of 1 and 0.25
% respectively. Filter the discrete-time signal with the FIR equiripple
% filter object.

n = 0:159;
x = cos(pi/8*n)+0.25*sin(pi/4*n);
y = filter(Hd,x);

%%
% Plot the original and filtered signals in the frequency domain.

freq = 0:(2*pi)/160:pi;
xdft = fft(x);
ydft = fft(y);

plot(freq/pi,abs(xdft(1:length(x)/2+1)))
hold on
plot(freq/pi,abs(ydft(1:length(y)/2+1)),'r','linewidth',2)
hold off
legend('Original Signal','Lowpass Signal','Location','NorthEast')
ylabel('Magnitude')
xlabel('Normalized Frequency (\times\pi rad/sample)')