how to find frequency content of original, interpolated and filtered data in matlab

To find the frequency content of a signal, you can use the Fast Fourier Transform (FFT) in MATLAB. Here is an example code:

main.m
% Generate original signal
t = linspace(0, 1, 1000);
x = sin(2*pi*5*t) + sin(2*pi*10*t); % signal with 5 Hz and 10 Hz components

% Interpolate signal
tq = linspace(0, 1, 5000); % new time vector with more samples
xq = interp1(t, x, tq, 'linear');

% Filter signal
fs = 5000; % sampling frequency
f_nyquist = fs/2; % Nyquist frequency
Wn = [6, 11]/f_nyquist; % passband from 6 Hz to 11 Hz
n = 200; % filter order
b = fir1(n, Wn); % filter coefficients
xf = filter(b, 1, xq); % apply filter to interpolated signal

% Compute FFT of signals
X = fft(x);
Xq = fft(xq);
Xf = fft(xf);

% Compute frequency axis
f = (0:length(X)-1)/length(X)*fs;

% Plot results
figure
subplot(3,1,1)
plot(t, x)
title('Original Signal')
xlabel('Time (s)')
ylabel('Amplitude')
subplot(3,1,2)
plot(tq, xq)
title('Interpolated Signal')
xlabel('Time (s)')
ylabel('Amplitude')
subplot(3,1,3)
plot(tq, xf)
title('Filtered Signal')
xlabel('Time (s)')
ylabel('Amplitude')

figure
subplot(3,1,1)
plot(f, abs(X))
title('Original Signal')
xlabel('Frequency (Hz)')
ylabel('Magnitude')
xlim([0, 20])
subplot(3,1,2)
plot(f, abs(Xq))
title('Interpolated Signal')
xlabel('Frequency (Hz)')
ylabel('Magnitude')
xlim([0, 20])
subplot(3,1,3)
plot(f, abs(Xf))
title('Filtered Signal')
xlabel('Frequency (Hz)')
ylabel('Magnitude')
xlim([0, 20])
1299 chars
62 lines

This code generates a signal with 5 Hz and 10 Hz components, interpolates it to have more samples, filters it with a bandpass filter from 6 Hz to 11 Hz, and computes the FFT of the original, interpolated and filtered signals. The frequency axis is computed based on the sampling frequency, and the magnitude spectrum of each signal is plotted.

You can modify this code to work with your own signals and filters.

gistlibby LogSnag