If I want to plot the PSD of a simple sinusoidal wave in Matlab, I would do something like the following:
Fs = 1000;
t = 0:1/Fs:1-(1/Fs);
x = cos(2*pi*100*t) ;
N = length(x);
xdft = fft(x);
xdft = xdft(1:N/2+1);
psdx = (1/(Fs*N)) * abs(xdft).^2;
psdx(2:end-1) = 2*psdx(2:end-1);
freq = 0:Fs/length(x):Fs/2;
plot(freq,10*log10(psdx))
grid on
But suppose, for simplicity, I have a sinewave generator in SIMULINK and I need to plot the PSD. I did something like the following:
Then I got the variable called "Sinwave", how can I possibly apply the above Matlab code to plot the PSD?
Please note that the variable Sinewave is 1x1 double time series. I tried to just replace x with Sinwave, but it didn't work.
Update: Applying the answers
I applied what's recommended down, but I have a different output than if I do it with Matalb. Here is the code I used:
Fs = 1000;
x = Sinwave.Data;
N = length(x);
dft = fft(x);
dft = dft(1:N/2+1);
psd = (1/(Fs*N)) * abs(dft).^2;
psd(2:end-1) = 2*psd(2:end-1);
freq = 0:Fs/length(x):Fs/2;
plot(freq,10*log10(psd))
grid on
This one for the SIMULINK-exported sinewave
However, the one from the matlab code is like the following:
I need the output to be like this from matalb with all these ripples in the noise floor. How can I get the exact output?
Please note I've used the exact values for both.
Update 2: SIMULINK sinewave setup
1- Sinewave block
2- To workspace block
3- Solver