How to get spectral image of .mat file?

3 次查看(过去 30 天)
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.

回答(1 个)

Anudeep Kumar
Anudeep Kumar 2025-5-16
编辑:Anudeep Kumar 2025-5-16
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!

类别

Help CenterFile Exchange 中查找有关 Spectral Measurements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by