how to find frequency content in matlab

In order to find the frequency content of a signal in MATLAB, you can use the Discrete Fourier Transform (DFT) provided by the built-in fft function.

Here is an example code that shows you how to calculate the frequency content of a signal:

main.m
% Define a signal
t = 0:0.001:1; % time axis
f = 10; % signal frequency in Hz
x = sin(2*pi*f*t); % signal with amplitude 1

% Plot the signal in time domain
figure;
plot(t, x);
xlabel('Time (s)');
ylabel('Amplitude');
title('Signal in time domain');

% Perform DFT on the signal
X = fft(x);
X_mag = abs(X); % Magnitude of the DFT coefficients
freq = (0:length(X)-1)*(1/length(X))*(1/(t(2)-t(1))); % Frequency axis

% Plot the frequency content of the signal
figure;
plot(freq, X_mag);
xlabel('Frequency (Hz)');
ylabel('Magnitude');
title('Signal in frequency domain');
569 chars
24 lines

The code above generates a 10 Hz signal and plots the signal in both time domain and frequency domain. In the frequency domain plot, you can see that the peak magnitude corresponds to the signal frequency of 10 Hz.

related categories

gistlibby LogSnag