我正在尝试绘制斜坡函数组合的傅里叶函数 我将原始函数定义如下: x = @(t) r(t + 1) - 2 * r(t) + r(t - 1);这样我就会再次使用它。
我在尝试查找并绘制 x 的 FT 时遇到了一些问题,导致 X(w) 的幅度不符合预期。在“X1 = fft(x1)/(length(t)/100);”中的代码中我必须将 fft 乘以 100 才能获得正确的幅度,但我不明白为什么 我的新代码:
FS=50000;
t = linspace(-50,50,FS); % time-axis
w=linspace(-FS/2,FS/2,length(t)); % frequency axis
% Define the functions and parameters
r = @(t) t .* (t >= 0);
S = 7;
G = 8;
% Original signal x(t)
figure(1);
x = @(t) r(t + 1) - 2 * r(t) + r(t - 1);
x1 = x(t);
plot(t, x1, 'r-', 'LineWidth', 2);
xlabel('time in sec (t)');
ylabel('x(t)');
title('Plot of x(t)');
grid on;
xlim([-5, 5]);
% Fourier Transform
% FT of x(t)
figure(6);
X1 = fft(x1)/(length(t)/100);
R1=fftshift(X1);
plot(w, abs(R1), 'r-', 'LineWidth', 1);
xlabel('angular frequency (rad/sec)');
ylabel('amplitude');
title('Plot of X(w)');
grid on;
xlim([-50000, 50000]);
在以下 MATLAB 脚本中:
信号直接用
triang
构建
时域和谱域匹配的信号功率值
|X(f)| 的频率参考已对齐
数据提示(标记)位于主瓣和第一旁瓣上,与三角脉冲和锯齿脉冲一致,达到约 27dB。
.
clear all;close all;clc
% Fs=50kHz and signal time span 100 seconds is way to apart
Fs=50000; % [Hz] frequency
dts=1/Fs; % [s] time
.
tp1=-.1;tp2=.1; % pulse window
t1=-.5;t2=.5; % pulse + gap window
t=[t1:dts:t2]; % total pulse time window
tp=[tp1:dts:tp2]; % busy pulse time window
Tp=tp(end)-tp(1); % busy pulse delay
Ts=t(end)-t(1); % total pulse delay
np1=floor(abs(t1-tp1)/dts); % busy pulse starts
dnp=floor(Tp/dts); % busy pulse length
np2=np1+dnp; % busy pulse stops
% pulse definition
% r = @(t) t .* (t >= 0);
% fx = @(t) r(t + tp2) - dnp* dts * r(t) + r(t - tp1);
% xp=fx(tp);
xp=triang(dnp);
x=zeros(1,numel(t));
x([np1:np2-1])=xp(:);
% time domain
figure(1);
ax1=gca
plot(ax1,t,x);
title(ax1,'base pulse');xlabel(ax1,'t[s]');
exportgraphics(ax1,['upload_01.jpg'],'Resolution',100)
f=linspace(-Fs/2,Fs/2,length(t)); % [Hz] frequency points
% aligning frequency reference for X(f)
flabels=round(linspace(f(1),f(end),11)/1e3,0);
nflabels=25002+floor(flabels*1e3/50e3*numel(f));
nflabels(2:end)=10*round((nflabels(2:end))/10);
flabels=f(nflabels)+25001;
flabels(1)=0;
cellf={};
for k1=1:1:numel(flabels)
cellf{k1}=num2str(1e-2*round( f(nflabels(k1))/10));
end
Px=1/numel(x)*sum(x.^2)/Ts % [W] x(t) signal power
X1 = 1/(numel(f))*fft(x,numel(f));
X1(1)=[]; % trick to make center max(abs(X)) right on 0Hz
X=fftshift(X1);
absX=abs(X);
sum(abs(X).^2) % overall |X(f)|^2 area is signal power
% spectrum domain
figure(2)
ax2=gca
hp1=plot(10*log10(abs(X).^2))
title(' 10 LOG10 |X(f)|^2');xlabel('f [kHz]');
grid on
grid minor
ax2.XTick=flabels
ax2.XTickLabels=cellf
axis(ax2,[24925 25075 -100 -10])
datip1=datatip(ax2.Children,25000,-20.28);
datip2=datatip(ax2.Children,25015,-46.60);
exportgraphics(ax2,['upload_02.jpg'],'Resolution',100)