How to plot the graph with different amplitudes at different frequencies?
11 views (last 30 days)
Show older comments
For the amplitude of D(w), I have used the command "simplify" and obtained that there are two different amplitudes at different frequency. At w=40pi, the absolute amplitude is 50pi, whereas at w=4960pi and w=5040pi, the amplitudes are 25pi, what should I do to plot the graph showing different amplitudes at different frequency?
%create symbolic functions x, a, b, c, d, e, f_c with independent variable t
syms x(t) a(t) h(t) b(t) c(t) d(t) e f_c(t) f_c1(t) f_c2(t) t tau
%create symbolic functions A, B, C, D, and E with independent variable w
syms A(w) B(w) C(w) D(w) E(w) w
x(t) = cos(100*pi*t);
a(t) = x(0.4*t);
h(t) = dirac(t-0.02);
b(t) = int(a(tau)*h(t-tau), 'tau', -inf, inf);
f_c(t) = 10*cos(2500*pi*t);
f_c1(t) = f_c(t);
f_c2(t) = f_c(t);
c(t) = b(t)*f_c1(t);
d(t) = c(t)*f_c2(t);
% f_c1(t)
% f_c2(t)
% figure
%
% subplot (3,1,1)
% fplot(a(t))
% xlim([-0.05 0.05]),ylim([-1.5 1.5])
% title ('Time domain of signal a(t)')
% xlabel('Time, t')
% ylabel('Amplitude, a(t)')
% grid on
%
% A(w) = fourier(a(t), w);
% w = -60*pi:0.1*pi:60*pi;
% subsA = A(w);
% % Replace Inf value with suitable value
% idx = subsA == Inf;
% subsA(idx) = pi; % choose suitable value from the expression of fourier transform.
% subplot (3,1,2)
% plot(w,real(subsA));
% ylim([0 4])
% title ('Frequency domain of signal A(\omega)')
% ylabel("\Re(A(\omega))");
% xlabel("\omega");
% xticks(-40*pi:20*pi:40*pi);
% xticklabels({'-40\pi', '-20\pi', '0', '20\pi', '40\pi'})
%
% subplot (3,1,3)
% plot(w, angle(A(w)))
% title ('Phase spectrum of signal A(\omega)')
% ylabel("\angle(A(\omega))");
% xlabel("\omega");
%
%
% figure
%
% subplot(3,1,1)
% fplot(b(t))
% xlim([-0.05 0.05]),ylim([-1.5 1.5])
% title ('Time domain of signal b(t)')
% xlabel('Time, t')
% ylabel('Amplitude, b(t)')
% grid on
%
% syms B w
% B(w) = fourier(b(t), w);
% w = -60*pi:0.1*pi:60*pi;
% subsB = B(w);
% % Replace Inf value with suitable value
% idx = abs(subsB) == Inf;
% subsB(idx) = pi; % choose suitable value from the expression of fourier transform.
% subplot (3,1,2)
% plot(w,real(subsB));
% ylim([0 4])
% title ('Frequency domain of signal B(\omega)')
% ylabel("\Re(B(\omega))");
% xlabel("\omega");
% xticks(-60*pi:20*pi:60*pi);
% xticklabels({'-40\pi', '-20\pi', '0', '20\pi', '40\pi'})
%
% subplot (3,1,3)
% plot(w, angle(B(w)))
% ylim([-4 4])
% title ('Phase spectrum of signal B(\omega)')
% ylabel("\angle(B(\omega))");
% xlabel("\omega");
% figure
%
% subplot(3,1,1)
% fplot(c(t))
% xlim([-0.05 0.05]),ylim([-12 12])
% title ('Time domain of signal c(t)')
% xlabel('Time, t')
% ylabel('Amplitude, c(t)')
% grid on
%
% syms C w
% C(w) = fourier(c(t), w);
% simplify(C(w))
% w = -2800*pi:20*pi:2800*pi;
% subsC = C(w);
% % Replace Inf value with suitable value
% idx = abs(subsC) == Inf;
% subsC(idx) = 5*pi; % choose suitable value from the expression of fourier transform.
% subplot (3,1,2)
% plot(w,real(subsC));
%
% ylim([0 20])
% title ('Frequency domain of signal C(\omega)')
% ylabel("\Re(C(\omega))");
% xlabel("\omega");
% xticks([-2540*pi -2460*pi 0 2460*pi 2540*pi]);
% xticklabels({'-2540\pi', '-2460\pi', '0', '2460\pi', '2540\pi'})
%
% subplot (3,1,3)
% plot(w, angle(C(w)))
% ylim([-4 4])
% title ('Phase spectrum of signal C(\omega)')
% ylabel("\angle(C(\omega))");
% xlabel("\omega");
figure
subplot(3,1,1)
fplot(d(t))
xlim([-0.1 0.1]),ylim([-110 110])
title ('Time domain of signal d(t)')
xlabel('Time, t')
ylabel('Amplitude, d(t)')
grid on
syms D w
D(w) = fourier(d(t), w);
w = -5040*pi:10*pi:5040*pi;
simplify(D(w))
subsD = D(w);
% Replace Inf value with suitable value
idx = abs(subsD) == Inf;
subsD(idx) = 25*pi; % choose suitable value from the expression of fourier transform.
subplot (3,1,2)
plot(w,real(subsD));
ylim([0 160])
title ('Frequency domain of signal D(\omega)')
ylabel("\Re(D(\omega))");
xlabel("\omega");
subplot (3,1,3)
plot(w, angle(D(w)))
ylim([-4 4])
title ('Phase spectrum of signal D(\omega)')
ylabel("\angle(D(\omega))");
xlabel("\omega");
This is the calculation that I have done to verify the answer.
0 Comments
Answers (1)
Sayan
on 15 Sep 2023
I understand from your query that it is required to plot the co-efficient of the "dirac" function of the fourier transform. However, in the code, all the coefficients of the "dirac" function are assigned to 25*pi. This can be found in the below code snippet.
subsD = D(w);
% Replace Inf value with suitable value
idx = abs(subsD) == Inf;
subsD(idx) = 25*pi;%%here the "idx" contains the indices of dirac functions and all the values of "subsD" corresponding to "idx" is assigned to 25*pi
The possible fix is to find the indices of the correlating angular frequency and use them to assign the correct value. This is shown in the below code snippet.
%create a function "ap" to return the indices of the corresponding
%frequency
function n=ap(f)
n=int32(((5040*pi+f)/(10*pi))+1);%as the value of "w" are in arithmetic progrssion indices are obtained using the formula
end
subsD = D(w);
%manually assign the values to the "dirac" of the corresponding frequency
subsD(ap(-5040*pi))=25*pi;
subsD(ap(5040*pi))=25*pi;
subsD(ap(-4960*pi))=25*pi;
subsD(ap(4960*pi))=25*pi;
subsD(ap(-40*pi))=50*pi;
subsD(ap(40*pi))=50*pi;
%now the amplitude of subsD can be plotted
plot(w,subsD);
Further information on "dirac" function can be found in the following MATLAB documentation:
Hope this helps in resolving the query.
0 Comments
See Also
Categories
Find more on Transforms in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!