From: Anne Stewart on
Hi all,

i have a problem with removing noise from signal. so, this is my code:

f = 7000 %frekvencija
l = 100 %duljina signala
T = 1/f
t = (0:l)*T
x = 0.1*sin(2*pi*45*t) + sin(4*pi*220*t)
y = 0.7*sin(2*pi*750*t) + sin(2*pi*120*t)
z = x + y
subplot(2,1,1)
plot(t,z)
xlabel('t[s]')
ylabel('A')
Z = fft(z)
N = size(z,2)/2
ampl = abs(Z)/N
subplot(2,1,2)
frek = (0:70)/(2*N*f)
xlabel('frekvencija [Hz]')
ylabel('amplituda')
plot(frek, ampl (1:71))
% Imamo tri vrha [u 2.828*10^(-6), 8.486*10^(-6) i u 1.556*10^(-6)]. Prvi vrh ima amplitudu 0.84, drugi 0.85, a treci 0.68.
% Sad cemo dodati random noise u signal.
noise = 0.3*randn(1,size(z,2))
m = z + noise
M = fft(m)
n = size(m,2)/2
Ampl = abs(M)/n %spektar
figure
subplot(2,1,1)
plot(t,m)
xlabel('t(s)')
ylabel('amplituda')
subplot(2,1,2)
Frek = (0:70)/(2*n*f)
plot(Frek,Ampl(1:71))
xlabel('frekvencija [Hz]')
ylabel('amplituda')
% Pripadajuci vrhovi imaju iste amplitude kao i u signalu bez random noise, dok je ostatak noise, tj. šum i on ima amplitude manje od amplituda spomenutih vrhova.
figure
plot(Z/N,'r+')
hold on
plot(M/n,'bx')
Ampl(find(Ampl<0.16)) = 0
iAmpl = ifft(Ampl)
figure
plot(t,iAmpl)
xlabel('t[s]')
ylabel('amplituda')


i was wondering if i could get that 2nd figure, 2nd plot so that after 0.2 at time axe the noise is totaly zero, or less than it is now??
From: us on
On Aug 2, 3:51 pm, "Anne Stewart" <mara.ko...(a)gmail.com> wrote:
> Hi all,
>
> i have a problem with removing noise from signal. so, this is my code:
>
> f = 7000 %frekvencija
> l = 100 %duljina signala
> T = 1/f
> t = (0:l)*T
> x = 0.1*sin(2*pi*45*t) + sin(4*pi*220*t)
> y = 0.7*sin(2*pi*750*t) + sin(2*pi*120*t)
> z = x + y
> subplot(2,1,1)
> plot(t,z)
> xlabel('t[s]')
> ylabel('A')
> Z = fft(z)
> N = size(z,2)/2
> ampl = abs(Z)/N
> subplot(2,1,2)
> frek = (0:70)/(2*N*f)
> xlabel('frekvencija [Hz]')
> ylabel('amplituda')
> plot(frek, ampl (1:71))
> % Imamo tri vrha [u 2.828*10^(-6), 8.486*10^(-6) i u 1.556*10^(-6)]. Prvi vrh ima amplitudu 0.84, drugi 0.85, a treci 0.68.
> % Sad cemo dodati random noise u signal.
> noise = 0.3*randn(1,size(z,2))
> m = z + noise
> M = fft(m)
> n = size(m,2)/2
> Ampl = abs(M)/n %spektar
> figure
> subplot(2,1,1)
> plot(t,m)
> xlabel('t(s)')
> ylabel('amplituda')
> subplot(2,1,2)
> Frek = (0:70)/(2*n*f)
> plot(Frek,Ampl(1:71))
> xlabel('frekvencija [Hz]')
> ylabel('amplituda')
> % Pripadajuci vrhovi imaju iste amplitude kao i u signalu bez random noise, dok je ostatak noise, tj. &#353;um i on ima amplitude manje od amplituda spomenutih vrhova.
> figure
> plot(Z/N,'r+')
> hold on
> plot(M/n,'bx')
> Ampl(find(Ampl<0.16)) = 0
> iAmpl = ifft(Ampl)
> figure
> plot(t,iAmpl)
> xlabel('t[s]')
> ylabel('amplituda')
>
> i was wondering if i could get that 2nd figure, 2nd plot so that after 0.2 at time axe the noise is totaly zero, or less than it is now??

a hint:

help filter; % <- and its siblings...

us
From: Anne Stewart on
us <us(a)neurol.unizh.ch> wrote in message <93eead52-b641-4b46-9b07-b65c09bee2da(a)f20g2000pro.googlegroups.com>...
> On Aug 2, 3:51 pm, "Anne Stewart" <mara.ko...(a)gmail.com> wrote:
> > Hi all,
> >
> > i have a problem with removing noise from signal. so, this is my code:
> >
> > f = 7000 %frekvencija
> > l = 100 %duljina signala
> > T = 1/f
> > t = (0:l)*T
> > x = 0.1*sin(2*pi*45*t) + sin(4*pi*220*t)
> > y = 0.7*sin(2*pi*750*t) + sin(2*pi*120*t)
> > z = x + y
> > subplot(2,1,1)
> > plot(t,z)
> > xlabel('t[s]')
> > ylabel('A')
> > Z = fft(z)
> > N = size(z,2)/2
> > ampl = abs(Z)/N
> > subplot(2,1,2)
> > frek = (0:70)/(2*N*f)
> > xlabel('frekvencija [Hz]')
> > ylabel('amplituda')
> > plot(frek, ampl (1:71))
> > % Imamo tri vrha [u 2.828*10^(-6), 8.486*10^(-6) i u 1.556*10^(-6)]. Prvi vrh ima amplitudu 0.84, drugi 0.85, a treci 0.68.
> > % Sad cemo dodati random noise u signal.
> > noise = 0.3*randn(1,size(z,2))
> > m = z + noise
> > M = fft(m)
> > n = size(m,2)/2
> > Ampl = abs(M)/n %spektar
> > figure
> > subplot(2,1,1)
> > plot(t,m)
> > xlabel('t(s)')
> > ylabel('amplituda')
> > subplot(2,1,2)
> > Frek = (0:70)/(2*n*f)
> > plot(Frek,Ampl(1:71))
> > xlabel('frekvencija [Hz]')
> > ylabel('amplituda')
> > % Pripadajuci vrhovi imaju iste amplitude kao i u signalu bez random noise, dok je ostatak noise, tj. &#353;um i on ima amplitude manje od amplituda spomenutih vrhova.
> > figure
> > plot(Z/N,'r+')
> > hold on
> > plot(M/n,'bx')
> > Ampl(find(Ampl<0.16)) = 0
> > iAmpl = ifft(Ampl)
> > figure
> > plot(t,iAmpl)
> > xlabel('t[s]')
> > ylabel('amplituda')
> >
> > i was wondering if i could get that 2nd figure, 2nd plot so that after 0.2 at time axe the noise is totaly zero, or less than it is now??
>
> a hint:
>
> help filter; % <- and its siblings...
>
> us


thanks for your reply,

but here's the thing, i have to type filter myself, not like filter from the menu. oh and how could i get the plot on 4th figure to look more alike the original signal??

Anne
From: Anne Stewart on
"Anne Stewart" <mara.kozic(a)gmail.com> wrote in message <i3cahk$31j$1(a)fred.mathworks.com>...
> us <us(a)neurol.unizh.ch> wrote in message <93eead52-b641-4b46-9b07-b65c09bee2da(a)f20g2000pro.googlegroups.com>...
> > On Aug 2, 3:51 pm, "Anne Stewart" <mara.ko...(a)gmail.com> wrote:
> > > Hi all,
> > >
> > > i have a problem with removing noise from signal. so, this is my code:
> > >
> > > f = 7000 %frekvencija
> > > l = 100 %duljina signala
> > > T = 1/f
> > > t = (0:l)*T
> > > x = 0.1*sin(2*pi*45*t) + sin(4*pi*220*t)
> > > y = 0.7*sin(2*pi*750*t) + sin(2*pi*120*t)
> > > z = x + y
> > > subplot(2,1,1)
> > > plot(t,z)
> > > xlabel('t[s]')
> > > ylabel('A')
> > > Z = fft(z)
> > > N = size(z,2)/2
> > > ampl = abs(Z)/N
> > > subplot(2,1,2)
> > > frek = (0:70)/(2*N*f)
> > > xlabel('frekvencija [Hz]')
> > > ylabel('amplituda')
> > > plot(frek, ampl (1:71))
> > > % Imamo tri vrha [u 2.828*10^(-6), 8.486*10^(-6) i u 1.556*10^(-6)]. Prvi vrh ima amplitudu 0.84, drugi 0.85, a treci 0.68.
> > > % Sad cemo dodati random noise u signal.
> > > noise = 0.3*randn(1,size(z,2))
> > > m = z + noise
> > > M = fft(m)
> > > n = size(m,2)/2
> > > Ampl = abs(M)/n %spektar
> > > figure
> > > subplot(2,1,1)
> > > plot(t,m)
> > > xlabel('t(s)')
> > > ylabel('amplituda')
> > > subplot(2,1,2)
> > > Frek = (0:70)/(2*n*f)
> > > plot(Frek,Ampl(1:71))
> > > xlabel('frekvencija [Hz]')
> > > ylabel('amplituda')
> > > % Pripadajuci vrhovi imaju iste amplitude kao i u signalu bez random noise, dok je ostatak noise, tj. &#353;um i on ima amplitude manje od amplituda spomenutih vrhova.
> > > figure
> > > plot(Z/N,'r+')
> > > hold on
> > > plot(M/n,'bx')
> > > Ampl(find(Ampl<0.16)) = 0
> > > iAmpl = ifft(Ampl)
> > > figure
> > > plot(t,iAmpl)
> > > xlabel('t[s]')
> > > ylabel('amplituda')
> > >
> > > i was wondering if i could get that 2nd figure, 2nd plot so that after 0.2 at time axe the noise is totaly zero, or less than it is now??
> >
> > a hint:
> >
> > help filter; % <- and its siblings...
> >
> > us
>
>
> thanks for your reply,
>
> but here's the thing, i have to type filter myself, not like filter from the menu. oh and how could i get the plot on 4th figure to look more alike the original signal??
>
> Anne


okay, i changed frequency and signal lenght so now the 2nd figure, 2nd plot looks fine (and it SHOULD look like that because i haven't done any noise removal at that point). the problem is when doing fft and ifft, the 4th figure is not even close to original signal (interference of those two sinusoids) - what's wrong??
From: Anne Stewart on
okay i got the point, 2nd figure should be exactly as it is, but the problem is in the step between fft - ifft, i can't remove the noise in the last plot. here is the correction od frequency and signal time:

f = 70000 %frekvencija
l = 1000 %duljina signala
T = 1/f
t = (0:l)*T
x = 0.1*sin(2*pi*45*t) + sin(4*pi*220*t)
y = 0.7*sin(2*pi*750*t) + sin(2*pi*120*t)
z = x + y
subplot(2,1,1)
plot(t,z)
xlabel('t[s]')
ylabel('A')
Z = fft(z)
N = size(z,2)/2
ampl = abs(Z)/N
subplot(2,1,2)
frek = (0:70)/(2*N*f)
xlabel('frekvencija [Hz]')
ylabel('amplituda')
plot(frek, ampl (1:71))
% Imamo tri vrha [u 2.828*10^(-6), 8.486*10^(-6) i u 1.556*10^(-6)]. Prvi vrh ima amplitudu 0.84, drugi 0.85, a treci 0.68.
% Sad cemo dodati random noise u signal.
noise = 0.3*randn(1,size(z,2))
m = z + noise
M = fft(m)
n = size(m,2)/2
Ampl = abs(M)/n %spektar
figure
subplot(2,1,1)
plot(t,m)
xlabel('t[s]')
ylabel('amplituda')
subplot(2,1,2)
Frek = (0:70)/(2*n*f)
plot(Frek,Ampl(1:71))
xlabel('frekvencija [Hz]')
ylabel('amplituda')
% Pripadajuci vrhovi imaju iste amplitude kao i u signalu bez random noise, dok je ostatak noise, tj. &#353;um i on ima amplitude manje od amplituda spomenutih vrhova.
figure
plot(Z/N,'r+')
hold on
plot(M/n,'bx')
fM = fix(M/0.0945)*100
ifM = ifft(fM)
W = real(ifM)
figure
plot(t,W)
xlabel('t[s]')
ylabel('amplituda')