www.gusucode.com > dsp 案例源码程序 matlab代码 > dsp/ResampleASignalUsingFIRRateConverterExample.m
%% Resample a Signal using FIR Rate Converter % This example shows how to resample a 100 Hz sine wave signal by a factor % of 3:2 %% % *Note*: This example runs only in R2016b or later. If you are using an % earlier release, replace each call to the function with the equivalent % |step| syntax. For example, myObject(x) becomes step(myObject,x). hsin = dsp.SineWave(1, 100,'SampleRate', 5000,'SamplesPerFrame', 50); %% % Create a FIR rate converter filter. The default interpolation % factor is 3 and decimation factor is 2. hfirrc = dsp.FIRRateConverter; input = hsin(); output = hfirrc(input); %% % Plot the original and resampled signals. ndelay = round(length(hfirrc.Numerator)/2/hfirrc.DecimationFactor); indx = ndelay+1:length(output); x = (0:length(indx)-1)/hsin.SampleRate*hfirrc.DecimationFactor/hfirrc.InterpolationFactor; stem((0:38)/hsin.SampleRate, input(1:39)); hold on; stem(x, hfirrc.InterpolationFactor*output(indx),'r'); legend('Original','Resampled');