%% Design a Sample-Rate Converter
% This example shows how to design sample-rate converter that uses a 3rd order Lagrange interpolation filter to convert from 44.1kHz to 48kHz.

[L,M] = rat(48/44.1);
f = fdesign.polysrc(L,M,'Fractional Delay','Np',3);
Hm = design(f,'lagrange');

%
% Original sampling frequency

Fs = 44.1e3;

%
% 9408 samples, 0.213 seconds long

n = 0:9407;

%
% Original signal, sinusoid at 1kHz

x  = sin(2*pi*1e3/Fs*n);

%
% 10241 samples, still 0.213 seconds

y = filter(Hm,x);

%
% Plot original sampled at 44.1kHz

stem(n(1:45)/Fs,x(1:45))
hold on

%
% Plot fractionally interpolated signal (48kHz) in red

stem((n(3:51)-2)/(Fs*L/M),y(3:51),'r','filled')
xlabel('Time (sec)');ylabel('Signal value')
legend('44.1 kHz sample rate','48 kHz sample rate')

% For more information about Farrow SRCs, see the "Efficient Sample Rate Conversion between Arbitrary Factors" example, efficientsrcdemo.
% Copyright 2012 The MathWorks, Inc.