Signals and Systems Matlab
Signals and Systems Matlab
Question 1
a. n=1:50;
s=sin(2*pi*n/50);
stem(n,s)
xlabel('n')
ylabel('Amplitude')
title('Figure 1')
b.
>>n1=1;
>>n2=length(s);
i.
>>Maximum=max (s((n1:n2)-n(1)+1))
Maximum =
0.9980
ii.
>>Minimum=min (s((n1:n2)-n(1)+1))
Minimum=
-0.9980
iii.
>>Mean=mean (s((n1:n2)-n(1)+1))
Mean =
-3.2752e-17
iv.
mean squared =
0.5000
v.
>>RMS=sqrt(mean(s((n1:n2)-n(1)+1).^2))
RMS =
0.7071
vi.
>>Energy=sum(s((n1:n2)-n(1)+1).^2)
Energy =
25
c.
T_s=1/100
T_s =
0.0100
t=1:T_s:50
plot(t,s)
xlabel('t')
ylabel('Amplitude')
title('Figure 2')
i.
Signalduration=length(s)
Signalduration=
4901
ii.
Energy=sum(s.^2)
Energy =
2.4500e+03
iii.
Mean=mean(s)
Mean =
-2.7769e-17
iv.
Avg Power=Energy./Signalduration
=0.50
v.
sqrt(mean(s.^2))
ans =
0.7070
Question 2.
a.
>> load('data_1.mat')
>> t=1:length(clarinet);
>> plot(t,clarinet)
>>xlim([0 500.00)]
>> xlabel('t')
>> ylabel('clarinet')
b.
c.
i.
>> load('data_1.mat')
>> y=fft(clarinet);
>> plot(abs(y))
>> xlabel('freq')
>> ylabel('Amplitude')
ii.
d.
>> hist(clarinet,50);
d.MSV=0.150
RMSV=0.387
e.
>> x=length(clarinet)
x=
22050
>> mean(clarinet((n1:n2)-n(1)+1))
ans =
-0.0029
>> energy=sum(clarinet((n1:n2)-n(1)+1).^2)
energy =
4.5256e+03
>>MS= mean((clarinet(n1:n2)-n(1)+1).^2)
MS =
0.2052
>> RMS=sqrt(mean((clarinet(n1:n2)-n(1)+1).^2))
RMS =
0.4530
3.
>> load('data_1.mat')
>> plot(sys1_out)
>> ylabel('Amplitude')
>> plot(sys2_out)
>> ylabel('Amplitude')
ii. The frequency appeared to have increased and became a bit orderly.
3c.
Rmse=0.198816185354747
Rmse=0.205288009879387
ii.sys1_out has the least error as the difference between the original signal(clarinet) and the modified
signal(sys1_out) is not as big as that of sys2_out.
4.
% Define a threshold:
threshold = 0.2;
for i=1:Blockno
n1=support_out(i);
n2=support_out(i)+Block_size-1;
block=mboc(n1:n2);
RMS=sqrt(mean(block.^2));
if RMS>threshold
output(end+1)=1;
else
output(end+1)=0;
end
end
end
b.
[detection, i] = sig_nosig1(mboc)
>> stairs(i,detection,'k:');
hold on
plot(mboc)
xlabel("TIME")
ylabel("Amplitude")
c.Thrshold-0.01