Calculate the RMS for a sinusoidal wave - simulink

I want to calculate the RMS value for a sinusoidal wave by taking only 40 samples per cycle. The sampling frequency is 2 KHz and the sine frequency is 50 Hz.
Please, can anyone give me a hint?

I created the simulink model shown in the image, using the following blocks:
Sine Wave - Simulink > Sources
RMS - Simscape > Power Systems > Specialized Technology > Control & Measurements
Mux - Simulink > Signal Routing
Scope - Simulink > Sinks
In order to configure the Sine Wave block I chose a Sample Based (discrete) Sine type with an Amplitude of 10 V and 40 Samples per period, as you requested. Since you want the sine to have a frequency of 50 Hz, the Sample time must be the period of the signal T = 1/(50 Hz) = 0.02s divided by 40, which yields 5e-4 s. The remaining parameters were left at the default values.
Then, I configured the RMS block with a Fundamental frequency of 50 Hz to match the frequency of the sine wave, and changed the Initial RMS value to 0 V. The remaining parameters were left at the default values.
Finally I simulated the model for 0.08 s (4 cycles). Since the sine wave has an amplitude of 10 V, the theoretical RMS value is the amplitude divided by the square root of 2, which yields 7.07 V. The readings obtained from the scope confirm this value (purple line).
Note how the RMS block requires to wait for one period of the signal to generate the first reading. During this period, the displayed reading is the Initial RMS value that we configured previously at 0 V.

Related

Analyze frequency content of signal consisting of two sinusoidal

my friends good evening, i am trying to construct model in simulink which will analyze frequency content of signal consisting of two sinusoidal function, here is corresponding simulink model
first sinusoidal functions' parameters are :
Amplitude is 20 and frequency is 2pi30 ,sample time is 0.01(sampling frequency is 100), for the second sinusoidal function we have amplitude 30 and frequency content as 2pi10(so frequency is 10 in first and 30 in second), i have added those two signal and using Spectrum Analyzer i want to display frequency contents(if i would have possibility to use vector scope before, then i can use fft, abs and then vector scope to show result, but here when i run simulation, i got following result :
originally it shows me in KHz, i tried to replace parameters from here :
for example sampling frequency is 100 also frequency axis should be between [0,50] but no result yet, so how can i show result ? am i missing something?

sinusoidal signal with varying frequency

I want to generate a variable frequency sinusoidal signal. I am changing the frequency from 0Hz to 30Hz, but the frequency sine output increases above 30Hz during first 1 second simulation and finally after 1 second the frequency settles down to 30Hz.
Please suggest me why the frequency of the sine wave not following the frequency.
It because of simulation Sample time , It is one second.
Change the Sample time to a small number such as 0.01
It looks like you misread some parameters of chirp usage, particularly target frequency and target time.
When you work with a swept cosine sweep, target frequency will be reached at half of target time. So if you set target frequency = 30 Hz and target time = 1 s you will have 30 Hz at 0.5 s and 60 Hz at 1 s.
From Matlab documentation:
Target frequency is the instantaneous frequency of the output at half the Target time, tg/2.
Target time is the time at which the sweep reaches 2*f(tg).

How do i get all the numbers of fft bins in a defined frequency band?

I use the matlab software. To my question.
I have a audio signal, on which i am applying a STFT. I take a segment
(46 ms, specifially chosen) out of my signal y(audio signal) and use a FFT on it. Then i go to the next segment, until to end of my audio signal.
My WAV-File is 10.8526 seconds long. If I have a sample frequency of
44100Hz, this means my y is 10.8526*fs = 478599.66 which is
shown in the workspace as 478 6000 x2 double.
The length of my fft is 2048. My signal are differentiated under lower frequency band [0 300], mfb [301 5000] and hfb [5001 22050(fs/2)].
The bands are just an example and not the actual matlab code. Basicall what i want (or what I am trying to do), is to get the values of my bins in the defined frequency band and do a arithmetic mean on it.
I chose 46 ms because, I want it as long as the fft length, or nearly as long as the fft. (It is not exact).Afterwards, I want to try plotting it, but that is not important right now. Any help is appreciated.
Fourier transform of a signal in time domain in a vector of size n will return another vector of size n of same signal but in frequency domain.
Frequency domain will be from 0 (dc offset) to your sampling frequency. But you will only be able to use half of that. Second half would have same values but mirrored.
You can obtain the center frequency of each useful bin with:
f = Fs*(0:(n/2))/n;

why FFT results in high frequency range are not correct?

I am doing FFT with matlab.the time period i am doing the fft on it is 1 second and it consist of 50000 equlay spaces samples. I want to test the FFT results. so I have given an input as below (wave) which is a complex of sinosuidal waves (and I have samples it by sampling frequency of 50 KHZ)and I expect to have the frequency magnitude results as I have given in the input. the results are ok for low frequency ranges but for the higher frequency (5752 Hz and 7993 Hz) results are 5.87 and 6.7 respectively (instead of 6 and ). what Is the origin of this big mistake ? how can I improve my results ?!
Here is the code:
t = 0:1/50000:1;
wave = 100*sin(2*pi*50*t)+1*sin (2*pi*123*t)+2*sin (2*pi*203*t)+3*sin(2*pi*223*t)+4*sin(2*pi*331*t)+5*sin(2*pi*2812*t)+6*sin(2*pi*5752*t)+7*sin(2*pi*7993*t);
SPEC = fft(wave);
L = size(SPEC,2);
x= (0:L/2-1);
Half_SPEC = abs(SPEC(1:L/2))/(L/2); %% removing the mirror side and ranging the domain
plot(x,Half_SPEC);
As Oli Charlesworth has pointed out, you are taking the FFT of 50001 points, which means that the frequency spacing is 1/50001.
Typically the FFT will give you the exact magnitude of your sinusoid only if its frequency is an exact multiple of the frequency spacing. Otherwise, the energy will be spread over multiple FFT bins in a process called spectral leakage.
You may confirm this by changing the number of samples such that the frequency of your sinusoids are a multiple of the frequency spacing:
t = 0:1/50000:1-1/50000;
Windowing the input signal can also help control the amount of leakage.

relationship between peak value and rms

suppose that we have following signal:
Compute the RMS level of a 100-Hz sinusoid sampled at 1 kHz.
t = 0:0.001:1-0.001;
X = cos(2*pi*100*t);
it's spectrum is
plot(periodogram(X));
now if i want to to calculate magnitude of peak,i know that there is some relationship between root mean square(RMS) and amplitude for sinusoidal models,form this site
http://www.indiana.edu/~emusic/acoustics/amplitude.htm
Example: The rms of a sine wave with a hypothetical peak-to peak value of –1 to 1 will be 0.707. This can be used to extrapolate that any rms amplitude = 0.707 x peak amplitude. Peak amplitude = 1.414 x rms amplitude.
i can calculate
y=rms(X);
si does it means that peak ampltide=1.414*rms(X)?in this case i have got
y*1.414
ans =
0.9998
but why does it gives me so small number?peak is more then 45 from picture,please help me
It appears you are confusing the frequency and time domains - your plot is in the frequency domain while RMS describes the Root Mean Square value of the time domain signal.
If you plot the generated cosine signal in the time domain, you will see a cosine with an amplitude of 1. In the frequency domain (seen in your figure), the x-axis is the frequency and the y-axis is the signal energy. Thus the peak would be higher for a signal measured over longer time.
Regarding the calculation you make in the end:
y=rms(X);
Gives you the rms value of the signal (in the time domain) as y. Multiplying y by 1.414 gives you the signal amplitude (with a decimal error for rounding sqrt(2) ).
So in short I think your confusion comes from the plot being in the frequency domain and the RMS value being in the time domain. Thus the peak of the plot is not related to the RMS value.