Question
a) (t/3). b) (2*t/100). c) (t-(5/4)). d) sinc((2*pi*t - 10*pi)/5). e) sinc (pi*t/5). f) sinc(pi*t/5)*(t/10). Do the above problems using MATLAB to create the sketches.
a) (t/3). b) (2*t/100). c) (t-(5/4)). d) sinc((2*pi*t - 10*pi)/5). e) sinc (pi*t/5). f) sinc(pi*t/5)*(t/10).
Do the above problems using MATLAB to create the sketches. Create an appropriate time vector using an increment of 0.01 seconds.
The built-in MATLAB function for (t) is called rectpuls, and the built-in MATLAB function for (t) is called tripuls.
The built-in MATLAB function sinc is defined slightly differently than the book, so use the supplied function sinc_nopi.m. below:
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;
This is explained further in the screencast "Pulse and Sinc Signals". Make sure to label all axes properly in your plots.
====Study the provided MATLAB programs entitled fft_spectrum below :=========
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
====== and plot_fft_spectrum: ===========
function [f,X] = plot_fft_spectrum(t,x,fignum)
%this function calls fft_spectrum to compute the fft of an arbitrary
%signal, and plot the magnitude and phase spectrum
%It calls the function fft_spectrum to do the computation
%INPUTS %t is the vector of time samples on which x is defined
%x is the vector of samples of the function x(t)
%fignum is the figure number you wish MATLAB to plot in
%compute the spectrum and the frequency axis values
if t(1)==0 %positive time scale
[f,X]=fft_spectrum(t,x);
else %balanced time scale, so put the t=0 value in the first element
[f,X]=fft_spectrum(t,fftshift(x));
end
figure(fignum), clf
subplot(3,1,1), plot(t,x,'b','LineWidth',2)
title('Time Signal')
ylabel('x(t)')
xlabel('Time (seconds)')
grid on
subplot(3,1,2), plot(f,abs(X),'b','LineWidth',2)
title('Magnitude Spectrum')
ylabel('|X(f)|')
xlabel('Frequency (Hz.)') axis([min(f) max(f) 0 1.2*max(abs(X))])
grid on
subplot(3,1,3),
plot(f,angle(X),'r','LineWidth',2)
title('Phase Spectrum')
ylabel('\Phi(X(f))')
xlabel('Frequency (Hz.)')
grid on
% subplot(5,1,4), plot(f,real(X),'b')
% grid on
% subplot(5,1,5), plot(f,imag(X),'r')
% grid on
Using below the program test_fft_spectrum, plot the approximate magnitude and phase spectra of the functions given in problem above from questio A to F.
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.
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
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started