Generate trapezoidal waveform from a square waveform using convolution

Hello,
I try to generate a trapezoidal waveform from a square waveform using convolution using rectpuls() and fft() but I don't manage to obtain the good result with correct amplitude (i.e. same as the original signal). Could you please help me ?
Thank you !
Example:
t = 0:10e-6:10;
signal = 270*square(t);
trise=100e-6;
x = rectpuls(t-trise/2,trise);
conv = ifft(fft(signal).*fft(x));
figure
plot(t,signal,'k-+'); hold on
plot(t,conv,'r-s'); hold on
legend('signal', 'conv')
xlabel('Time (s)')
ylabel('Signal (-)')

 採用された回答

William Rose
William Rose 2023 年 3 月 9 日
編集済み: William Rose 2023 年 3 月 9 日

0 投票

[edit correct capitalization errors]
Your convolution worked and it did produce a trapezoidal signal. You just need to zoom in more on the transitions to see the trapezoidal shape. See zoomed-in plot below.
If you want wider transitions, then you need to make the signal x have a wider pulse. In its present form, the pulse in x is only 0.0001 time units long.

4 件のコメント

Victor Dos Santos
Victor Dos Santos 2023 年 3 月 9 日
編集済み: Victor Dos Santos 2023 年 3 月 9 日
@William Rose @Abhijeet Thanks for your answers, I know the convolution worked but as you can see the amplitude of the convolution signal does not match the square one.
The answer @Abhijeet gived me to correct the amplitude didn't work:
t = 0:10e-6:10;
amplitude = 270;
signal = amplitude*square(t);
trise = 30e-6;
x = amplitude*rectpuls(t-trise/2,trise);
conv = (1/length(signal))*ifft(fft(signal).*fft(x));
figure
plot(t,signal,'k-+'); hold on
plot(t,conv,'r-s'); hold on
legend('signal', 'conv')
xlabel('Time (s)')
ylabel('Signal (-)')
@Victor Dos Santos, if you want the convolution to have the same amplitude as the original signal, then divide by the sum of the valyues in x:
t=0:.01:10; signal=270*square(t);
trise=0.3; x=rectpuls(t-trise/2,trise);
conv=ifft(fft(signal).*fft(x))/sum(x);
figure
subplot(211), plot(t,signal,'-r.',t,conv,'-b.'); legend('signal','conv')
subplot(212), plot(t,x,'-g.'); legend('x')
Or you can normalize x before using it in the convolution, so that the area under the curve in x is one:
x=x/sum(x);
Then do the convolution, and you won't need to divide by sum(x):
conv=ifft(fft(signal).*fft(x));
Victor Dos Santos
Victor Dos Santos 2023 年 3 月 9 日
Thank you @William Rose, that's what I was looking for !
William Rose
William Rose 2023 年 3 月 9 日
@Victor Dos Santos, you're welcome.

サインインしてコメントする。

その他の回答 (0 件)

製品

リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by