'Signal Corrupted With Zero-Mean Random Noise' 'Time (Milliseconds) '
'Signal Corrupted With Zero-Mean Random Noise' 'Time (Milliseconds) '
clc
Fs = 1000; % Sampling frequency
T = 1/Fs; % Sample time
L = 1000; % Length of signal
t = (0:L-1)*T; % Time vector
% Sum of a 50 Hz sinusoid and a 120 Hz sinusoid
x = 0.7*sin(2*pi*50*t) + sin(2*pi*120*t);
y = x + 2*randn(size(t)); % Sinusoids plus noise
figure(1)
plot(Fs*t(1:50),y(1:50))
title('Signal Corrupted with Zero-Mean Random Noise')
xlabel('time (milliseconds)')
NFFT = 2^nextpow2(L); % Next power of 2 from length of y
Y = fft(y,NFFT)/L;
f = Fs/2*linspace(0,1,NFFT/2+1);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear
clc
Fs = 1000; % Sampling frequency
T = 1/Fs; % Sample time
L = 1000; % Length of signal
t = (0:L-1)*T; % Time vector
% Sum of a 50 Hz sinusoid and a 120 Hz sinusoid
w=3.14
p=4
x = 0.7*sin(2*pi*150*t);
y = x ; % Sinusoids
figure(1)
plot(Fs*t(1:50),y(1:50))
title('Signal Corrupted with Zero-Mean Random Noise')
xlabel('time (milliseconds)')
NFFT = 2^nextpow2(L); % Next power of 2 from length of y
Y = fft(y,NFFT)/L;
f = Fs/2*linspace(0,1,NFFT/2+1);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Superposición de funciones armónicas
%Sea una función periódica resultado de la superposición de tres
funciones
%armónicas con distintas frecuencias, amplitudes y fases iniciales
%x=200*sin(2*pi*100+pi/2)+100*sin(2*pi200+pi)+100*sin(2*pi*400+3*pi/2);
clear
clc
f=[100,200,400]; %frecuencias
A=[200,100,100]; %amplitudes
phi=[90,180,270]; %fases
subplot(2,2,1)
stem(f,A)
axis([0,500,0,210])
xlabel('Frecuencia')
ylabel('Amplitud')
subplot(2,2,2)
stem(f,phi)
axis([0,500,0,360])
xlabel('Frecuencia')
set(gca,'YTick',0:90:360)
set(gca,'YTickLabel',{'0','\pi/2','\pi','3\pi/2','2\pi'})
ylabel('Fase')
subplot(2,2,3:4) %resultante
t=(0:0.1:30)/1000; %milisegundos
x=zeros(1,length(t));
for i=1:length(f)
x=x+A(i)*sin(2*pi*f(i)*t+phi(i)*pi/180);
end
plot(t,x,'r')
xlabel('t(ms)')
ylabel('x')
title('Resultante')
ylim([-410,410])
set(gca,'XTick',(0:5:30)/1000)
set(gca,'XTickLabel',{'0','5','10','15','20','25','30'})
grid on
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear
%Compare cosine waves in the time domain and the frequency domain.
X = [x1];
%Plot the first 100 entries from each row of X in a single figure in
order and compare their frequencies.
for i = 1:1
%subplot(3,1,i)
plot(t(1:100),X(i,1:100))
title(['Row ',num2str(i),' in the Time Domain'])
end
% algorithm performance purposes, fft allows you to pad the input with
trailing zeros. In this case, pad each row of X with zeros so that the
length of each row is the next higher power of 2 from the current length.
Define the new length using the nextpow2 function.
n = 2^nextpow2(L);
%Specify the dim argument to use fft along the rows of X, that is, for
each signal.
dim = 2;
%Compute the Fourier transform of the signals.
Y = fft(X,n,dim);
%Calculate the double-sided spectrum and single-sided spectrum of each
signal.
P2 = abs(Y/L);
P1 = P2(:,1:n/2+1);
P1(:,2:end-1) = 2*P1(:,2:end-1);
%In the frequency domain, plot the single-sided amplitude spectrum for
each row in a single figure.
for i=1:1
%subplot(3,1,i)
plot(0:(Fs/n):(Fs/2-Fs/n),P1(i,1:n/2))
title(['Row ',num2str(i),' in the Frequency Domain'])
end