To calculate the energy of a signal x1, we need to square each sample in the signal and sum up all the squared samples. Here's the MATLAB code to calculate the energy of the given cosine signal:
main.m259 chars9 lines
In this code, we first define the frequency (fo
), sampling rate (fs
), duration (dur
), and time vector (tvec
) of the signal. Then, we generate the cosine signal (x1
). Finally, we calculate the energy of the signal by squaring each sample in the signal (x1.^2
) and summing up all the squared samples (sum(x1.^2)
). The result is stored in the variable energy
.
gistlibby LogSnag