zero‐padding at the end of the signals

조회 수: 73 (최근 30일)
MathWizardry
MathWizardry 2021년 12월 1일
댓글: Star Strider 2021년 12월 1일
Perform zero‐padding at the end of the signals in with shorter length such that the two signals will have the same length. Multiply the two signals. Plot and describe the resulting waveform.
I tried using my code however it says that "Arrays have incompatible sizes for this operation."
Matlab code:
>> Fs=7000;
>> t=[0:219]/Fs;
>> y=1.8*sin(2*pi*2300*t);
>> length(y);
>> Fs2=1400;
>> t2=[0:1/Fs2:0.349];
>> y2=exp(-t/0.060);
>> length(y2);
>> y(1,250)=0;
>> yt=y.*y2;
>> plot(t2,y)
Please help me in correcting the codes. The output waveform should be similar in the image provided.
  댓글 수: 1
MathWizardry
MathWizardry 2021년 12월 1일
This is the given:
1) 220 samples of sinusoid with frequency of 2300 Hz, amplitude of 1.8 and sampling rate is 7000Hz.
2) 350ms of an exponentially decaying signal with a time constant of 60ms; and sampling rate is 1400Hz.
they are already translated to the code as provided but then again it shows "Arrays have incompatible sizes for this operation."

댓글을 달려면 로그인하십시오.

답변 (1개)

Star Strider
Star Strider 2021년 12월 1일
With this assignment:
y(1,250)=0;
the ‘y’ vector no longer has 220 elements, it now has 250.
To illustrate, this does not create one value equal to 42 , it creates a vector the last value of which is 42:
yv(5) = 42
yv = 1×5
0 0 0 0 42
So this result is entirely expected —
Fs=7000;
t=[0:219]/Fs;
y=1.8*sin(2*pi*2300*t);
size(y)
ans = 1×2
1 220
Fs2=1400;
t2=[0:1/Fs2:0.349];
y2=exp(-t/0.060);
size(y2)
ans = 1×2
1 220
y(1,250)=0;
yt=y.*y2;
Arrays have incompatible sizes for this operation.
plot(t2,y)
With the problem now defined, I defer to you for the solution.
.
  댓글 수: 8
MathWizardry
MathWizardry 2021년 12월 1일
i need to have the same vector with the same length. i dont know what causes the error. it should have a waveform that will have a flatline at the end.
Star Strider
Star Strider 2021년 12월 1일
I have no idea what this is supposed to do.
First, it defines ‘t’ two different times with one vector about twice the length off the other vector. That will simply not work for this sort of analysis.
The solution to these problems is to define ‘t’ one time at the beginning of the code, and with a specific sampling frequency.
The best way to zero-pad is to define a zeros vector of the apprpiate length for each signal vector at the beginning of the code (so, one for the sine curve and one for the exponential function) and then assign the appropriate signal vector elements to it.
An example of that would be —
Fs = 1000;
t = linspace(0, 1, Fs);
szv = zeros(1,2*numel(t));
s = sin(2*pi*t*10);
s2 = szv;
s2(1:numel(s)) = s;
t2 = linspace(0, fix(numel(szv)/numel(s2)), numel(szv));
figure
plot(t, s)
grid
figure
plot(t2, s2)
grid
Then do all the analysis and plotting.
Also, please use a script for this rather than running everything in the Command Window.
.

댓글을 달려면 로그인하십시오.

카테고리

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