Unable to 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). i have attached the question along too.

what is the mistake of the code,i have defined function.still its not working.

    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
1

There are 1 answers

0
SleuthEye On BEST ANSWER

The fft function returns a spectrum corresponding to frequencies between 0 and fs with the upper half of the spectrum (between fs/2 and fs) being a symmetry of the lower half for real-valued signals. That upper half of the spectrum is often also represented as negative frequencies between -f2/2 and 0 (such that the whole spectrum is shown between -fs/2 and fs/2). To plot the spectrum using this convention, you need to swap the upper and lower halves of the result, and generate corresponding frequency vector for the x-axis:

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]);