amp = 3;
freq = 5;
phi = pi/4;
fs = 50;
Ts = 1/fs;
l = 1; %second samples
sineWaveFunc(amp,freq,phi,Ts,l)
plot(t, s)
xlabel('time')
ylabel('Amplitude')
title('sineWave')
myPow = calcPower(fs, freq, s);
myFFT = findFFT(s);
%calculate power
N = length(s) + 1; % to be even :)
S = fft(s,N);
SdB = 20*log10(S); % or SdB = mag2db(S);
freqs = (0:N/2-1)*fs/N;
figure(2)
plot(freqs, SdB(1:N/2))
xlabel('frequency')
ylabel('amplitude')
title('spectrum')
function sinFFT = findFFT(s)
N = length(s) + 1;
sinFFT = fft(s, N);
%plot(sinFFT, N)
end
function pow = calcPower(fs, freq,s)
Nsamp = round(fs/freq);
pow = (1/Nsamp)*sum(abs(s(1:Nsamp)).^2);
end
function [s , t] = sineWaveFunc(amp,freq,phi,Ts,l)
t = 0:Ts:l;
s = amp*sin(2*pi*freq*t + phi);
end
A blog by YouTube Scientist Explorer Wanderer SonOfTerra92 https://www.youtube.com/user/SonOfTerra92
Subscribe to:
Post Comments (Atom)
Diaries of an Aspiring Astrophysicist (DAS Astro) Podcast
Diaries of an Aspiring Astrophysicist Episode 1: The last year has been weird Episode 2: Cosmic Collisions and Gravitational Wa...
-
Visualizing confirmed exoplanet detection with Tableau. Every human child has at one point in their lives dreamed of venturing to the st...
-
How Pulsar Timing Arrays Work Best Explanation so far for how a Pulsar Timing Array Works, and it makes it look more analogous to an Inter...
-
O Brave New World I would like to take some time to talk about what many would consider to be a fringe science science. If you...
No comments:
Post a Comment