Help. I keep getting error messages on FFT Signal with two sinusoids (100 Hz and 200 Hz) with -10 dB.

1 view (last 30 days)
I am new in matlab. This code supposed to show 3 graphs - magnitude spectrum, and phase spectrum. The problem is it wont show anything and keeps getting error messages. In this code, I want to make two sinusoids with frequencies 100 Hz and 200 Hz, with -10 dB in sine signal(I already wrote it in sig_noise).
if true
% code
% Example 3.3 Determine spectrum of a noisy waveform
N = 1024; % Data length
N2 = 511; % Valid spectral points
fs = 1000; % Sample frequency (assumed by sig_noise)
f = [100 200];
[x,t] = sig_noise(f,-10,N); % % Generate data using ‘sig_noise’(I mean it to be 100 Hz and 200 Hz sine plus white noise in -10 dB)
X = fft(x); % Calculate FFT
X_mag = abs(X); % Compute magnitude spectrum
Phase = unwrap(angle(X)); % Phase spectrum unwraped
Phase = Phase*360/(2*pi); % Convert phase to deg
f = (0:N-1)*fs/N; % Frequency vector
subplot(2,1,1);
plot(f(1:N2),X_mag(1:N2),'k'); % Plot magnitude spectrum
......Labels and title.......
subplot(2,1,2);
plot(f(1:N2),Phase(1:N2),'k'); % Plot phase spectrumy
label('Phase (deg)','FontSize',14);
......Labels and title.......
end
ps: It is supposed to show like this
<</matlabcentral/answers/uploaded_files/132613/magnitude%20spectrum%20and%20phase%20spectrum.png>>
  4 Comments
KALYAN ACHARJYA
KALYAN ACHARJYA on 16 Sep 2018
Edited: KALYAN ACHARJYA on 16 Sep 2018
Is this function, inbuilt function or user-defined function? Main source link
Error
Undefined function or variable 'sig_noise'.

Sign in to comment.

Answers (0)

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!