%% Design an Octave Band Filter
% Note: If you are using R2016a or an earlier release, replace each call to the object with the equivalent step syntax. For example, obj(x) becomes step(obj,x).
% Design a sixth order, octave-band class 0 filter with a center frequency of 1000 Hz and, a sampling frequency of 44.1 kHz.

d = fdesign.octave(1,'Class 0','N,F0',6,1000,44100)
biquad = design(d,'SystemObject',true)

% Plot the magnitude response of the filter using fvtool. The logarithmic scale for frequency is automatically set by fvtool for the octave filters.

fvtool(biquad)

% Filter a sinusoidal signal using the above designed filter. The input is a sum of two tones - one at 0.3 kHz and the other at 3 kHz. Initiatize a spectrum analyzer to view the filtered output power spectrum.

Fs = 2500;
Sineobject1 = dsp.SineWave('SamplesPerFrame',1024,...
    'SampleRate',Fs,'Frequency',100);
Sineobject2 = dsp.SineWave('SamplesPerFrame',1024,...
    'SampleRate',Fs,'Frequency',1000);

sa = dsp.SpectrumAnalyzer('SampleRate',Fs,'NumInputPorts',2,...
    'PlotAsTwoSidedSpectrum',false,'YLimits',[-250,50],...
    'ChannelNames',{'Input','FilteredOutput'},'ShowLegend',true);


% Stream the sinusoidal signal and pass it as an input to the biquadratic filter. View the input and the filtered output power spectra using the spectrum analyzer.

for Iter = 1:3000
    Sinewave1 = Sineobject1();
    Sinewave2 = Sineobject2();
    Input = Sinewave1 + Sinewave2;
    filteredOutput = biquad(Input);
    sa(Input,filteredOutput);
end

% Copyright 2012 The MathWorks, Inc.