English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

how would i generate a cosine burst of frequency 2Hz, lasting 5 second in MATLAB. need the code.

2007-01-30 21:51:03 · 2 answers · asked by Anonymous in Science & Mathematics Engineering

2 answers

T = 5; %duration in seconds
Fs = 44100; %sampling rate
t = 1/Fs:1/Fs:T; %vector of time samples
F = 2; %frequency

signal = cos(2*pi*F*t); %create vector containing burst
plot(t, signal); xlabel('time, sec'), ylabel('cos(t)'); %plot it
soundsc(signal, Fs); %play it through your soundcard

You may want to apply a window too, depending on what you're doing. That's reasonably easy - something like this should do the trick:
signal = hamming(length(t)).' .* cos(2*pi*F*t);

2007-01-31 14:10:20 · answer #1 · answered by Gavin P 2 · 0 0

n=0:5T;
T= ??; -- you need to define the sampling rate like say 64
f=2;
w=2*pi*f/T;

X= cos(w*n);

i imagine you'll want a plot so:
plot(n,X)

2007-01-31 10:08:33 · answer #2 · answered by cw 3 · 0 0

fedest.com, questions and answers