Pregunta

I have a signal that is sampled at the rate of 10 000 Hz, and I need to resample it down to 4 000 Hz. In MATLAB I use a simulink model with three simple blocks: "From Workspace" with specified sample time (0.0001 s) -> "Rate Transition" with specified output sample time 0.00025 s -> "To Workspace" to save the output data. (One the rate transition block i see "No Op").

I thought that the same thing may be done using Matlab functions such as "interp1" to interpolate data but no luck. I have tried everything, and still I don't know how to implement the same functionality that "rate transition" has.

I need to write this data resampling in C#, and my question is: what is this simulink's underlying algotithm what ports data from one sampling frequency to another? Or how else can I get the effect i need?

Thanks, KP

¿Fue útil?

Solución

It seems that the Rate Transition block does not do any interpolation. It behaves like a zero-order hold when the sampling frequency is higher in the input than in the output. Thus, you could try this:

% Sampling frequency
Fs1 = 10e3;
Fs2 = 4e3;

% Load your data
y = load('yourdata'); %y=sin(0:1/Fs1:1);
Ttime = (length(y)-1)*(1/Fs1);

% X-Axis
x  = 0:1/Fs1:Ttime;
xi = 0:1/Fs2:Ttime;

% Zero-order hold
yi = zeros(length(xi),1);
jj = 1;
xi(1) = x(1);
for ii=2:length(y)
    % Update value
    if (x(ii)>=xi(jj)),
        yi(jj) = y(ii-1);
        jj = jj+1;
    end
end

% Plot
figure
hold on
scatter(x,y,'b');
scatter(xi,yi,'r');
hold off
legend('Fs=10k','Fs=4k')

The only modification with the previous code is to estimate the yi (y-axis interpolated) from a zero-order hold.

Otros consejos

You can interpolate in this way:

% Sampling frequency
Fs1 = 10e3;
Fs2 = 4e3;

% Load your data
y = load('yourdata'); %y=sin(0:1/Fs1:1);
Ttime = (length(y)-1)*(1/Fs1);

% X-Axis
x  = 0:1/Fs1:Ttime;
xi = 0:1/Fs2:Ttime;

% Interpolate
method = 'cubic';
yi = interp1(x,y,xi,method);

% Plot
figure
hold on
scatter(x,y,'b');
scatter(xi,yi,'r');
hold off
legend('Fs=10k','Fs=4k')

The main step is 'interp1' that performs one-dimension interpolation.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top