📄 filtdem.m
字号:
function slide=filtdem
% FILTDEM Filter design and filtering demo.
% This demonstration designs a filter with the Signal Processing Toolbox
% and applies it to a signal made up of harmonic components.
%
% To see it run, type 'filtdem'.
%
% See also FILTDEM2, FILTDEMO.
% Copyright (c) 1988-98 by The MathWorks, Inc.
% $Revision: 5.9 $
if nargout<1,
playshow filtdem
else
%========== Slide 1 ==========
slide(1).code={
'Fs=100;',
't=(1:100)/Fs;',
's1=sin(2*pi*t*5); s2=sin(2*pi*t*15); s3=sin(2*pi*t*30);',
' s=s1+s2+s3;',
' plot(t,s);',
' xlabel(''Time (seconds)'');',
' ylabel(''Time waveform'');',
' drawnow;',
'' };
slide(1).text={
' Press the "Start" button to see a demonstration of',
' filtering with the Signal Processing Toolbox.',
'',
' >> Fs=100;',
' >> t=(1:100)/Fs;',
' >> s1=sin(2*pi*t*5); s2=sin(2*pi*t*15); s3=sin(2*pi*t*30);',
' >> s=s1+s2+s3;',
' >> plot(t,s);'};
%========== Slide 2 ==========
slide(2).code={
};
slide(2).text={
' Here''s an example of filtering with the Signal Processing',
' Toolbox. First make a signal with three sinusoidal',
' components (at frequencies of 5, 15, and 30 Hz).',
' >> Fs=100;',
' >> t=(1:100)/Fs;',
' >> s1=sin(2*pi*t*5); s2=sin(2*pi*t*15); s3=sin(2*pi*t*30);',
' >> s=s1+s2+s3;',
' >> plot(t,s);'};
%========== Slide 3 ==========
slide(3).code={
'[b,a]=ellip(4,0.1,40,[10 20]*2/Fs);',
'[H,w]=freqz(b,a,512);',
'plot(w*Fs/(2*pi),abs(H));',
'xlabel(''Frequency (Hz)'');',
'ylabel(''Mag. of frequency response'');',
'grid;',
'drawnow;',
'' };
slide(3).text={
' To design a filter to keep the 15 Hz sinusoid and get rid',
' of the 5 and 30 Hz sinusoids, we create an eighth order',
' IIR filter with a passband from 10 to 20 Hz. Here is its',
' frequency response. The filter was created with the ELLIP',
' command.',
' >> [b,a]=ellip(4,0.1,40,[10 20]*2/Fs);',
' >> [H,w]=freqz(b,a,512);',
' >> plot(w*Fs/(2*pi),abs(H));'};
%========== Slide 4 ==========
slide(4).code={
'sf=filter(b,a,s);',
'plot(t,sf);',
'xlabel(''Time (seconds)'');',
'ylabel(''Time waveform'');',
'axis([0 1 -1 1]);',
'drawnow; pause(1);' };
slide(4).text={
'After filtering, we see the signal is a 15 Hz sinusoid,',
' exactly as expected.',
'',
' >> sf=filter(b,a,s);',
' >> plot(t,sf);',
' >> xlabel(''Time (seconds)'');',
' >> ylabel(''Time waveform'');',
' >> axis([0 1 -1 1]);'};
%========== Slide 5 ==========
slide(5).code={
'S=fft(s,512);',
'SF=fft(sf,512);',
'w=(0:255)/256*(Fs/2);',
'plot(w,abs([S(1:256)'' SF(1:256)'']));',
'xlabel(''Frequency (Hz)'');',
'ylabel(''Mag. of Fourier transform'');',
'grid;',
'' };
slide(5).text={
' Finally, here is the frequency content of the signal before and',
' after filtering. Notice the peaks at 5 and 30 Hz have been',
' effectively eliminated.',
' >> S=fft(s,512);',
' >> SF=fft(sf,512);',
' >> w=(0:255)/256*(Fs/2);',
' >> plot(w,abs([S(1:256)'' SF(1:256)'']));',
' >> xlabel(''Frequency (Hz)'');',
' >> ylabel(''Mag. of Fourier transform'');'};
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -