Prev: Save figure from GUIDE GUI
Next: Normalize
From: Shane Anderson on 15 Jul 2010 18:06 "Viral Doshi" <sweetviral(a)hotmail.com> wrote in message <ho0sk2$87v$1(a)fred.mathworks.com>... > Hello, > I have a project where I need to use a band pass filter and need a signal to go through it. > Using FDA tools, I have created a Equirpple Band Pass Filter. I generated a M-File for this band pass filter....here is the file > > function Hd = bfp1to5 > %BFP1TO5 Returns a discrete-time filter object. > > % > % M-File generated by MATLAB(R) 7.8 and the Signal Processing Toolbox 6.11. > % > % Generated on: 16-Mar-2010 23:19:07 > % > > % Equiripple Bandpass filter designed using the FIRPM function. > > % All frequency values are in kHz. > Fs = 20; % Sampling Frequency > > Fstop1 = 1; % First Stopband Frequency > Fpass1 = 1.5; % First Passband Frequency > Fpass2 = 4.5; % Second Passband Frequency > Fstop2 = 5; % Second Stopband Frequency > Dstop1 = 0.0001; % First Stopband Attenuation > Dpass = 0.057501127785; % Passband Ripple > Dstop2 = 0.0001; % Second Stopband Attenuation > dens = 20; % Density Factor > > % Calculate the order from the parameters using FIRPMORD. > [N, Fo, Ao, W] = firpmord([Fstop1 Fpass1 Fpass2 Fstop2]/(Fs/2), [0 1 ... > 0], [Dstop1 Dpass Dstop2]); > > % Calculate the coefficients using the FIRPM function. > b = firpm(N, Fo, Ao, W, {dens}); > Hd = dfilt.dffir(b); > > % [EOF] > > I have used Simulink to have a variable coming from workplace going through and a variable coming out to the workplace. > If I had to write a program to do the job rather than having a simulink, how can I take a signal, call this function and have a output? > > Any help would be highly appreciated > > V //////////////////////////////////////////////////////////////////////////////////////////////// Hi copy paste this code in the top of your M-file, without the first line, that is " function Hd = bfp1to5 ", and then give the signal to it. That is let say your signal is an array called "sig", then you program should look like this ///////////////////////////// clc; clear all; > %function Hd = bfp1to5 - now this line is not running. > %BFP1TO5 Returns a discrete-time filter object. > > % > % M-File generated by MATLAB(R) 7.8 and the Signal Processing Toolbox 6.11. > % > % Generated on: 16-Mar-2010 23:19:07 > % > > % Equiripple Bandpass filter designed using the FIRPM function. > > % All frequency values are in kHz. > Fs = 20; % Sampling Frequency > > Fstop1 = 1; % First Stopband Frequency > Fpass1 = 1.5; % First Passband Frequency > Fpass2 = 4.5; % Second Passband Frequency > Fstop2 = 5; % Second Stopband Frequency > Dstop1 = 0.0001; % First Stopband Attenuation > Dpass = 0.057501127785; % Passband Ripple > Dstop2 = 0.0001; % Second Stopband Attenuation > dens = 20; % Density Factor > > % Calculate the order from the parameters using FIRPMORD. > [N, Fo, Ao, W] = firpmord([Fstop1 Fpass1 Fpass2 Fstop2]/(Fs/2), [0 1 ... > 0], [Dstop1 Dpass Dstop2]); > > % Calculate the coefficients using the FIRPM function. > b = firpm(N, Fo, Ao, W, {dens}); > Hd = dfilt.dffir(b); > > % [EOF] > >output = filter(Hd, sig); /////////////////////////////////////////////////////// output is your filtered signal
|
Pages: 1 Prev: Save figure from GUIDE GUI Next: Normalize |