zero‐padding at the end of the signals

51 ビュー (過去 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 Center および File ExchangeSpectral Measurements についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by