Plot spectrum and time domain of ADC data.

58 visualizzazioni (ultimi 30 giorni)
Abdel
Abdel il 3 Gen 2024
Commentato: William Rose il 4 Gen 2024
I'm trying to make a script that can automate the process of reconstructing a baseband/message signal. For now, I have only made a script that can process an analog AM signal. Furthermore, I use an 18-bit converter where the full-scale voltage is 8.192 Vpp, and it has differential inputs.
I have successfully reconstructed the signal. My problem is, when I plot the signal in both time and frequency domains, the magnitude does not match the magnitude I see on the P-scope software. However, the time and frequency axes are correct. How can I adjust the level so it matches the magnitude spectrum I see on the P-scope?
P-scope software showing a signal at 4.9MHz, the magnitude is -83 dBFS. When i load the data to matlab and try to plot the signal in time and frequency i get
FSR = 8.192; % Full-Scale Range in volts peak-to-peak
bits = 18; % Number of bits
% Calculate LSB size
LSB_size = FSR / (2^bits - 1);
% Convert ADC samples to voltage
Voltage = ADC_data * LSB_size;
% Calculate the magnitude spectrum using FFT
magnitude_spectrum = abs(fft(ADC_data));
% Normalize to 0 dB (assuming max amplitude in baseband is 0 dB)
max_amp = max(20 * log10(magnitude_spectrum));
scaled_spectrum = 20 * log10(magnitude_spectrum)-max_amp;
% Plot the scaled magnitude spectrum in dB
figure;
plot(f, scaled_spectrum(1:Samples/2+1));
title('Scaled Magnitude Spectrum (dB)');
xlabel('Frequency (Hz)');
ylabel('Magnitude (dB)');
% Plot signal in time domain with y-axis
figure;
t= (0:(1/Fs):(length(Voltage)-1)/Fs);
plot(t,Voltage);
title('Signal in Time Domain');
xlabel('Time (s)');
ylabel('Amplitude');

Risposte (1)

William Rose
William Rose il 3 Gen 2024
You normalize the amplitude spectrum by assuming the peak signal amplitude is 0 db. So of course your peak plotted signal amplitude is 0 dB. What if you eliminate that step?
The screenshot you gave shows an amplitude of 0 for the time domain signal in P-scope. Can you adjust that scale, so that we can see the amplitude of the time domain signal that P-scope is working with?
There are various ways of normalizing a spectrum. I don't know how P-scope does it. In P-scope, are you plotting the amplitude spectrum or the power spectrum? I assume it is the amplitude spectrum, since that is what you compute and plot in Matlab.
Your Matlab script does not divide by the number of samples. It should, because if you don't, the fft amplitude of a two-seocnd long recording will be twice that of a 1-second recording, and so on.
Does the P-scope software shows any units for the spectrum amplitude? I don't see units on the screenshot you gave. Maybe they are cut off, or availble elsewhere. Units could help clarify what P-scope is doing. For example, if the units include sqrt(Hz) in the demnominator, then P scope is probably showing the square root of the power spectral density.
Another choice that affects the units of the spectrum is single or two-sided spectrum.
I usually don't worry about the exact values of a spectrum matching between different systems. I care more about the relative magnitudes: height of peak relative to the noise floor, ratio of signal to noise, rolloff due to filtering, etc.
If you are testing the reversibility of the transform, then the units of the frequency domain don't really matter, as long as you are consistent when you go forward and backward, between time and frequency domains.
If you attach a sample of the time domain signal ("voltage"), we can play with it, to try and reproduce the P-scope output.
You say your ADC has a full scale range of 8.192V. The signal amplitude in your time domain plot in Matlab is about 8x10^-4 Vpp. That means you are only using about 5 bits (32 levels) of the ADC to digitize the signal. But the signal that you show in your Matlab time domain plot seems to have more than 32 levels. So something is not what you say it is. Please clarify.
  2 Commenti
William Rose
William Rose il 4 Gen 2024
In my answer above, I said "But the signal that you show in your Matlab time domain plot seems to have more than 32 levels. So something is not what you say it is. Please clarify." I looked more closely at the time domain plot you provided above and now I see that it does show disc rete levels associated with digitization. The height of the levels in the plot (i.e. the value of 1 bit, or the LSB value) is about 16 . I expected LSB=8.192/(2^18-1)=31 . Can you explain this factor-of-two discrepancy? Am I mis-reading the time-domain plot you provided? Details like this are worth following, if you are trying to understand the frequency-domain amplitude displayed by P-scope.
William Rose
William Rose il 4 Gen 2024
Make a time-domain signal similar to the signal in @Abdel's image above.
% Define constants
fs=15e6; % sampling rate (Hz)
fc=4.9e6; % carrier wave frequency (Hz)
fmod=1e3; % modulation frequency (Hz)
T=8.7e-3; % signal duration (s)
A=2.4e-4; % carrier wave amplitude, before modulation (V)
m=0.75; % modulation amplitude (no units)
xMn=-1e-4; % carrier wave mean value (V)
LSB=8.192/(2^18-1); % one bit amplitude (V)
% Create signal
t=0:1/fs:T;
c=A*sin(2*pi*fc*t); % carrier wave
x=(1+m*sin(2*pi*fmod*t)).*c+xMn; % modulated signal
xADC=round(x/LSB)*LSB; % signal after digitization
% Plot signal
figure; plot(t,xADC,'-b');
grid on; xlabel ('Time (s)'); ylabel('Amplitude')
The signal above looks similar to the time domain signal in the image posted by @Abdel, except the LSB above is larger by a factor of 2 than the LSB in the image of @Abdel.
Take the Fourier transform of signal above and plot it on a dB scale.
N=length(t); % number of points in signal
f=(0:N-1)*fs/N; % frequencies for 2-sided transform
Xadc=fft(xADC-mean(xADC))/N;
XdB=20*log10(abs(Xadc)); % X (dB)
figure; plot(f,XdB,'-b'); ylim([-200 -50]);
grid on; xlabel('Frequency (Hz)'); ylabel('Amplitude (dB)');
The amplitudes above are similar to the amplitudes in the P-scope screen capture image: the peaks are around -80 dB and the noise floor is around -150 dB. You could adjust by a factor of 2 (6 dB) if you plot a single sided spectrum, instead of the 2-sided spectrum above. There could be an additional adjustment of about 3 dB if one uses rms voltage. I don't know what P-scope does.

Accedi per commentare.

Prodotti


Release

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by