How can I transform between Time-Domain and Frequency-Domain?
7 次查看(过去 30 天)
显示 更早的评论
Hi,
I encounter the problem of transforming a shape from the time domain to the frequency domain.
I used the following commands to convert Fourier.
n1=8;
n2=72;
nt=25501;
dt=1.176470588235294e-13;
F=zeros(n1+n2+2,nt);
F1=F(n1+n2,:);
F2 = fftshift(fft(F1));
f=linspace(-10,10,length(F2));
figure(1);
plot(f, 10*log10(abs(F2)))
Please do not doubt the values entered such as 'nt' and 'dt' because all the shapes obtained in the time domain are correct and the only problem is in converting the frequency.
Let me know please.
Thank you.
回答(1 个)
TED MOSBY
2024-10-19
Hi Mohammad,
To transform a shape from the time domain to the frequency domain using the Fourier Transform in MATLAB, it seems like you're already on the right track.
Signal Initialization: Instead of initializing F to zeros, I replaced it with a random signal for demonstration. Make sure F1 contains the actual shape data you want to analyze.
Frequency Vector Calculation: The frequency vector f is derived from the sampling frequency, which is computed as Fs = 1 / dt. This provides the correct scaling for the frequency axis.
FFT Handling: The fft function is still used as you had it, but with the proper initialization for F1.
I adjusted your code with the above modifications:
% Parameters
n1 = 8;
n2 = 72;
nt = 25501;
dt = 1.176470588235294e-13;
% Initialize the time-domain signal (example: a random signal)
F = rand(n1 + n2 + 2, nt);
F1 = F(n1 + n2, :);
% Compute the Fourier Transform
F2 = fftshift(fft(F1));
% Frequency vector calculation
Fs = 1 / dt; % Sampling frequency
f = linspace(-Fs/2, Fs/2, length(F2)); % Frequency vector
% Plotting the result
figure(1);
plot(f, 10 * log10(abs(F2))); % Plot in dB scale
xlabel('Frequency (Hz)');
ylabel('Magnitude (dB)');
title('Frequency Domain Representation');
grid on;
The output should look like this:
Hope this helps!
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!