How to get spectral image of .mat file?

3 visualizaciones (últimos 30 días)
john karli
john karli el 4 de Oct. de 2021
Editada: Anudeep Kumar el 16 de Mayo de 2025
I have .mat file of modulation signal and i want to plot the spectral image from it? how can i do it ?
I have attached the .mat file.

Respuestas (1)

Anudeep Kumar
Anudeep Kumar el 16 de Mayo de 2025
Editada: Anudeep Kumar el 16 de Mayo de 2025
Hey john,
I came across a MATLAB Answer that seems closely related to your question. If I understand correctly, you're looking to compute the FFT to convert a signal from the time domain to the frequency domain using the fft function and then use fftshift to center the zero frequency (DC component) in the spectrum.
Here’s a refined code snippet that should help you achieve that:
% Load the .mat file
data = load('frame_snr152PSK001.mat');
% Assuming the signal is stored in a variable named 'signal'
signal = data.frame; % Adjust this to match the actual variable name
% Sampling frequency (you need to know or define this)
Fs = 1000; % Example: 1000 Hz
% Take spectrum of the signal, and plot it.
spectrum = fft(signal);
numElements = length(spectrum)
shiftedSpectrum = fftshift(abs(spectrum));
fontSize=20;
% Plot spectrum.
% Make x axis for the spectrum. x is a frequency.
% But we'll call it f instead of x since it's a frequency.
% See example for getting frequency in the hhelp for fft().
f = (Fs / numElements) * linspace(-numElements/2, numElements/2, numElements);
% Do the plot with stem().
stem(f, shiftedSpectrum, 'r.-', 'LineWidth', 2, 'MarkerSize', 16);
% Make the plot fancy with grid, labels, etc.
grid on;
title('Spectrum Image', 'FontSize', fontSize);
xlabel('Frequency in Hertz', 'FontSize', fontSize);
ylabel('Power', 'FontSize', fontSize);
% Make bolder y axis. Y axis normally doesn't show at all except maybe on a grid line.
% line([0, 0], ylim, 'Color', 'k', 'LineWidth', 3);
% Make x and y axes go through the origina instead of at the left and bottom of the plot.
ax = gca;
ax.XTick = -480 : 30 : 480;
ax.XAxisLocation = 'origin';
ax.YAxisLocation = 'origin';
For more context please refer to the original MATLAB Answer :
And for detailed documentation on the functions ‘fft’ and ‘fftshift’ refer
Hope this helps!

Categorías

Más información sobre Spectral Measurements en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by