%
% DSKFIREX
%
% W. J. Gomes III, MSEE
% University of Massachusetts, Dartmouth
% gomes_w@code80.npt.nuwc.navy.mil
%
% M-file to test the DSK_FIR function which generates a coefficients file and downloads it
% with the approiate code to C3x DSK board to run FIR filters in real-time.  This file 
% implements 3 of the MATLAB FIR filter routines in real-time using DSK_FIR.
%
% First we will make an FIR1 three-band low pass filter of order 64 with Fc1=1kHz,
% Fc2=2kHz, Fc3=4kHz, and fs=10kHz
%
close all
clear all
a=1;
frlen=1024;
fs=10e3;
Fc1=1e3;
Fc2=2e3;
Fc3=3e3;
Fc4=4e3;
f=[Fc1/(fs/2),Fc2/(fs/2),Fc3/(fs/2),Fc4/(fs/2)];
order=64;
b=fir1(order,f,'DC-0');
dsk_fir(b,fs);
disp(' ');
disp('Press any key to continue with the next FIR filter');
h=freqz(b,a,frlen);
fpl=[0:fs/2/frlen:fs/2-fs/2/frlen];
fig=figure;
plot(fpl,(10*log10(abs(h)))-57);
grid on
zoom on
title('FIR1 Two-band Low Pass Filter, order=64, fs=10kHz, Fcs=1kHz,2kHz,3kHz,4kHz');
xlabel('Frequency');
ylabel('dB');
figure(fig);
pause
close all
%
% Next we will make an FIR2 high pass filter of order 55 with Fc=1.5kHz,
% and fs=8kHz
%
fs=8e3;
Fc=1.5e3;
f=[0,Fc/(fs/2),Fc/(fs/2),1];
m=[0,0,1,1];
order=55;
b=fir2(order,f,m);
dsk_fir(b,fs);
disp(' ');
disp('Press any key to continue with the next FIR filter');
h=freqz(b,a,frlen);
fpl=[0:fs/2/frlen:fs/2-fs/2/frlen];
fig=figure;
plot(fpl,(10*log10(abs(h)))-57);
grid on
zoom on
title('FIR2 High Pass Filter, order=55, fs=8kHz, Fc=1.5kHz');
xlabel('Frequency');
ylabel('dB');
figure(fig);
pause
close all
%
% Finally we will make an REMEZ Low pass filter of order 48 with Fc=5kHz, and fs=16kHz
%
fs=16e3;
Fc1=5e3;
Fc2=5.5e3;
f=[0,Fc1/(fs/2),Fc2/(fs/2),1];
m=[1,1,0,0];
order=48;
b=remez(order,f,m);
dsk_fir(b,fs);
h=freqz(b,a,frlen);
fpl=[0:fs/2/frlen:fs/2-fs/2/frlen];
fig=figure;
plot(fpl,(20*log10(abs(h)))-57);
grid on
zoom on
title('REMEZ Low Pass Filter, order=48, fs=16kHz, Fc=5kHz');
xlabel('Frequency');
ylabel('dB');
figure(fig);
