You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
help me to write a code for processing an audio signal using taylor series
1 view (last 30 days)
Show older comments
clc;
clear all;
[x,Fs] = audioread('audioe.wav');
sound(x,Fs);
whos x
disp(Fs)
x = x(:,1);
dt = 1/Fs;
t = 0:dt:(length(x)*dt)-dt;
figure(1)
plot(t,x); xlabel('Seconds'); ylabel('Amplitude');
h = spectrum.periodogram; % create a periodogram spectral estimator.
figure(2)
psd(h,x,'Fs',Fs); % Calculates and plots the two-sided PSD.
%plot(psd(spectrum.periodogram,x,'Fs',Fs,'NFFT',length(x)));
y = interp(x,4);%resample data at a higher rate using lowpass interpolation
%[y, ty] = resample(x,t,Fs);
%y =resample(x,3,2);
figure(3)
subplot(211);
stem(x);
title('Original Signal');
subplot(212);
stem(y);
title('Interpolated Signal');
SNR = snr(x);
SNR1 = snr(y);
a=2;
N =2;
z = taylor(x,a,N);
plot(z);
3 Comments
Elavarasi E
on 20 Sep 2019
i need to sum up three different dimensions, which is in taylor series. this is in matrix and the equation is :
(x+h) = x + (h.*diff(x)) + (h^2.*diff(x,2))./factorial(2);
(x+h) is of same length of 'x' while first derivative is one lessthan 'x' and second derivative is of two lessthan of 'x'.
Elavarasi E
on 28 Sep 2019
In an audio signal, I need to find the intermediate samples. To read the intermediate I make use of taylor series. Audio signal is read thro’ [x,Fs] = audioread('audioe.wav');
The taylor series am using is f(x+h) = f(x) + hf’(x) + h2f’’(x)/2! .
Were f(x) is ‘x’ . Accordingly f(x+h) should be x(t)+h but this doesn’t work. ‘h’ is some intermediate value.
clc;
close all;
clear all;
[x,Fs] = audioread('audioe.wav');
sound(x,Fs);
whos x
disp(Fs)
x= x(:,1);
dt = 1/Fs;
t = 0:dt:(length(x)*dt)-dt;
figure(1)
plot(t,x);
xlabel('Seconds');
ylabel('Amplitude');
dx = gradient(x);
dx2 = gradient(dx);
for t = 0:dt:(length(x)/4*dt)-dt
for x = 0:dt:(length(x)/4*dt)-dt
h = 0.347;
y(t+h) = x + (h.*dx) + (h^2.*dx2)./factorial(2);
end
end
figure(2)
% hold on
plot(t,x,'blue',t,y, 'red')
% hold off
legend('actual','taylorseries')
for loop doesnt work
Accepted Answer
darova
on 20 Sep 2019
Try gradient instead of diff
dx = gradient(x);
dx2 = gradient(dx);
result = x + (h.*dx) + (h^2.*dx2)./factorial(2);
21 Comments
Elavarasi E
on 23 Sep 2019
this is my code to read an audio signal
clc;
close all;
clear all;
[x,Fs] = audioread('audioe.wav');
sound(x,Fs);
whos x
disp(Fs)
x= x(:,1);
dt = 1/Fs;
t = 0:dt:(length(x)*dt)-dt;
figure(1)
plot(t,x);
xlabel('Seconds');
ylabel('Amplitude');
h = 0.347;
dx = gradient(x);
dx2 = gradient(dx);
for t1 = 0:dt:(length(x)*dt)-dt
(x+h) == x + (h.*dx) + (h^2.*dx2)./factorial(2);
end
figure(2)
hold on
plot(t,x,'blue',t1(:,1:length(x+h)),(x+h), 'red')
hold off
legend('actual','taylorseries')
the lengths same now. but, the for loop does not excecute nor do it shows me any error except doble equal sign. the second figure does appear at all.
darova
on 23 Sep 2019
What does it mean?
for t1 = 0:dt:(length(x)*dt)-dt
(x+h) == x + (h.*dx) + (h^2.*dx2)./factorial(2);
end
Elavarasi E
on 23 Sep 2019
am equating the time t1 to t which nothing but dt . in this for loop i get an error wrt equal sign
Elavarasi E
on 23 Sep 2019
i need to process the read audio signal through taylor series. the length of the fine processed audio signal will be same as that of the actual signal. so i use a 'for' loop as the length of time 't' and plot the fine processed signal wrt 't'. but the for loop is not exceuting nor does it show me any error.
Elavarasi E
on 23 Sep 2019
the only error it shows is about equal sign n it guides me to use double equal sign.
Elavarasi E
on 23 Sep 2019
f(x+h) = f(x) + hf'(x) + h^2f''(x)/2!
i need to find the intermediate value of f(x) at instance z = x+dt where both time n signal are variable.
darova
on 23 Sep 2019
Please show the error occurs and why it guides you to use double sign
Why it doesn't work?
result = x + (h.*dx) + (h^2.*dx2)./factorial(2);
Elavarasi E
on 28 Sep 2019
In an audio signal, I need to find the intermediate samples. To read the intermediate I make use of taylor series. Audio signal is read thro’ [x,Fs] = audioread('audioe.wav');
The taylor series am using is f(x+h) = f(x) + hf’(x) + h2f’’(x)/2! .
Were f(x) is ‘x’ . Accordingly f(x+h) should be x(t)+h but this doesn’t work. ‘h’ is some intermediate value.
this my modified code again does not work for the "for" loop
clc;
close all;
clear all;
[x,Fs] = audioread('audioe.wav');
sound(x,Fs);
whos x
disp(Fs)
x= x(:,1);
dt = 1/Fs;
t = 0:dt:(length(x)*dt)-dt;
figure(1)
plot(t,x);
xlabel('Seconds');
ylabel('Amplitude');
dx = gradient(x);
dx2 = gradient(dx);
for t = 0:dt:(length(x)/4*dt)-dt
for x = 0:dt:(length(x)/4*dt)-dt
h = 0.347;
y(t+h) = x + (h.*dx) + (h^2.*dx2)./factorial(2);
end
end
figure(2)
% hold on
plot(t,x,'blue',t,y, 'red')
% hold off
legend('actual','taylorseries')
Elavarasi E
on 30 Sep 2019
clc;
close all;
clear all;
[x,Fs] = audioread('audioe.wav');
sound(x,Fs);
whos x
disp(Fs)
x= x(:,1);
dt = 1/Fs;
t = 0:dt:(length(x)*dt)-dt;
figure(1)
plot(t,x);
xlabel('Seconds');
ylabel('Amplitude');
for t = 1:dt:(length(x)/4*dt)-dt
for k = 1:length(x)/32
dx(k) = gradient(x(k));
dx2(k) = gradient(dx(k));
h = 0.347;
y(t+h) = x(k) + (h.*dx(k)) + (h^2.*dx2(k))./factorial(2);
end
end
figure(2)
% hold on
plot(t,x,'blue',t,y, 'red')
% hold off
legend('actual','taylorseries')
Results :
Name Size Bytes Class Attributes
x 2395137x2 38322192 double 44100
Array indices must be positive integers or logical values.
Error in eaudiodiff (line 24)
y(t+h) = x(k) + (h.*dx(k)) + (h^2.*dx2(k))./factorial(2);
1) guide me to solve theabove error.
2) when i execute these statements individually on comment window
k = 1:length(x)/32
dx(k) = gradient(x(k))
dx2(k) = gradient(dx(k))
h = 0.347
y(t+h) = x(k) + (h.*dx(k)) + (h^2.*dx2(k))./factorial(2)
I get an error as memoryspace exceeded.
darova
on 30 Sep 2019
I don't have your data so i generated some random
n = 100;
Fs = 2000;
dt = 1/Fs;
t = 0:dt:(n*dt)-dt;
x = 0.05*sin(2000*t) + cos(100*t); % random data
dx = gradient(x);
dx2 = gradient(dx);
h = 0.347;
x1 = x + h.*dx + h^2.*dx2./factorial(2);
plot(t,x,'blue',t,x1, '.r')
legend('actual','taylorseries')
xlabel('Seconds');
ylabel('Amplitude');
And here are the results
Slightly differs is it?
Elavarasi E
on 1 Oct 2019
Appreciate your kindness. Ya it differs. Actually I have to process it on any audio signal.
when I execute the entire code I get these errors
Array indices must be positive integers or logical values.
Error in eaudiodiff (line 24)
y(t+h) = x(k) + (h.*dx(k)) + (h^2.*dx2(k))./factorial(2);
1) guide me to solve the above error.
2) when i execute these statements individually on comment window
k = 1:length(x)/32
dx(k) = gradient(x(k))
dx2(k) = gradient(dx(k))
h = 0.347
I get the correct values but when the below equation is executed
y(t+h) = x(k) + (h.*dx(k)) + (h^2.*dx2(k))./factorial(2)
I get an error as memoryspace exceeded.
need to rectify these two errors.
Elavarasi E
on 1 Oct 2019
ur code is correct but its only for one instance at x1, which should actually be x+h, i.e x1 = (x+h). i need to evaluate it for all the values of x displaced by the instance 'h' wrt to 't'.
i.e., y(t+h) = x(k) + (h.*dx(k)) + (h^2.*dx2(k))./factorial(2)
y(0+h) is the output at instance x(0). were x(0) is calculated using taylor series. this has to repeat for all 't'.
darova
on 1 Oct 2019
Maybe try this
result = x + (h.*dx) + (h^2.*dx2)./factorial(2);
result = result + h;
% result = result - h;
Elavarasi E
on 2 Oct 2019
Very much appreciate your prompt response.
here I need to find the value at instance (t+h) but result = result + h will give me output + h and not output at time (t+h).
i.e if output is 20 , t= 5 and h = 0.112
as per result = result + h; i'll get the result as 20.112 at time t = 5 but at the instance t = 5.112 it will be some 'xx' value.
I need this 'xx' value. this can be done only by varying both time and amplitude.
darova
on 2 Oct 2019
So add it to t
x1 = x + (h.*dx) + (h^2.*dx2)./factorial(2);
t1 = t + h;
plot(t,x,t1,x1)
Elavarasi E
on 23 Oct 2019
hi !
let 'n' be a sequence. it should be broken down into samples of length 1024.
i.e n/1024 = y spectrum.
i should plot this 'y' spectrum as overlapped spectrums with an overlap of 48 samples on each spectrum. the last spectrum can be padded with zeroes at the last.
More Answers (0)
See Also
Categories
Find more on Signal Generation and Preprocessing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)