How to get max from Scope (Simulink) - matlab

I would like to get only one number (maximum) from sinusoid in Matlab Simulink scope. I have a voltage measurement to measure AC voltage and current measurement. I need to find max. In my example the voltage is 231V and current is 0.26. the result number is 231*0.26 = .. to multiple it I need to get the max number from sinusoid.
Thanks a lot.

Based on your description, I think that the MinMax Running Resettable block would be more appropriate for your application.
The MinMax block will take multiple scalar value inputs (or a vector input) and output the minimum or maximum value (depending on your settings) of those inputs at the current instant in time. This would be better used to compare two signals, not to find the maximum value of a particular "stream" of signal data.
So, for example, let's say that you have a Sine Wave block that is feeding into a MinMax block (which has been set to output the max value). The MinMax block will look at all of its inputs at the current instant in time and output the maximum value. However, in this case, MinMax only has one input -- the sine wave. So the output of MinMax will actually be the same as the output of the Sine Wave block.
On the other hand, MinMax Running Resettable outputs the minimum or maximum of all past inputs. So for example, if you had a sine wave with a peak value of 231 that was being fed into the u input of a MinMax Running Resettable block, then by the end of the simulation, this block will output 231. This is, of course, provided that your simulation has run long enough that the sine wave has reached its peak value.
Note that the MinMax Running Resettable block was an R input that can be used to reset the block. If you simply want to find the max value of your signal over time and do not need to reset the block, then you can go ahead and just leave this input disconnected.

i once studied matlab at engineering school and i think you need to link the output of your sinusoid to a box called minmax
http://www.mathworks.com/help/simulink/slref/minmax.html

Related

Simulink model is not seems to work at high frequency [Just a representation mistake ?]

I have a model of the form:
All I am doing here is mixing the two sine waveforms based on the random bits.
I set the signal frequency of first sign wave to:
Second sign wave:
The output is :
But it works well when the signals are of low frequency.
How can I make it to work even at high frequencies ?
80*10^3*t and 12*10^4*t are both always an integer for all values of t=0:0.01:100. Hence the sin is always being evaluated at an integer multiple of 2*pi. Hence the value of the plot is always zero (or near enough to it down in the 10^-8 or 10^-9 range.
You need to change the sample rate so that you get points where sin is not zero.

Matlab: finding phase difference using cpsd

From my understanding, when using the cpsd function as such:
[Pxy,f] = cpsd(x,y,window,Ns,NFFT,Fs);
matlab chops the time series data into smaller windows with size specified by you. And the windows are shifted by Ns data point. The final [Pxy, f] are an average of results obtained from each individual window. Please correct me if I am wrong about this process.
My question is, if I use angle(Pxy) at a specific frequency, say 34Hz. Does that give me the phase difference between signal x and y at the frequency 34Hz?
I am having doubt about this because if Pxy was an average between each individual window, and because each individual was offset by a window shift, doesn't that mean the averaged Pxy's phase is affected by the window shift?
I've tried to correct this by ensuring that the window shift corresponds to an integer of full phase difference corresponding to 34Hz. Is this correct?
And just a little background about what I am doing:
I basically have numerous time-series pressure measurement over 60 seconds at 1000Hz sampling rate.
Power spectrum analysis indicates that there is a peak frequency at 34 Hz for each signal. (averaged over all windows)
I want to compare each signal's phase difference from each other corresponding to the 34Hz peak.
FFT analysis of individual window reveals that this peak frequency moves around. So I am not sure if cpsd is the correct way to be going about this.
I am currently considering trying to use xcorr to calculate the overall time lag between the signals and then calculate the phase difference from that. I have also heard of hilbert transform, but I got no idea how that works yet.
Yes, cpsd works.
You can test your result by set two input signals, such as:
t=[0:0.001:5];
omega=25;
x1=sin(2*pi*omega*t);
x2=sin(2*pi*omega*t+pi/3);
you can check whether the phase shift calculated by cpsd is pi/3.

Time invariance in matlab

How can I write a MATLAB program that takes the given system described in terms input x(t) and output
y(t) relations is input and finds out whether it is time-invariant or not?
From here:
If the input signal x(t) produces an output y(t) then any time shifted
input, x(t + \delta), results in a time-shifted output y(t + \delta)
So all you have to do is input a signal and store its output. Then delay (i.e., shift) the input signal by some amount and then see if the output is a shifted version of the earlier one (with the shift being equal to the amount by which the input signal was shifted). With the information provided, it's impossible to say if there are certain classes of signals for which the above test would fail. However, if this is for homework or something, any old signal would probably do.

DTMF, DFT window length

We've got an assignment in school to create a DTMF decoder, but are having trouble understanding what needs to be done, and how. First of all we need to calculate the energy of the signal using convolution. We do it by making use of the window length and the absolute value of the input signal:
SmoothEnergyOfInputSignal = conv(abs(X), ones(1,winlen)/winlen); %moving average
Now, we don't know how to get the proper window length. The smoothed energy is used to segment the signal, and later to determine the different frequencies in the signal making use of basis vectors(?)
The dtmf-pulses are at least 40ms separated by at least 40ms of silence.
The sampling frequency is at 8kHz and our signal is about 17601 samples long.
We thought that by doing fs*0.04 we'd get the window length. 0.04=40ms, but now the smoothed energy signal is shifted so the segments go beyond the maximum samples of the input signal.
[Sound, fs] = audioread('dtmf_all.wav');
winlen = fs*0.04
E = conv(abs(Sound),ones(1, winlen)/winlen)
Long story short: How do we calculate the "correct" window length?
Thanks in advance.
EDIT: The instructions were updated, and we're not supposed to use convolution. We're supposed to use filter()

Continuos Signal to MATLAB Function in Simulink

How can I introduce a continuos signal to a MATLAB Function block so I can get a continuos output.
My MATLAB Function block will be this:
function y = fcn(u)
y = 2*exp(-u);
So I can get a negative exponential, this because I need a control voltage source with a negative exponential signal. I need to introduce a controlled voltage source a exponential signal, is there other way?
Thanks
First of all, you don't need a MATLAB function to do that: take your input signal, multiply it by -1 with a Gain block, then use a Math Function block set to exp, and finally another Gain block to multiply it by 2.
Second, your input signal can be whatever you want. For example, you can use a Sine Wave block, or choose whatever block you want from the Sources library. If you leave the Sample Time parameter to 0, you will have a "continuous" signal (in the Simulink sense of the word), see Specify Sample Time in the documentation for more details. You can also use your own data from the MATLAB workspace using a From Workspace block.