MATLAB CODE
_____________________________________________________________________________________________________________________________________________________________________
clear all
close all
% Example MATLAB M-file that plots a Fourier series
% Set up some input values
P = 4; %period = 2P
num_terms = 100; %approximate infinite series with finite number of terms
% Miscellaneous setup stuff
format compact; % Gets rid of extra lines in output. Optional.
% Initialize x-axis values from -1.25L to 1.25L. Middle number is step size. Make
% middle number smaller for smoother plots
t = -4:0.001:4;
x=zeros(length(t),1); % reseting original half range expanded function array
x(0<=t & t<2)=1; % forming the original half range expanded function array for the purpose of plotting only
x(2<t & t <4)=0;
x(t<0 & -2<t)=1;
x(t<-2 & t>-4)=0;
figure %plotting original half range expanded function
plot(t,x)
axis([-4.5 4.5 -0.5 1.5])
%Starting to approximate f(t)
% Initialize y-axis values. y = f(t)
f = zeros(size(x'));
% Add a0/2 to series
a0 = 1;
f = f + a0/2;
% Loop num_terms times through Fourier series, accumulating in f.
figure
for n = 1:num_terms
% Formula for an.
an = (2/(n*pi))*sin(n*pi/2);
bn=0;
% Add cosine and sine into f
f = f + an*cos(n*pi*t/P) + bn*sin(n*pi*t/P);
% Plot intermediate f. You can comment these three lines out for faster
% execution speed. The function pause(n) will pause for about n
% seconds. You can raise or lower for faster plots.
plot(t,f);
set(gca,'FontSize',16);
title(['Number of terms = ',num2str(n)]);
grid on;
if n < 5
pause(0.15);
else
pause(0.1);
end
xlabel('even approx');
end;
SOLUTION
In mathematics, a function on the real numbers is called astep function(or staircase function) if it can be written as afinite linear combination of indicator functions of intervals. Informally speaking, a step function is a piecewise constantfunction having only finitely many pieces.
You are given a finite step function xt=-1 0<t<4 1 4<t<8. Hand calculate the FS coefficients of...
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)');
Amplitude=3; fs=8000; n=0:399; t=0:1/fs: n*1/fs-1/fs; signal=3+3*cos(2*pi*1100*t)+3*cos(2*pi*2200*t)+3*cos(2*pi*3300*t); fftSignal= fft(signal); fftSignal=f ftshift (fftSignal); f=fs/2*linspace(-1,1,fs); plot(f,abs(fftsignal); xlabel('Frequency(Hz)’) ylabel('amplitude(v)') title('Spectral domain') plz code above using For ..End loop to archive the same results.
MATLAB
code starts here ---------
clear
T0=2;
w0=2*pi/T0;
f0=1/T0;
Tmax=4;
Nmax=15;
%---
i=1;
for t=-Tmax: .01:Tmax
T(i)=t;
if t>=(T0/2)
while (t>T0/2)
t=t-T0;
end
elseif t<=-(T0/2)
while (t<=-T0/2)
t=t+T0;
end
end
if abs(t)<=(T0/4)
y(i)=1;
else
y(i)=0;
end
i=i+1;
end
plot(T,y),grid, xlabel('Time (sec)'); title('y(t) square wave');
shg
disp('Hit return..');
pause
%---
a0=1/2;
F(1)=0; %dc freq
C(1)=a0;
for n=1:Nmax
a(n)=(2/(n*pi))*sin((n*pi)/2);
b(n)=0;
C(n+1)=sqrt(a(n)^2+b(n)^2);
F(n+1)=n*f0;
end
stem(F,abs,(C)), grid, title(['Line Spectrum: Harmonics = '
num2str(Nmax)]);
xlabel('Freq(Hz)'), ylabel('Cn'), shg
disp('Hit return...');
pause
%---
yest=a0*ones(1,length(T));
for n=1:Nmax
yest=yest+a(n)*cos(2*n*pi*T/T0)+b(n)*sin(2*n*pi*T/T0);...
Also :
FS (2.8)
FS (4)
FS (5)
The function f(t) is defined by -3t+6, 0<t<4 f(t) = -3, 4 < t < 5. Let f (t) denote the periodic extension of f(t), with period 5. Evaluate f (-2.3), f (O), f (7.5), f (9.2) and state the value to which the Fourier series of f (t), FS(t), converges for each of the following values: t = 0,t = 2.8, t = 4, t = 5. Enter all your answers...
Q#4: (24 points) Given the function y-f(x) shown below: na f(r) -3 (a) Calculate the period of function, T and frequency, (2TT)/T (b) Calculate the Fourier Coefficients Ao. An, and Bn of the Fourier series expansion of function, y-f(x). Here n 1, 2, 3,... (integers) (c) Write the Fourier series approximation of function, yf(x), in terms of numbers, n & x only
Q#4: (24 points) Given the function y-f(x) shown below: na f(r) -3 (a) Calculate the period of function,...
Create a file named “toneA.m” with the following MATLAB code: clear all Fs=5000; Ts=1/Fs; t=[0:Ts:0.4]; F_A=440; %Frequency of note A is 440 Hz A=sin(2*pi*F_A*t); sound(A,Fs); Type toneA at the command line and then answer the following: (a) What is the time duration of A? (b) How many elements are there in A? (c) Modify toneA.m by changing “Fs=5000” to “Fs=10000”. Can you hear any difference? (d) Create a file named “tone.m” with the following MATLAB code: function x = tone(frequency,...
function x(t) = sin(4*pi*t) 0<t<1/2 x(t) = 0 1/2<t<1 x(t) = x2(t+1) Determine ak coefficients for x(t) Plot the approximation using matlab of x(t) using ak coefficients for |k|<=11
Please answer "b" only.
%Example code
function plotFS(m);
%m = user provided number of terms desired in the Fourier series;
%this code computes the Fourier series of the function
%f(x)=0, for -pi<= x <0,
% =cos(x) for 0<= x <pi
%generate the interval from -pi to pi with step size h;
h = pi/100;
xx1=[-pi:h:0];
xx2=[0:h:pi];
xx = [xx1, xx2];
%generate the given function f so that it can be graphed
ff = [zeros(size(xx1)), cos(xx2)];
%compute the first partial sum...
Calculate the Fourier Series coefficients of x(t) = cos(2*pi*1*t) + 2*sin(2*pi*4*t). Based on your results which set of FS coefficients corresponding to the positive side of the spectra is correct. a0=0, a1=1/2, a2=1/j, a3 = 0 a1=1, a2=2, a3 = 0 a1=1/2j, a2=1/2, a3 = 0 a1=1/2, a2=2/2j, a3 = 0
3. Consider the function defined by f(x) = 1, 0 < r< a, | 0, a< x < T, where 0a < T (a) Sketch the odd and even periodic extension of f (x) on the interval -3n < x < 3« for aT/2 (b) Find the half-range Fourier sine series expansion of f(x) for arbitrary a. (e) To what value does the half-range Fourier sine series expansion converge at r a? [8 marks
3. Consider the function defined by...