How do i generate a triangular waveform
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I have to generate a triangular signal on 3 periods, 1000 points on period( N=1000 ), with a 5% noise signal on it. Here it is what i did: close all; clear all; clc;
N=1000; fi=1:N; s=zeros(1); t=zeros(1);
for i=1:N s(i)=N/2*sin(6*pi/N*i); %semnal sinusoidal de 3 perioade if s(i)>0 t(i)=i-N/12+rand*N/40; %semnal triunghiular pozitiv + 5% zgomot else t(i)=-i+3*N/12+rand*N/40; %semnal triunghiular negativ end if s(i)>0 t(i)=i-5*N/12+rand*N/40; %semnal triunghiular pozitiv + 5% zgomot else t(i)=-i+7*N/12+rand*N/40; %semnal triunghiular negativ end if s(i)>0 t(i)=i-9*N/12+rand*N/40; %semnal triunghiular pozitiv + 5% zgomot else t(i)=-i+11*N/12+rand*N/40; %semnal triunghiular negativ end end
%i=1:N/6 %dinte fierestrau pana la N/6
%t(i)=i-N/12; %reparam semnalul cu N/12
%i=N/6:N/3 %semnalul negativ
%t(i)=-i+3*N/12;
%i=N/3:N/2
%t(i)=i-5*N/12;
%i=N/2:2*N/3
%t(i)=-i+7*N/12;
%i=2*N/3:5*N/6
%t(i)=i-9*N/12
%i=5*N/6:N
%t(i)=-i+11*N/12;
Vmax=max(t); %valoarea max
Vmin=min(t); %valoarea min
Vmed=sum(t)/N; %val med
%regula: Se calculeaza Vmax si se creeaza un vector care sa ia valori din 2 in 2 n=1:2:N
% t(i)=i-n(1)*Vmax, t(i)=-i+n(2)*Vmax
plot(fi,s,fi,t,'r'); %reprezentarea grafica
title('Semnale');
xlabel('Nr.de puncte');
ylabel('Amplitudinea');
legend('semnal sinusoidal','semnal triunghiular','Location','Best');
The problem with my program is that my triangular wave form is not similiar on all periods.
0 Kommentare
Antworten (0)
Siehe auch
Kategorien
Mehr zu Signal Processing Toolbox finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!