clc;
clear;

// 1. Sample signal (5Hz and 50Hz)
t = 0:0.01:1;
x = sin(2*%pi*5*t) + sin(2*%pi*50*t);

// 2. FIR filter design specifications
n = 20; // Filter order
fc = 0.1; // Normalized cutoff frequency 

// 3. Design the Filters
// wfir syntax for basic windowed filter: wfir(type, order, cutoff)
h_lp = wfir('lp', n, fc); // Low Pass Filter
h_hp = wfir('hp', n, fc); // High Pass Filter

// 4. Apply Filters via Convolution
y_lp = conv(x, h_lp);
y_hp = conv(x, h_hp);

// 5. Plotting all results together
figure('BackgroundColor', [1 1 1]);

subplot(3,1,1);
plot(t, x);
title("Input Signal (5Hz + 50Hz Noise)");
xgrid();

subplot(3,1,2);
plot(y_lp);
title("Filtered Output (Low Pass - Isolated 5Hz)");
xgrid();

subplot(3,1,3);
plot(y_hp);
title("Filtered Output (High Pass - Isolated 50Hz)");
xgrid();
