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] -
this question has answer here:
- matlab fft , home brewed fft 1 answer
unable obtain low pass signal , magnitude spectrum .also plot inphase , quadrature components of x(t) , envelope of x(t). have attached question along too.
what mistake of code,i have defined function.still 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 function fftseq n=length(y); f=([0:n-1]-n/2)*fs/n; % generate frequency vector plot y=fftshift(y); % swap lower , upper spectrum halves plot(f, abs(y)); xlabel('frequency'); ylabel('x(f)'); axis([-500 500]); xl=loweq(x,ts,fo);%calling function loweq plot(abs(x1)); figure = 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 lowpass equivalent of signal x % f0 center frequency. % ts 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, fft of sequence m. % sequence zero-padded meet required frequency resolution df. % ts sampling interval. output df final frequency resolution. % output m zero-padded version of input m. m 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
the fft function returns spectrum corresponding frequencies between 0 , fs upper half of spectrum (between fs/2 , fs) being symmetry of lower half real-valued signals. upper half of spectrum represented negative frequencies between -f2/2 , 0 (such whole spectrum shown between -fs/2 , fs/2). plot spectrum using convention, need swap upper , lower halves of result, , generate corresponding frequency vector x-axis:
n=length(y); f=([0:n-1]-n/2)*fs/n; % generate frequency vector plot y=fftshift(y); % swap lower , upper spectrum halves plot(f, abs(y)); xlabel('frequency'); ylabel('x(f)'); axis([-500 500]);
Comments
Post a Comment