-1

无法获得低通信号及其幅度谱。也无法绘制 x(t) 的同相和正交分量以及 x(t) 的包络。我也附上了这个问题。

代码的错误是什么,我已经定义了函数。仍然无法正常工作。

    df=0.5;
ts=0.001;
fs=1/ts;
t=-2:0.001:2;
fo=200;
x=sinc(100*t).*cos(400*pi*t);
plot(t,x);
xlabel('time');
ylabel('x(t)');
y=fftseq(x,ts,df);%calling the function fftseq
N=length(y);
f=([0:N-1]-N/2)*fs/N; % generate frequency vector for plot
y=fftshift(y);        % swap lower and upper spectrum halves

plot(f, abs(y));
xlabel('frequency');
ylabel('x(f)');
axis([-500 500]);

xl=loweq(x,ts,fo);%calling the function loweq
plot(abs(x1));
figure
I = real(x1);%real part
Q = imag(x1);%imaginary part
plot(I);
plot(Q);
function xl=loweq(x,ts,f0)
% xl=loweq(x,ts,f0)
%LOWEQ returns the lowpass equivalent of the signal x
% f0 is the center frequency.
% ts is the sampling interval
t=[0:ts:ts*(length(x)-1)];
z=hilbert(x);
xl=z.*exp(-j*2*pi*f0*t);
end

function [M,m,df]=fftseq(m,ts,df)
% [M,m,df]=fftseq(m,ts,df)
% [M,m,df]=fftseq(m,ts)
%FFTSEQ generates M, the FFT of the sequence m.
% The sequence is zero-padded to meet the required frequency resolution df. 
% ts is the sampling interval. The output df is the final frequency resolution.
% Output m is the zero-padded version of input m. M is the FFT.
fs=1/ts;
if nargin == 2
n1=0;
else
n1=fs/df;[enter image description here][1]
end
n2=length(m);
n=2^(max(nextpow2(n1),nextpow2(n2)));
M=fft(m,n); 
m=[m,zeros(1,n-n2)];
df=fs/n;
end
4

1 回答 1

0

fft函数返回对应于 0 和 之间的频率的频谱fs,频谱的上半部分(在fs/2和之间fs)是实值信号下半部分的对称。频谱的上半部分通常也表示为-f2/2和 0 之间的负频率(因此整个频谱显示在-fs/2和之间fs/2)。要使用此约定绘制频谱,您需要交换结果的上半部分和下半部分,并为 x 轴生成相应的频率向量:

N=length(y);
f=([0:N-1]-N/2)*fs/N; % generate frequency vector for plot
y=fftshift(y);        % swap lower and upper spectrum halves

plot(f, abs(y));
xlabel('frequency');
ylabel('x(f)');
axis([-500 500]);
于 2017-09-11T14:19:53.713 回答