Time and Frequency domain
    5 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
Hi everyone,
I have a matlab code in time domain, i want to changged to frequncy domain. What should i do? it is a little bit big codes.
Also, if you have an example of code in frequency domain and before changged (time domain), will be very useful.
Thanks in advance.
0 comentarios
Respuestas (1)
  AR
 el 27 de Mzo. de 2025
        You can convert your code from time domain to frequency domain using Fast Fourier Transform (FFT). 
You can refer to the below steps for the conversion: 
1. Identify sections of the code that handle time domain signals. 
2. Apply FFT using “fft” function to convert these signals to frequency domain.
Y = fft(signal); %Example
3. Create a frequency vector to get the output:
f = Fs * (0:(L/2)) / L; 
You can proceed with conducting the required operations such as filtering or analysis directly in the frequency domain, where convolution becomes multiplication. 
Here is an example implementation for the same: 
% Parameters 
Fs = 1000; % Sampling frequency (Hz) 
T = 1/Fs; % Sampling period (s) 
L = 1500; % Length of signal 
t = (0:L-1)*T; % Time vector 
% Create a signal 
f = 50;% Frequency of the sine wave (Hz) 
signal = 0.7*sin(2*pi*f*t); 
% Plot time-domain signal 
figure; 
subplot(2,1,1); 
plot(t, signal); 
title('Time Domain Signal'); 
xlabel('Time (s)'); 
ylabel('Amplitude'); 
% Compute Fourier Transform 
Y = fft(signal); 
% Compute two-sided spectrum and then the single-sided spectrum 
P2 = abs(Y/L); 
P1 = P2(1:L/2+1); 
P1(2:end-1) = 2*P1(2:end-1); 
% Define frequency domain 
f = Fs*(0:(L/2))/L; 
% Plot frequency-domain signal 
subplot(2,1,2); 
plot(f, P1); 
title('Frequency Domain Signal'); 
xlabel('Frequency (Hz)'); 
ylabel('|P1(f)|'); 
The waveform in the top plot is a sine wave, which is a periodic signal in time domain. The bottom waveform shows the frequency domain plot with a peak at 50 Hz. 
If you need to convert back to the time domain, use inverse of FFT by utilizing the “ifft” function. 
You can refer the below MathWorks Documentations for more information:  
0 comentarios
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


