MATLAB仿真-在频谱上显示内插和抽取效果
目录
结论
内插频谱压缩,抽取频谱扩展。
2倍内插仿真
以下是2倍内插前后的频谱图对比,可以看出:
2倍内插即将原频谱2倍压缩,原40Hz处变成了20Hz,原25Hz变成了12.5Hz。
测试代码如下:
fs = 120; % sample frequency (Hz)
t = 0:1/fs:10-1/fs; % 10 second span time vector
x = (1.0)*sin(2*pi*15*t) ... % 15 Hz component
+ (1.5)*sin(2*pi*20*(t-2)) ... % 40 Hz component
+ (3.0)*sin(2*pi*25*(t-2)) ... % 40 Hz component
+ (0.5)*sin(2*pi*30*t) ... % 15 Hz component
+ (1.0)*sin(2*pi*40*(t-2)) ... % 40 Hz component
+ (1.5)*sin(2*pi*50*(t-2)) ... % 40 Hz component
+ 2.5*gallery('normaldata',size(t),4); % Gaussian noise;
y = fft(x);
n = length(x); % number of samples
y0 = fftshift(y); % shift y values
f0 = (-n/2:n/2-1)*(fs/n); % 0-centered frequency range
power0 = abs(y0).^2/n; % 0-centered power
subplot(2,1,1);plot(f0,power0)
xlabel('Frequency(Hz)')
ylabel('Power')
title('原始信号频谱');
x = interp(x,2);
y = fft(x);
n = length(x); % number of samples
y0 = fftshift(y); % shift y values
f0 = (-n/2:n/2-1)*(fs/n); % 0-centered frequency range
power0 = abs(y0).^2/n; % 0-centered power
subplot(2,1,2);plot(f0,power0)
xlabel('Frequency(Hz)')
ylabel('Power')
title('2倍内插后的频谱');
2倍抽取仿真
以下是2倍抽取前后的频谱图对比,可以看出:
2倍抽取即将原频谱2倍扩展,原30Hz变成了60Hz,原15Hz变成了30Hz。
测试代码如下:
%% Decimate a Signal
% Create a sinusoidal signal sampled at 4 kHz. Decimate it by a factor of
% four.
% Copyright 2015 The MathWorks, Inc.
%%
fs = 200;
t = 0:.00025:1;
t = 0:1/fs:1-1/fs; % 1 second span time vector
x = 0.5*sin(2*pi*1*t)+1*sin(2*pi*15*t)+1.5*sin(2*pi*30*t) +1.0*sin(2*pi*45*t)+ 0.5*sin(2*pi*60*t);
y = fft(x);
y0 = fftshift(y); % shift y values
n = length(x);
f = (-n/2:n/2-1)*(fs/n);
power = abs(y0).^2/n;
subplot(3, 1, 1); plot(f, power); title('抽取前的频谱');
xlabel('Frequency');
ylabel('Power');
fs_4 = fs ;
x_4 = decimate(x,2);
y = fft(x_4);
y_4 = fftshift(y); % shift y values
n_4 = length(x_4); % number of samples
f_4 = (-n_4/2:n_4/2-1)*(fs_4/n_4); % frequency range
power_4 = abs(y_4).^2/n_4; % power of the DFT
subplot(3, 1, 2); plot(f_4, power_4); title('2倍抽取后的频谱');
xlabel('Frequency');
ylabel('Power');