Periodogram of a square wave

Hi everyone, I'm doing a DSP project where I need to extract the THD and SNDR of a Sigma-Delta DPWM.
I'm using the MATLAB function "periodogram" on the output to do it, but it returns bad results because the output wave is a square wave and not a sine wave (which amplifies the error). How can I work around that and get the correct periodogram of a square wave?
Thank you very much!

6 Comments

it's not really a surprise that a PWM signal is a square wave, unless you apply a strong low pass filter and then you recover the input (analog) signal (like in a class D amplifier)
what is the purpose of doing the THD analysis at the PWM signal level ??
In fact my problem is not with the nature of the output, but with the fact that the "periodogram" function does not work reliably with non-sine waves. The objective is to analyse the performance of different orders (1st through 3rd and 3rd modified) of the Sigma-Delta DPWM architecture.
Periodogram works but it may not be the right tool for what you want ...
example on a variable duty cycle square wave (something that can simulate a PWM signal)
n = 1:1024;
x = round(abs(sin(pi/100*n)+0.1*randn(size(n))));
figure(1)
plot(x)
nfft = length(x);
figure(2)
periodogram(x,[],nfft)
Yes, that's what I did. The problem is that when calculating THD, SNR and SNDR the results do not show the supposed trend or magnitude of change (as per the reference paper "Quantization noise shaping in digital PWM converters" by Norris). My professor said that, since the wave is square, its discontinuities amplify the error when calculating the periodogram and invalidate the results (THD,SNR,SNDR). So my query is whether it exists a way of reducing that error.
I hope I was clear. Thank you for replying.
I don't have accss to this publication
maybe you can take contact with the authors to further discuss that topic
Gianmarco Lavacca
Gianmarco Lavacca on 31 May 2023
Edited: Gianmarco Lavacca on 31 May 2023
I don't really have the time to do that, the deadline is fairly near. I'll just own up to it in the report. Thank you very much for your help though. I'll leave the question open in case someone has suggestions.

Sign in to comment.

 Accepted Answer

akshatsood
akshatsood on 4 Sep 2023
Edited: akshatsood on 6 Sep 2023
Hi Gianmarco,
I understand that you working on a Sigma-Delta DPWM. As stated in the question, you have used periodogram on the output square wave, yet it renders bad results. As per my understanding, you can leverage the fft function to compute the Fourier transform of the square wave and then calculate the power spectral density from the Fourier coefficients.
I have assumed a random data to discuss the workaround. Here is the code snippet for you reference
frequency = 10;
duration = 1;
samplingRate = 1000;
% generating square wave
t = 0:(1/samplingRate):(duration-1/samplingRate);
squareWave = square(2*pi*frequency*t);
N = length(squareWave);
Y = fft(squareWave); % computing Fourier transform
% determinging the power spectral density (PSD)
psd = (abs(Y).^2)/N;
f = samplingRate*(0:(N/2))/N; % frequency vector
% plot the square wave and the periodogram
tiledlayout(2,1);
nexttile;
plot(t,squareWave);
ylabel('Amplitude');
title('Square Wave');
grid on;
nexttile;
plot(f, 10*log10(psd(1:N/2+1)));
xlabel('Frequency (Hz)');
ylabel('Power Spectral Density (dB/Hz)');
title('Periodogram of Square Wave');
grid on;
I believe that, following this approach would be helpful in supressing the errors and acheiving a satisfactory result for the periodogram of the square wave.
Have a look at the documentation page for fft function for better understanding
I hope this helps.

1 Comment

Thank you very much. The exam is done and gone, but i'm sure your answer will help somebody else.

Sign in to comment.

More Answers (0)

Products

Release

R2021b

Community Treasure Hunt

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

Start Hunting!