How to plot FFT and spectrogram of I-Q data?

70 visualizaciones (últimos 30 días)
Meghna Roy Chowdhury
Meghna Roy Chowdhury el 4 de Oct. de 2023
Respondida: William Rose el 7 de Oct. de 2023
I have I-Q data of file which is stored in the variable y.
f=fopen(file,'rb');
y = fread(f);
y = y(1:2:end) + i*y(2:2:end);
I want to plot the FFT (dB on the y axis and frequency on the x axis) of this I-Q data of sampling rate Fs.
I then want to plot a spectrogram, and set the colorbar based on the noise level from the FFT.
Can someone help me with a code for this?

Respuestas (2)

William Rose
William Rose el 4 de Oct. de 2023
I assume the data is in a file called "filepath", that you want to open the file for reading (hence the "r"), and the file is in big endian format (hence the "b"). If that is correct, then do
file = 'filepath';
f=fopen(file,'r','b'); % note change in this line
y = fread(f);
fclose(f); % close the file after reading the data
Check to see that the value of f is 3 or more after the fopen() command. If not, then fopen() was not successful, and fread() will fail.
If you are still having trouble, attach the data file in a comment by using the paper clip icon above.
  3 comentarios
William Rose
William Rose el 6 de Oct. de 2023
@Meghna Roy Chowdhury, yes I can help. Will you post the file, please?
William Rose
William Rose el 6 de Oct. de 2023
Since I-Q data is complex, the FFT will not complex-conjugate-symmetric around Fs/2. That's not a problem. More later. Traveling.

Iniciar sesión para comentar.


William Rose
William Rose el 7 de Oct. de 2023
Since you did not provide the data file, I have created a complex signal y(t) composed of band-limited Gaussian noise, sampled at 1 MHz for 10 milliseconds. The real and imaginary parts are independent. Your line
y = y(1:2:end) + i*y(2:2:end);
will not work, unless you have defined i=sqrt(-1) beforehand.
This WILL do what you want, because 1i is predefined to equal sqrt(-1):
y = y(1:2:end) + 1i*y(2:2:end);
The attached script plots the FFT of the signal. One example is shown below.
I defined a variable freq2, in which the frequencies go from -Fs/2 to +Fs/2. I used it for the horizontal axis of the plot above.This is common in RF signal analysis. The variable freq goes from 0 to +Fs. You could use freq for plotting, if you prefer.
The also plots the spectrogram, with a color bar - see below. This signal's spectrogram does not change significantly with time, because the signal y is stationary (not changing, statistically, with time). You can make a signal with a chirp or some other time-dependent feature and observe its spectrogram. spectrogram() uses a frequency axis that goes from 0 to +Fs.
The dB scale for the STFT is very different from the dB scale for the FFT, for two reasons: 1. the normalization is different, and 2. the FFT is proportional to amplitude, while the STFT is proportional to power=amplitude squared.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by