How to test a low pass filter by generating a test signal?

10 views (last 30 days)
Hi,
I have designed a simple program to read in pressure versus time data from an excel file and apply a 2 Hz low pass filter and then perform an FFT on the filtered signal. My question is this: is there a way to generate an full frequency spectrum pulse so i can test the low pass filter before moving onto my own data?
here is the code i have.
if true
% code
data = xlsread('data.xlsx');
t = data(:,1);
p = data(:,2);
subplot(3,1,1);
plot(t,p);
title('Original waveform')
xlabel('Time (seconds)')
ylabel('Pressure (mmHg)')
fs=1000 %sample Freuency
fn=fs/2; % Nyquist Frequency
fc=2; % Desired Cutoff frequency (example)
[b,a]=butter(2,fc/fn); % IIR Filter coefficients, b=num, a=denom
xf=filter(b,a,data); % apply filter to x
subplot(3,1,2);
plot(t,p);
title('2 Hz low pass')
xlabel('Time (seconds)')
ylabel('Pressure (mmHg)')
L = length(xf);
NFFT = 2^nextpow2(L); % Next power of 2 from length of y
Y = fft(xf,NFFT)/L;
f = fs/2*linspace(0,1,NFFT/2+1);
% Plot single-sided amplitude spectrum.
subplot(3,1,3);
plot(f,2*abs(Y(1:NFFT/2+1)))
title('Single-Sided Amplitude Spectrum of y(t)')
xlabel('Frequency (Hz)')
ylabel('|Y(f)|')
% code
end

Accepted Answer

Star Strider
Star Strider on 1 May 2014
Use the freqz function:
[h,w] = freqz(b,a,100);
figure(1)
subplot(2,1,1)
plot(abs(h))
subplot(2,1,2)
plot(w)

More Answers (0)

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!