How do you get MATLAB to print simplified expression in command window?
Show older comments
Hello,
I am working with a time domain function and can successfully plot it (figure 1) and plot its fourier transform (figure 3).
Now, I want to have MATLAB output the simplified expression, that the figure 3 fourier graph is based on, in the command window as a function. How can I do this?
Best regards.
% starting point
%------------------------
clear all;
close all;
N=4096; % N= number of points in the FFT
t=linspace(-1/2,1/2,N); % time span = 1 second
s = 10*rectpuls(5*t)
%------------------------
% Plot the input signal s(t)
figure(1);
clf;
plot(t,s,'linewidth',2); % plot the real input signal
hold on;
line( [-1/2 1/2],[0 0] ); % x-axis line
grid on;
ymax = max( abs(s) )*1.5; % ymax = plot scale factor
axis([-1/2 1/2 -ymax ymax]); % rescale
xlabel('Time (sec)');
ylabel('Amplitude');
title('s(t) defined on 1 sec centered at 0');
%------------------------
s = fftshift(s); % reorder the input signal
S = fft(s)/N; % S = Fourier transform
S = fftshift(S); % reorder the transform
n = -100:100; % define points near the origin
Sn = S(1+(N/2)+n); % Sn = points near the origin
figure(2);
plot(t,s,'linewidth',2);
title('s(t) after rearranged by fftshift');
xlabel('Time (sec)');
ylabel('Amplitude');
energy_t = trapz(t, abs(s).^2 )
energy_f = trapz(t, abs(S).^2 )*N
%------------------------
% Plot real & imag Fourier transform S(f) near f=0
figure(3);
clf;
plot(n,real(Sn),'-b', 'markersize',2); % blue solid
hold on;
plot(n,imag(Sn),'--r','markersize',2); % red dashed
grid on;
axis([-100 100 -1.5 1.5]);
xlabel('Freq (Hz)');
ylabel('Amplitude');
title('Fourier Transform S(f)');
1 Comment
Walter Roberson
on 9 Nov 2019
What simplified expression would that be? Are you trying to detect the peaks and create an expression along the lines of "the input was the sum of these three frequencies" ?
Answers (0)
Categories
Find more on Fourier Analysis and Filtering 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!