Alex Haesche

From Class Wiki
Revision as of 14:06, 18 December 2013 by Daniel.liwag (talk | contribs) (Created page with "% Lowpass filter a discrete-time signal consisting of two sine waves. % Use MATLAB to design a lowpass FIR filter with the Parks-Mclellan % (Remez) method.Specify the passband f…")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

% Lowpass filter a discrete-time signal consisting of two sine waves.

% Use MATLAB to design a lowpass FIR filter with the Parks-Mclellan % (Remez) method.Specify the passband frequency to be 0.15? radians/sample % and the stopband frequency to be 0.25? radians/sample. Specify 1 dB of % allowable passband ripple and a stopband attenuation of 60 dB.

clc clear all close all

% Query the valid design methods for your filter specification object, d. d=fdesign.lowpass('Fp,Fst,Ap,Ast',0.15,0.25,1,60);

% Ap — amount of ripple allowed in the pass band in decibels (the default % units). % Ast — attenuation in the stop band in decibels (the default units). % Fp — frequency at the start of the pass band. Specified in normalized % frequency units. % Fst — frequency at the end of the stop band. Specified in normalized % frequency units.

% Create an FIR equiripple filter and view the filter magnitude response % with fvtool. designmethods(d);

% Create a signal consisting of the sum of two discrete-time sinusoids % with frequencies of ?/8 and ?/4 radians/sample and amplitudes of % 1 and 0.25 respectively. Filter the discrete-time signal with the FIR % equiripple filter object, Hd. Hd = design(d,'equiripple'); fvtool(Hd);

n = 0:159; x = 0.25*cos((pi/8)*n)+sin((pi/4)*n); y = filter(Hd,x); Domega = (2*pi)/160; freq = 0:(2*pi)/160:pi; xdft = fft(x); ydft = fft(y); plot(freq,abs(xdft(1:length(x)/2+1))); hold on; plot(freq,abs(ydft(1:length(y)/2+1)),'r','linewidth',2); legend('Original Signal','Highpass Signal','Location','NorthEast'); ylabel('Magnitude'); xlabel('Radians/Sample');

% Create a filter of order 10 with a 6-dB frequency of 9.6 kHz and a % sampling frequency of 48 kHz. d=fdesign.lowpass('N,Fc',10,9600,48000); designmethods(d);

% % Display filter magnitude response Hd = design(d); % Zoom in on the magnitude response to verify that the -6 dB point is at % 9.6 kHz. fvtool(Hd);

% References: % http://eeweb.poly.edu/iselesni/EL713/remez/remez.pdf % http://www.mathworks.com/help/signal/ref/fdesign.lowpass.html