Multiplying sine wave with step function

조회 수: 9 (최근 30일)
xRah
xRah 2020년 11월 5일
답변: xRah 2020년 11월 5일
Hi again!
I'm trying to produce a sampled data vector of a sine wave with the following parameters:
  • Amplitude 0.187
  • Signal Freq. 187Hz
  • Sampling rate 1600s^-1
I am running into an error and cannot figure out what the issue is with element wise multiplication of the step function and the sine wave. Code is as follows:
nn = -3:14; % index vector
uu = double(nn >= 0);% unit step
Ts = 1.6e-3;% sample time
Fs = 1600; % sample rate
t = linspace(-3, 14, Fs); % time
w = 2*pi*187; % omega
xx = 0.187*sin(w*t);% x(t) = 0.187sin(w*t)
xxuu = xx .* uu; % multiplying step function with sine wave
stem(t, xxuu)% stem plot
I am not entirely sure if this is the best way to go about this problem either. My code includes some hints I got from this site.

채택된 답변

Ameer Hamza
Ameer Hamza 2020년 11월 5일
편집: Ameer Hamza 2020년 11월 5일
I am not sure how you defined 'uu' vector. But the following code works fine
Ts = 1.6e-3;% sample time
Fs = 1600; % sample rate
t = linspace(-3, 14, Fs); % time
uu = 1*(t>=0);
w = 2*pi*187; % omega
xx = 0.187*sin(w*t);% x(t) = 0.187sin(w*t)
xxuu = xx .* uu; % multiplying step function with sine wave
stem(t, xxuu)% stem plot
  댓글 수: 3
xRah
xRah 2020년 11월 5일
oh and the index vector is supposed to be -3:14
xRah
xRah 2020년 11월 5일
i seem to have forgotten it -.-

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

추가 답변 (3개)

madhan ravi
madhan ravi 2020년 11월 5일
uu = @(nn) +(nn >= 0);
xxuu = xx .* uu(t)

Paul
Paul 2020년 11월 5일
Change one line to:
xxuu = xx .* (t >= tstep); % set tstep as the time when the unit step is applied

xRah
xRah 2020년 11월 5일
Thank you all for your input and help :)

카테고리

Help CenterFile Exchange에서 Audio Processing Algorithm Design에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by