0% found this document useful (0 votes)
85 views3 pages

'Signal Corrupted With Zero-Mean Random Noise' 'Time (Milliseconds) '

The document contains code that generates and analyzes sinusoidal signals in the time and frequency domains. It defines sampling parameters and creates a signal as the sum of sinusoids with different frequencies, amplitudes and phases. Plots of the time domain signal and its frequency spectrum are generated. The code is then modified to compare cosine waves at different frequencies in both the time and frequency domains.

Uploaded by

jorge humberto
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
85 views3 pages

'Signal Corrupted With Zero-Mean Random Noise' 'Time (Milliseconds) '

The document contains code that generates and analyzes sinusoidal signals in the time and frequency domains. It defines sampling parameters and creates a signal as the sum of sinusoids with different frequencies, amplitudes and phases. Plots of the time domain signal and its frequency spectrum are generated. The code is then modified to compare cosine waves at different frequencies in both the time and frequency domains.

Uploaded by

jorge humberto
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

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
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);

% Plot single-sided amplitude spectrum.


figure(2)
plot(f,2*abs(Y(1:NFFT/2+1)))
title('Single-Sided Amplitude Spectrum of y(t)')
xlabel('Frequency (Hz)')
ylabel('|Y(f)|')

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

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);

% Plot single-sided amplitude spectrum.


figure(2)
plot(f,2*abs(Y(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.

%Specify the parameters of a signal with a sampling frequency of 1kHz and


a signal duration of 1 second.

Fs = 40; % Sampling frequency


T = 1/Fs; % Sampling period
L = 1000; % Length of signal
t = (0:L-1)*T; % Time vector
%Create a matrix where each row represents a cosine wave with scaled
frequency. The result, X, is a 3-by-1000 matrix. The first row has a wave
frequency of 50, the second row has a wave frequency of 150, and the
third row has a wave frequency of 300.
x1 =0.010*sin(2*pi*2*t); % First row wave
%x2 = % Second row wave
%x3 = cos(2*pi*300*t); % Third row wave

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

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy