From: daffidity Ming on 8 Jul 2010 17:31 Hi, I am new to Matlab and am trying to write a butterworth filter. Matlab help and Google gave me some indication as to what the code should look like but I still dont understand why it does not work. I am attempting to use a band pass filter to remove 1 frequency from a mixture of sine waves. % bandpass filter on a set of sin waves clear all; figure(1); clf; x = 0:0.1:500; y = 1.5*sin(2*pi*x/100) + 1*sin(2*pi*x/20); % frequencies present = 0.01 0.05 Hz plot(x,y, 'g'); f_nyquist = 2*pi/(0.1); n = 5 cutoff_f = [0.03 0.07]/f_nyquist %I would like the extract the 0.05 Hz sine wave [b, a] = butter(n, cutoff_f, 'bandpass'); output = filter(b, a, y); figure(3); clf; plot(x, output); Any help would be appreciated. D
From: Wayne King on 8 Jul 2010 18:07 "daffidity Ming" <adona13.alice(a)gmail.com> wrote in message <i15g2o$gg5$1(a)fred.mathworks.com>... > Hi, > > I am new to Matlab and am trying to write a butterworth filter. Matlab help and Google gave me some indication as to what the code should look like but I still dont understand why it does not work. I am attempting to use a band pass filter to remove 1 frequency from a mixture of sine waves. > > % bandpass filter on a set of sin waves > clear all; > figure(1); clf; > > x = 0:0.1:500; > > y = 1.5*sin(2*pi*x/100) + 1*sin(2*pi*x/20); % frequencies present = 0.01 0.05 Hz > plot(x,y, 'g'); > > f_nyquist = 2*pi/(0.1); > n = 5 > cutoff_f = [0.03 0.07]/f_nyquist %I would like the extract the 0.05 Hz sine wave > > [b, a] = butter(n, cutoff_f, 'bandpass'); > > output = filter(b, a, y); > figure(3); clf; > plot(x, output); > > Any help would be appreciated. > > D Hi D, How about using filter objects. x = 0:0.1:500; y = 1.5*sin(2*pi*x/100) + 1*sin(2*pi*x/20); % I'm just using your parameters--not saying it's the best filter h = fdesign.bandpass('N,F3dB1,F3dB2',10,0.03,0.07,10); D = design(h,'butter'); output = filter(D, y); plot(x,output); Hope that helps, Wayne
From: daffidity Ming on 8 Jul 2010 19:36 Thank you for pointing me in the right direction! it works and I am reading the documentation on it. "Wayne King" <wmkingty(a)gmail.com> wrote in message <i15i68$1t2$1(a)fred.mathworks.com>... > "daffidity Ming" <adona13.alice(a)gmail.com> wrote in message <i15g2o$gg5$1(a)fred.mathworks.com>... > > Hi, > > > > I am new to Matlab and am trying to write a butterworth filter. Matlab help and Google gave me some indication as to what the code should look like but I still dont understand why it does not work. I am attempting to use a band pass filter to remove 1 frequency from a mixture of sine waves. > > > > % bandpass filter on a set of sin waves > > clear all; > > figure(1); clf; > > > > x = 0:0.1:500; > > > > y = 1.5*sin(2*pi*x/100) + 1*sin(2*pi*x/20); % frequencies present = 0.01 0.05 Hz > > plot(x,y, 'g'); > > > > f_nyquist = 2*pi/(0.1); > > n = 5 > > cutoff_f = [0.03 0.07]/f_nyquist %I would like the extract the 0.05 Hz sine wave > > > > [b, a] = butter(n, cutoff_f, 'bandpass'); > > > > output = filter(b, a, y); > > figure(3); clf; > > plot(x, output); > > > > Any help would be appreciated. > > > > D > > Hi D, > > How about using filter objects. > > x = 0:0.1:500; > y = 1.5*sin(2*pi*x/100) + 1*sin(2*pi*x/20); > % I'm just using your parameters--not saying it's the best filter > h = fdesign.bandpass('N,F3dB1,F3dB2',10,0.03,0.07,10); > D = design(h,'butter'); > output = filter(D, y); > plot(x,output); > > Hope that helps, > Wayne
|
Pages: 1 Prev: inverse prediction for logistic regression? Next: colorbar title |