Académique Documents
Professionnel Documents
Culture Documents
%
% m-file to illustrate simple interpolation and
% decimation operations (Program 9B.1, p641)
% File name: prog9b1.m
% An Illustration of interpolation by a factor of 4
%
Fs=1000; % sampling
frequency
A=1.5; % relative
amplitudes
B=1;
f1=50; % signal
frequencies
f2=100;
t=0:1/Fs:1; % time vector
x=A*cos(2*pi*f1*t)+B*cos(2*pi*f2*t); % generate signal
y=interp(x,4); %
interpolate signal by 4
stem(x(1:25)) % plot
original signal
xlabel('Discrete time, nT ')
ylabel('Input signal level')
figure
stem(y(1:100)) % plot
interpolated signal.
xlabel('Discrete time, 4 x nT')
ylabel('Output signal level')
==========================================
%
% m-file to illustrate simple interpolation and
% decimation operations (Program 9B.2, p644).
% File name: prog9b2.m
% An Illustration of sampling rate changes using upfirdn by a
factor of 4
%
Fs=1000; % sampling
frequency
A=1.5; % relative
amplitudes
B=1;
f1=50; % signal
frequencies
f2=100;
t=0:1/Fs:1; % time vector
x=A*cos(2*pi*f1*t)+B*cos(2*pi*f2*t); %
generate signal
y=resample(x,4,1); %
interpolate signal by 4
stem(x(1:25)) % plot
original signal
xlabel('Discrete time, nT ')
ylabel('Input signal level')
figure
stem(y(1:100)) % plot
interpolated signal.
1
xlabel('Discrete time, 4 x nT')
ylabel('Interpolated output signal level')
y1=resample(y,1,4);
figure
stem(y1(1:25)) % plot
decimated signal.
xlabel('Discrete time, nT')
ylabel('Decimated output signal level')
============================================
function moptimum
clear all;
Fs = 96000; % sampling frequency in Hz
fp = 450; % passband edge frequency in Hz
dp = 0.0864; % overall passband deviation in +ve dB
ds = 60; % overall stopband deviation in +ve dB
M = 96; % overall decimation factor
===============================================
%
% m-file for working out the computational
% complexities of a 2-stage decimator
% Program name: mrate-ex1.m
%
dp=0.01; ds=0.01; dp1=dp/2; ds1=ds;
fp=5000;
Fi=1536000; F0=12000;
M=Fi/F0; M1=16; M2=8;
F1=Fi/M1; F2=F1/M2;
fs1=F1-(Fi/(2*M)); fs2=F2-(Fi/(2*M));
df1=(fs1-fp)/Fi; df2=(fs2-fp)/F1;
NUM= -10*log10(dp1*ds1)-13;
N1=(NUM/(14.6*df1)); N2=(NUM/(14.6*df2));
MPS=(N1*F1 + N2*F2); TSR = N1+N2;
M1
M2
2
fs1
fs2
df1
df2
N1
N2
MPS
======================================
p = floor(M/(2^(n-1)));
m = 1;
for i=2:p
for j=2:p
if n==2&i*j==M
R(m,1) = i; % get the 2-stage decimator factors
R(m,2) = j;
m = m + 1;
elseif n>2
for k=2:p
if n==3&i*j*k==M
R(m,1) = i; % get the 3-stage
R(m,2) = j; % decimator factors
R(m,3) = k;
m = m + 1;
elseif n>3
for l=2:p
if i*j*k*l==M
R(m,1) = i; % get the 4-
stage
R(m,2) = j; % decimator
factors
R(m,3) = k;
R(m,4) = l;
m = m + 1;
end
end
end
end
end
end
end
R = fliplr(sort(R')'); % sort the decimation factor vectors
z = zeros(1,size(R,2));
k = 1;
for i=1:size(R,1) % reject the redundancies
for j=i+1:size(R,1)
if R(i,:)==R(j,:)
R(j,:) = z;
end
end
if R(i,:)~=z
DecimationFactors(k,:) = R(i,:);
3
k = k + 1;
end
end
==========================================================
function decimation
clear all;
===========================================================
function EvalNStageDecimator(Fs,fp,dp,ds,R)
format long;
a1 = 0.005309; a2 = 0.07114; a3 = -0.4761; a4 = -0.00266;
a5 = -0.5941; a6 = -0.4278; a7 = 11.01217; a8 = 0.51244;
dp = 10^(dp/20.0)-1; ds = 10^(-ds/20.0);
Ftemp = Fs;
dp = dp/length(R);
MPS = 0; TSR = 0;
fprintf('stage\tfactor\tFi\tfp\tfs\tdp\tds\tN\n');
for i=1:length(R) % n=size(R,1) possible k-stages decimators
4
F = Ftemp/R(i);
fs = F - Fs/2/prod(R);
df = (fs - fp)/Ftemp;
Ftemp = F;
N = round((log10(ds)*(a1*log10(dp)^2+a2*log10(dp)+a3)+...
a4*log10(dp)^2+a5*log10(dp)+a6)/df-df*(a7+a8*(log10(dp)-
log10(ds)))+1);
fprintf('%d\t%d\t%d\t%d\t%d\t%-7.4f\t%-7.4f\t
%d\n',i,R(i),F,fp,fs,dp,ds,N);
MPS = MPS + N*F;
TSR = TSR + N;
end
fprintf('MPS = %d, TSR = %d\n\n',MPS,TSR);
format;
========================
function interpolation
clear all;