Execute the function, using 11 as Non, and 8 as Noff.
function fourier_example(Non,Noff)
%this function demonstrates fourier analysis and synthesis for a simple
%periodic rectangular wave of varying duty cycle.
%Inputs: Non= integer number of seconds per period that the signal is on
% Noff = integer number of seconds per period the signal is off
t=-30:.001:30; %time scale
Nharm = 20;
%number of harmonics to calculate
%construct a periodic square-wave with desired duty cycle
x=zeros(size(t));
for k1=-Nharm:Nharm
x = x + rectpuls( (t-Non/2 - k1*(Non+Noff))/Non );
end
D0 = Non/(Non+Noff); %dc value
T0=Non+Noff; %fundamental period
f0=1/T0;
%plot the original signal
figure(1); clf
subplot(2,1,1)
plot(t,x,'b','LineWidth',2)
grid on
axis([-30 30 -1 2])
title( ['Original periodic signal T0 = ' num2str(T0) ] ) xlabel('magnitude')
ylabel('time (sec.)')
%Now compute the Fourier coefficients.
%Since Matlab doesn't allow negative array indexing, we define
% D0, Dpos and Dneg for convenience.
%We will also assume we know the solution to the integral and program it
%directly into our code for convenience.
for k=1:Nharm
Dpos(k) = (exp(-j*k*2*pi*f0*Non) - exp(-j*k*2*pi*f0*0)) / (-j*k*2*pi); Dneg(k) = (exp(j*k*2*pi*f0*Non) - exp(j*k*2*pi*f0*0)) / (j*k*2*pi);
end
figure(2);clf
subplot(2,1,1)
hold on
stem(-(1:Nharm),abs(Dneg),'b','LineWidth',2)
stem(0,abs(D0),'b','LineWidth',2)
stem((1:Nharm),abs(Dpos),'b','LineWidth',2)
grid on
hold off
xlabel('Harmonic Index')
title('Magnitude Spectrum')
subplot(2,1,2)
hold on
stem(-(1:Nharm),angle(Dneg),'b','LineWidth',2)
stem(0,angle(D0),'b','LineWidth',2)
stem((1:Nharm),angle(Dpos),'b','LineWidth',2)
grid on
hold off
xlabel('Harmonic Index')
title('Phase Spectrum (in radians)')
%Now reconstruct the original signal from sinusoids using Fourier synthesis
x_recover=D0*ones(size(x)); %start with dc component
for k=1:Nharm
e1 = exp(j*k*2*pi*f0*t);
e2 = exp(-j*k*2*pi*f0*t);
x_recover=x_recover + Dpos(k)*e1 + Dneg(k)*e2;
figure(1)
subplot(2,1,2)
plot(t,x,'b','LineWidth',2)
grid on
hold on
plot(t,x_recover,'r','LineWidth',2)
hold off
axis([-30 30 -1 2])
title( ['Reconstructed Signal with ' num2str(k) ' harmonics.' ] )
xlabel('magnitude')
ylabel('time (sec.)')
pause(1)
end
%Main Script
%Call for function fourier_example using 11 as Non, 8 as
Noff
Non = 11;
Noff = 8;
fourier_example(Non, Noff);
%Function definition
function fourier_example(Non,Noff)
%this function demonstrates fourier analysis and synthesis for a
simple
%periodic rectangular wave of varying duty cycle.
%Inputs: Non= integer number of seconds per period that the signal
is on
% Noff = integer number of seconds per period the signal is off
t=-30:.001:30; %time scale
Nharm = 20;
%number of harmonics to calculate
%construct a periodic square-wave with desired duty cycle
x=zeros(size(t));
for k1=-Nharm:Nharm
x = x + rectpuls( (t-Non/2 - k1*(Non+Noff))/Non );
end
D0 = Non/(Non+Noff); %dc value
T0=Non+Noff; %fundamental period
f0=1/T0;
%plot the original signal
figure(1);
clf
subplot(2,1,1)
plot(t,x,'b','LineWidth',2)
grid on
axis([-30 30 -1 2])
title( ['Original periodic signal T0 = ' num2str(T0) ] )
xlabel('magnitude')
ylabel('time (sec.)')
%Now compute the Fourier coefficients.
%Since Matlab doesn't allow negative array indexing, we
define
% D0, Dpos and Dneg for convenience.
%We will also assume we know the solution to the integral and
program it
%directly into our code for convenience.
for k=1:Nharm
Dpos(k) = (exp(-j*k*2*pi*f0*Non) - exp(-j*k*2*pi*f0*0)) /
(-j*k*2*pi); Dneg(k) = (exp(j*k*2*pi*f0*Non) - exp(j*k*2*pi*f0*0))
/ (j*k*2*pi);
end
figure(2);
clf
subplot(2,1,1)
hold on
stem(-(1:Nharm),abs(Dneg),'b','LineWidth',2)
stem(0,abs(D0),'b','LineWidth',2)
stem((1:Nharm),abs(Dpos),'b','LineWidth',2)
grid on
hold off
xlabel('Harmonic Index')
title('Magnitude Spectrum')
subplot(2,1,2)
hold on
stem(-(1:Nharm),angle(Dneg),'b','LineWidth',2)
stem(0,angle(D0),'b','LineWidth',2)
stem((1:Nharm),angle(Dpos),'b','LineWidth',2)
grid on
hold off
xlabel('Harmonic Index')
title('Phase Spectrum (in radians)')
%Now reconstruct the original signal from sinusoids using Fourier
synthesis
x_recover=D0*ones(size(x)); %start with dc component
for k=1:Nharm
e1 = exp(j*k*2*pi*f0*t);
e2 = exp(-j*k*2*pi*f0*t);
x_recover=x_recover + Dpos(k)*e1 + Dneg(k)*e2;
figure(1)
subplot(2,1,2)
plot(t,x,'b','LineWidth',2)
grid on
hold on
plot(t,x_recover,'r','LineWidth',2)
hold off
axis([-30 30 -1 2])
title( ['Reconstructed Signal with ' num2str(k) ' harmonics.' ]
)
xlabel('magnitude')
ylabel('time (sec.)')
pause(1)
end
end
Screenshot of Plot:


Execute the function, using 11 as Non, and 8 as Noff. function fourier_example(Non,Noff) %this function demonstrates...
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);...
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...
please help me with this MATLAB CODE and
explain to me what each line does and what is used for?
leave your comments as words, not as pictures.
.....................................................................................................................................................................
clear all; close all; % For a script file, you better start with
clear all and close all
% However, for a fucntion, you better NOT to start
% with them
%% End of cell mode example
%% Plot function
t = 0:0.1:5;
x1 = sin(2*5*t); x2 = cos(3*7*t);...
Project in matlab. I have the correct ak value but not the
correct ao value. My code is attached below also
2. Determine and plot the magnitude and phase spectrum of the Fourier series coefficients a, that is, plot ja, I as a function of discrete frequencies Jok and La, as a function of discrete frequencies fok 03 025 蓋0.2 0.15 0.1 o o5 ·10-8-6 4610 phase -2 -2 8- t= 0: .01:4; 9- to = 4; 10- fo =1/4;...
Part 1: Exponential Fourier series The following MATLAB code calculates the exponential Fourier series coefficient for the signal x(t) shown in the figure below, plots it's double sided amplitude spectrum IDn l, double sided phase spectrem LDn, and the resulting signal xn(t). 4r 4a Periodic signal x(t) 1.1 Show that the complex Fourier Series Coefficients written as: D 1.2 Use the following Matlab to general the two sided spectral line. 1.3 Execute the Matlab code with To = 2π and...
Exercise 4. Computing and displaying the Fourier Transform of a signal Later in the semester it will become useful to determine the frequency response of a signal or system by taking the Fourier Transform empirically (rather than computing it analytically). To do so we make use of the fft and fftshift commands. The fft command is an efficient implementation of the Discrete Fourier Transform (DFT) known as the Fast Fourier Transform (FFT). When the FFT is computed the samples are...
Below is the MATLAB code of low-cut shelving filter which can cut the low frequency of given music signal and low-boost shelving filter which can boost the low frequency of given music signal. Design your low-boost shelving filter and low-cut shelving filter to have noticeablly different sound. Compare the sounds of two music signals after filtering, and explain the difference in sounds briefly. If there are any mistakes in code, correct them. Low-cut shelving filter code: close all, clear all,...
NB! This task is required to be solved in matlab. this task also requires the use of the function displayDualSpectrum();
which i have pasted in the bottom. the tasks that i need help with are A), B) and C). this is a multi-part question.
Task - Frequency mixing
We use a basic signal that can be described mathematically as follows:
with this We shall then make an amplitude modulated signal: where fc is the carrier frequency. the code below specifies...
how to do laplace transform on a signal that is in frequency domain. I have a signal that is in time domain and i used fft to plot it in the frequency domain, is there a way i could plot it in s domain. I know that i could do laplace transform directly from time domain to s domain, but I need to find out are these two results match each other. Fs = 4; % samples per second dt...
I need help in MATLAB. I'm working on a circuits lab report and I want to plot the derivative of an input signal. The circuit is a differentiator OpAmp. It is receiving a triangle wave as an input and should output a square wave. (I've included my existing code.) The output formula is: Vout = -(Rf)*C*(dVin/dt) Where Rf is feedback resistance: Rf = 1*10^6; and C = 1*10^-6. EXISTING CODE: %% This section is copied, and then modified from another...