Question

Study the provided MATLAB programs entitled fft_spectrum, plot_fft_spectrum, and test_fft_spectrum. Using the program test_fft_spectrum, plot the...

Study the provided MATLAB programs entitled fft_spectrum, plot_fft_spectrum, and test_fft_spectrum. Using the program test_fft_spectrum, plot the approximate magnitude and phase spectra of the functions given in problem 3.2-1. Adjust your time axis so that the frequency plots are scaled conveniently, and important features of the time and frequency plots are clearly visible. This can be done by experimenting with the values of N, tmin, and tmax.

And the 3.2-1 problems are:

(a) pi(t/3) (b) Delta (3x/100) (c) pi (t-5/4) (d) sinc [ (2pif - 10pi)/5] (e) sinc (pit/5); (f) sinc (pit/5 pi(t/10)

**************************************************************************************
MATLAB programs entitled fft_spectrum

function x=sinc_nopi(t)
%The built-in matlab sinc function uses the standard definition of
% sinc(x) = sin(pi*x)/(pi*x).
%In the Lathi textbook, the sinc function is defined as:
% sinc(x) = sin(x)/x.
%This function implements the Lathi version of the sinc function, the
%difference being a scaling factor of pi on the t axis
%The traditional sinc function has zero-crossings at integers (except 0)
%The Lathi defined sinc function has zero crossings at multiples of pi

x=zeros(size(t));
x(t~=0)=sin(t(t~=0))./t(t~=0);
x(t==0)=1;

**************************************************************************************
MATLAB programs entitled test_fft_spectrum


function test_fft_spectrum
%this function calls fft_spectrum to compute the fft of an arbitrary
%signal, and plot the magnitude and phase spectrum
%the input signal, x may be either real or complex valued, and is created
%by inserting your own code after line 17

%INPUTS to set
%set N, the number of samples
N=256;
%set tmin and tmax, tmin should either be -tmax or 0
tmax=20; tmin=-20;

%create the time increment and the time axis
tinc=(tmax-tmin)/N;
t=tmin:tinc:(tmax-tinc);

%INSERT CODE HERE TO CREATE THE SIGNAL x(t)
%some examples are included here and commented out
%x=rectpuls(t-5/4);
%x=tripuls(3*t/100);
x=sinc_nopi(t);
%x=sin(2*pi*16*t);
%x=exp(-t.^2*32);

[f,X] = plot_fft_spectrum(t,x,1);

E1=sum(x.^2)*tinc
finc=f(2)-f(1);
E2=sum(abs(X).^2)*finc

**************************************************************************************

MATLAB programs entitled plot_fft_spectrum

function [f,X] = fft_spectrum(t,x)
%this function uses the built-in fft to compute the frequency spectrum of a
%signal x. It also generates the appropriate frequency scale, f, and
%applies the "fftshift" so that X and f vectors are available directly for
%plotting.

%the inputs x and t should be vectors of the same length.
%the outputs, X and f will also be vectors of that length

%this program is very simple, and will only work if the time axis either starts with 0, or is
%balanced positive and negative, with 0 in the center.

%extract the parameters of t vector
N=length(x);
dt=t(2)-t(1);
%create frequency vector
df=1/(N*dt);
%note the difference between odd length and even length vectors
if rem(N,2)==0 %N even
f= ( (-N/2):(N/2-1) )*df;
else %N odd
f= ( (-(N-1)/2):((N-1)/2) )*df;
end
%find the index of the t=0 element
N0=find(t==0);

%do the fft to create the spectrum samples
%use proper shifting depending on the time scale and scale amplitude by dt
if N0==1 %time scale is nonnegative
%X=fftshift(fft(fftshift(x)))*dt;
X=fftshift(fft((x)))*dt;
elseif rem(N,2)==0 && N0==N/2+1 %time scale is balanced, N is even
X=fftshift(fft(x))*dt;
elseif rem(N,2)==1 && N0==(N+1)/2 %time scale is balanced, N is odd
X=fftshift(fft(x))*dt;
else %time scale is unbalanced, so this function won't handle it
disp('Unbalanced time scale.')
end

0 0
Add a comment Improve this question Transcribed image text
Know the answer?
Add Answer to:
Study the provided MATLAB programs entitled fft_spectrum, plot_fft_spectrum, and test_fft_spectrum. Using the program test_fft_spectrum, plot the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Need help converting the following code from Matlab into Python: N=2048; fs=4.9; t=0:1/fs:(N-1)/fs; fs1=200; t1=0:1/fs1:(N-1)/fs1; x2=0.5+0.6366.*cos(2.*pi.*t1)+0.1273.*cos(10.*pi.*t1)-0.0909.*cos(14.*pi.*t1);...

    Need help converting the following code from Matlab into Python: N=2048; fs=4.9; t=0:1/fs:(N-1)/fs; fs1=200; t1=0:1/fs1:(N-1)/fs1; x2=0.5+0.6366.*cos(2.*pi.*t1)+0.1273.*cos(10.*pi.*t1)-0.0909.*cos(14.*pi.*t1); x=0.5+0.6366.*cos(2.*pi.*t)+0.1273.*cos(10.*pi.*t)-0.0909.*cos(14.*pi.*t); X=fftshift(fft(x)); f=linspace(-fs/2,fs/2,N); plot(f,abs(X)./N); xlabel('f'); ylabel('|F(f)|'); title('magnitude spectrum of sampled signal'); x1=ifft(fftshift(X)); figure plot(t(1:100),x1(1:100)); xlabel('t'); ylabel('f(t)'); title('f(t) obtained by inverse transform'); figure plot(t1(1:1000),x2(1:1000)); xlabel('t'); ylabel('f(t)'); title('original f(t)');

  • Exercises: u used to the instructor b the end of next lab. 20 102 Plot the f(t)-sinc(20r) cos(300...

    Exercises: u used to the instructor b the end of next lab. 20 102 Plot the f(t)-sinc(20r) cos(300t)sinc (10t) cos(100t) Use the fast Fourier transform to find the magnitude and phase spectrum of the signal and plot over an appropriate range. Use appropriate values for the time interval and the sampling interval. Note that in Matlab sinc(x)-, so we need to divide the argument by n to make it match the given function. Le, sinc(20t/pi) Hint: Use the parameters from...

  • This is a MATLAB Question. Below is my base code for a Fourier Series of a...

    This is a MATLAB Question. Below is my base code for a Fourier Series of a half triangle wave. So I am being asked to isolate the first 8 components so that only those first 8 components of the half triangle function are calculated by MATLAB fft function, and then afterwards I am asked to do the same thing but with the first 20 components rather than the first 8. How do I isolate the first x number of components...

  • Write a Matlab function that argument of the function that represents the sam function that plots...

    Write a Matlab function that argument of the function that represents the sam function that plots the following signal for O<t<700Ts (where Ts is the " that represents the sampling frequency) x(t) = 2n=-50 4k,sinc(t - nt's) where kn ( 1 if n = 0 Note: sinc(x)=sin(nx)/(xx) of n0

  • Can you please help me answer Task 2.b? Please show all work. fs=44100; no_pts=8192; t=([0:no_pts-1]')/fs; y1=sin(2...

    Can you please help me answer Task 2.b? Please show all work. fs=44100; no_pts=8192; t=([0:no_pts-1]')/fs; y1=sin(2*pi*1000*t); figure; plot(t,y1); xlabel('t (second)') ylabel('y(t)') axis([0,.004,-1.2,1.2]) % constrain axis so you can actually see the wave sound(y1,fs); % play sound using windows driver. %% % Check the frequency domain signal. fr is the frequency vector and f1 is the magnitude of F{y1}. fr=([0:no_pts-1]')/no_pts*fs; %in Hz fr=fr(1:no_pts/2); % single-sided spectrum f1=abs(fft(y1)); % compute fft f1=f1(1:no_pts/2)/fs; %% % F is the continuous time Fourier. (See derivation...

  • MATLAB %% T = 1; N = 11; np = 2; dt = 0.001; tmax =...

    MATLAB %% T = 1; N = 11; np = 2; dt = 0.001; tmax = np*T; t = -tmax:dt:tmax; %% Function 1 %the following code was used to create the x(t) function xrange = floor((T/dt)/15); x1 = linspace(0,1,xrange); x2 = x1(end-1:-1:1); x3 = linspace(0,2,2*xrange); x4 = x3(end-1:-1:1); x5 = zeros(1,xrange); x6 = x1; x7 = 2*ones(1,xrange); x8 = 1+x2; x9 = -0.5*ones(1,xrange); x10 = x1/2-0.5; xtemp = [x1 x2 x3 x4 x5 x6 x7 x8 x9 x10]; ztemp =...

  • please show MATLAB code with results please MATLAB Provide printouts of the program and results where...

    please show MATLAB code with results please MATLAB Provide printouts of the program and results where you calculated the Fourier transform of the following: Each student will substitute the last two numbers from their student ID number for the letter "a" ult-a) Wribc an ID nunber 6(t+a) rect(t/a) (a/n)(sinc(at/n) expljat) cos(at) sin(at)u(t) See the attached examples Fourier Page 1 of Fourier Transform syms t w f-cos (2 *pi*t) ; fourier (f,w) ADe 2 Fourier Page 1 of Foutier Transform syms...

  • Reproduce Figures 9.2b and 9.2c on MATLAB, assuming that the square wave (Figure 9.2b) is a...

    Reproduce Figures 9.2b and 9.2c on MATLAB, assuming that the square wave (Figure 9.2b) is a periodic symmetric square wave of normalized amplitude (A=1). Each student group should decide the power spectral density level of the channel noise. Compute the Fourier transform of the periodic square wave. clear all close all %%%% T=12*pi; %number of period x=linspace(0,T); t=x/pi y0=square(x); %square wave signal y0ft=fft(y0); %calculating Fourier Transformof signal y0fts=fftshift(y0ft); y0ftFinal=abs(y0ft); AWGN= rand(size(x)); %Calculating whit noise Att=(1/3); nSig= Att*AWGN; y=y0+nSig; %Square wave...

  • Why we define ''f'' with between -fs/2 and fs/2. %fft DSB modulation; ts-1/fs tmax-(N-1)*ts; t-0:ts:tmax f--fs/2:fs/(N-1):fs/2; y2-fftshiftlftlv subplot(10,1,6) plot(f,y2) title('...

    Why we define ''f'' with between -fs/2 and fs/2. %fft DSB modulation; ts-1/fs tmax-(N-1)*ts; t-0:ts:tmax f--fs/2:fs/(N-1):fs/2; y2-fftshiftlftlv subplot(10,1,6) plot(f,y2) title('fft DSB Modulation of Signal' %fft DSB modulation; ts-1/fs tmax-(N-1)*ts; t-0:ts:tmax f--fs/2:fs/(N-1):fs/2; y2-fftshiftlftlv subplot(10,1,6) plot(f,y2) title('fft DSB Modulation of Signal'

  • To plot a figure of a function y=f(t) in an interval a and b in MATLAB,...

    To plot a figure of a function y=f(t) in an interval a and b in MATLAB, one should find n-1 points of t between a and b and then find the corresponding values to plot the figure. Below shows an example of a sin function in the range of 0 and 1 with 1000 increments, as well as the figure. >> t = 0:0.001:1; >> y = sin(2*pi*2*t); >> figure >> plot(t, y) 0 02 04 06 08 Demonstrate a...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT