获得低通信号及其幅度谱,还可以绘制 x(t) 的同相和正交分量以及 x(t)[MATLAB] 的包络
obtain the low pass signal and its magnitude spectrum also to plot the inphase and quadrature components of x(t) and the envelope of x(t)[MATLAB]
无法获得低通信号及其幅度谱。也无法绘制 x(t) 的同相和正交分量以及 x(t) 的包络。
我也附上了问题。
代码有什么错误,我已经定义了function.still它不起作用。
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
fft
函数returns一个频谱对应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]);
无法获得低通信号及其幅度谱。也无法绘制 x(t) 的同相和正交分量以及 x(t) 的包络。 我也附上了问题。
代码有什么错误,我已经定义了function.still它不起作用。
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
fft
函数returns一个频谱对应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]);