Home > ACA-Code > ToolResample.m

ToolResample

PURPOSE ^

SYNOPSIS ^

function [x_out, t_out] = ToolResample(x, fs_out, fs_in)

DESCRIPTION ^

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [x_out, t_out] = ToolResample(x, fs_out, fs_in)
0002 
0003     if (fs_out > fs_in)
0004         omega_cutoff = fs_in / fs_out;
0005     else
0006         omega_cutoff = fs_out / fs_in;
0007     end
0008     
0009     % compute filter coefficients
0010     iOrder = 4;
0011     [b, a] = butter(iOrder, 0.9 * omega_cutoff);
0012 
0013     % time axes
0014     t_in    = (0:length(x)-1) / fs_in;
0015     t_out   = (0:round(t_in(end) * fs_out)) / fs_out;
0016     if (fs_out > fs_in)
0017         % upsample: interpolate and filter
0018         
0019         % this uses the most horrible interpolation possible
0020         x_out = interp1(t_in, x, t_out,'linear');
0021         
0022         % low pass filter
0023         x_out = filtfilt(b, a, x_out);
0024     else
0025         % downsample: filter and interpolate
0026         
0027         % low pass filter
0028         x_out = filtfilt(b, a, x);
0029         
0030         % this uses the most horrible interpolation possible
0031         x_out = interp1(t_in, x_out, t_out,'linear');
0032     end
0033 end

Generated on Fri 22-Apr-2022 20:59:51 by m2html © 2005